Fórumok

Link view.jsp to processAction

lucky singh, módosítva 11 év-val korábban

Link view.jsp to processAction

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.07.30. Legújabb bejegyzések
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

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>  
<%@ page import="javax.portlet.PortletPreferences" %>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="javax.portlet.ActionRequest"%>

<portlet:defineobjects />
&lt;%
PortletPreferences prefs = renderRequest.getPreferences();
String greeting = (String)prefs.getValue(
    "greeting", "This is a discussion forum:");
%&gt;

&lt;%
PortletURL viewCommentURL = renderResponse.createActionURL();
viewCommentURL.setParameter(
ActionRequest.ACTION_NAME, "processAction");
%&gt;

	<portlet:renderurl var="viewCommentURL"> 
	<portlet:param name="jspPage" value="/html/commentportlet/view.jsp" /> 
	</portlet:renderurl>
<form name="<portlet:namespace/>fm" method="POST" action="<%=
	viewCommentURL.toString() %>">
	<fieldset>
	<legend>&lt;%= greeting %&gt;</legend>
		       Name:<input type="text" name="<portlet:namespace/>username"><br>
		Add comment:<input type="text" name="<portlet:namespace/>usercommenr">

			<br><input type="submit" value="Add" size="10" ">
		
	</fieldset>
</form>


My portlet.xml:
<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">
	
	<portlet>
		<portlet-name>commentportlet</portlet-name>
		<display-name>CommentPortlet</display-name>
		<portlet-class>com.test.comment.CommentPortlet</portlet-class>
		<init-param>
			<name>view-template</name>
			<value>/html/commentportlet/view.jsp</value>
		</init-param>
		<init-param>
			<name>edit-template</name>
			<value>/html/commentportlet/edit.jsp</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<portlet-mode>edit</portlet-mode>
		</supports>
		<resource-bundle>content/Language</resource-bundle>
		<portlet-info>
			<title>CommentPortlet</title>
			<short-title>CommentPortlet</short-title>
			<keywords></keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>


My portlet class-with processAction
package com.test.comment;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

//import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class CommentPortlet
 */
public class CommentPortlet extends MVCPortlet {
    public void processAction(
            ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {
    	
    	//String name = ParamUtil.getString(actionRequest, "username");
    	//String comment = ParamUtil.getString(actionRequest, "usercommenr");
    	//System.out.println("Your inputs ==&gt; " + name + ", " + comment);
    	System.out.println("Inside Processaction...");
    }

}


I see "CommentPortlet is temporarily unavailable". Please suggest how to use processAction.
Oliver Bayer, módosítva 11 év-val korábban

RE: Link view.jsp to processAction

Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
Hi,

if you're getting such error messages you should look at the console logs of your server to get more info why this error occurred.

HTH Oli
John Andrews, módosítva 11 év-val korábban

RE: Link view.jsp to processAction

New Member Bejegyzések: 22 Csatlakozás dátuma: 2012.07.26. Legújabb bejegyzések
use this form submit

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>


<%@ page import="javax.portlet.*"%>
<%@ page import="com.liferay.portal.service.UserLocalServiceUtil" %>
<%@ page import="com.liferay.portal.model.Organization" %>
<%@ page import="com.liferay.portal.model.User" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />

This is the <b>GroupCreationPortlet</b> portlet in View mode.

<form method="POST" action="<portlet:actionURL/>">
<input type="text" name="ownertarget"/>
<input type="submit" value="edit"/>
</form>
Roshan Qureshi, módosítva 11 év-val korábban

RE: Link view.jsp to processAction

Regular Member Bejegyzések: 159 Csatlakozás dátuma: 2010.08.24. Legújabb bejegyzések
Hi Lucky,

Use <portlet:actionURL> instead of <portlet:renderURL>

renderURL will call render method while actionURL will call processAction() method of the portlet.