I am new to liferay. I have view.jsp,on form submit it should link to action class.
I have done following so far:
Have created “New Liferay Plug-in Project” with “Custom portlet class”and define portlet class as-CommentPortlet.
My view.jsp
1
2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
3<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
4<%@ page import="javax.portlet.PortletPreferences" %>
5<%@page import="javax.portlet.PortletURL"%>
6<%@page import="javax.portlet.ActionRequest"%>
7
8<portlet:defineObjects />
9<%
10PortletPreferences prefs = renderRequest.getPreferences();
11String greeting = (String)prefs.getValue(
12 "greeting", "This is a discussion forum:");
13%>
14
15<%
16PortletURL viewCommentURL = renderResponse.createActionURL();
17viewCommentURL.setParameter(
18ActionRequest.ACTION_NAME, "processAction");
19%>
20
21 <portlet:renderURL var="viewCommentURL">
22 <portlet:param name="jspPage" value="/html/commentportlet/view.jsp" />
23 </portlet:renderURL>
24<form name="<portlet:namespace/>fm" method="POST" action="<%=
25 viewCommentURL.toString() %>">
26 <fieldset>
27 <legend><%= greeting %></legend>
28 Name:<input type="text" name="<portlet:namespace/>username" /><br/>
29 Add comment:<input type="text" name="<portlet:namespace/>usercommenr" />
30
31 <br/><input type="submit" value="Add" size="10" "/>
32
33 </fieldset>
34</form>
My portlet.xml:
1<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
2
3 <portlet>
4 <portlet-name>commentportlet</portlet-name>
5 <display-name>CommentPortlet</display-name>
6 <portlet-class>com.test.comment.CommentPortlet</portlet-class>
7 <init-param>
8 <name>view-template</name>
9 <value>/html/commentportlet/view.jsp</value>
10 </init-param>
11 <init-param>
12 <name>edit-template</name>
13 <value>/html/commentportlet/edit.jsp</value>
14 </init-param>
15 <expiration-cache>0</expiration-cache>
16 <supports>
17 <mime-type>text/html</mime-type>
18 <portlet-mode>view</portlet-mode>
19 <portlet-mode>edit</portlet-mode>
20 </supports>
21 <resource-bundle>content/Language</resource-bundle>
22 <portlet-info>
23 <title>CommentPortlet</title>
24 <short-title>CommentPortlet</short-title>
25 <keywords></keywords>
26 </portlet-info>
27 <security-role-ref>
28 <role-name>administrator</role-name>
29 </security-role-ref>
30 <security-role-ref>
31 <role-name>guest</role-name>
32 </security-role-ref>
33 <security-role-ref>
34 <role-name>power-user</role-name>
35 </security-role-ref>
36 <security-role-ref>
37 <role-name>user</role-name>
38 </security-role-ref>
39 </portlet>
40</portlet-app>
My portlet class-with processAction
1package com.test.comment;
2
3import java.io.IOException;
4
5import javax.portlet.ActionRequest;
6import javax.portlet.ActionResponse;
7import javax.portlet.PortletException;
8
9//import com.liferay.portal.kernel.util.ParamUtil;
10import com.liferay.util.bridges.mvc.MVCPortlet;
11
12/**
13 * Portlet implementation class CommentPortlet
14 */
15public class CommentPortlet extends MVCPortlet {
16 public void processAction(
17 ActionRequest actionRequest, ActionResponse actionResponse)
18 throws IOException, PortletException {
19
20 //String name = ParamUtil.getString(actionRequest, "username");
21 //String comment = ParamUtil.getString(actionRequest, "usercommenr");
22 //System.out.println("Your inputs ==> " + name + ", " + comment);
23 System.out.println("Inside Processaction...");
24 }
25
26}
I see "CommentPortlet is temporarily unavailable". Please suggest how to use processAction.
Please sign in to flag this as inappropriate.