Forums de discussion

RE: Portlet problem

veronica medeiros, modifié il y a 11 années.

Portlet problem

Regular Member Publications: 112 Date d'inscription: 18/02/14 Publications récentes
I followed the example http://www.opensource-techblog.com/2012/08/creating-custom-liferay-mvc-portlet.html to make a first portlet with value in input.
What I want to do: when typing the name in the input, click the button and show the name entered appear in front of the phrase NAME: _ (typed name) _ ... But that does not happen, someone help me please...

codes:

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

NAME:  ${userName}

<portlet:defineobjects />

<portlet:actionurl name="addName" var="addNameUrl"></portlet:actionurl>

<form action="${addNameUrl}" method="post">
<input type="text" name="userName"> 
<input type="submit">
</form>  


classe Name.java
package com.companyname.portlet;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class Name extends MVCPortlet {

		public void doView(RenderRequest renderRequest,
				RenderResponse renderResponse) throws IOException, PortletException {
			super.doView(renderRequest, renderResponse);
		}
		
	@ProcessAction(name="addName")  
    public void addName(ActionRequest actionRequest,  
      ActionResponse actionResponse) throws IOException, PortletException{  
     String userName = ParamUtil.get(actionRequest, "userName", StringPool.BLANK);  
     actionRequest.setAttribute("userName", userName);  
    }   
}


portlet.xml
<!--?xml version="1.0"?-->
<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>Name</portlet-name>
		<display-name>Name</display-name>
		<portlet-class>com.companyname.portlet.Name</portlet-class>
		<init-param>
			<name>view-jsp</name>
			<value>/view.jsp</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
		</supports>
		<portlet-info>
			<title>Nome</title>
			<short-title>Nome</short-title>
			<keywords>Nome</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>


Thank you,
thumbnail
mohammad azaruddin, modifié il y a 11 années.

RE: Portlet problem

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
veronica medeiros, modifié il y a 11 années.

RE: Portlet problem

Regular Member Publications: 112 Date d'inscription: 18/02/14 Publications récentes
Thank you...
I will read!
veronica medeiros, modifié il y a 11 années.

RE: Portlet problem

Regular Member Publications: 112 Date d'inscription: 18/02/14 Publications récentes
Anyone have another tip?

Thank you...
Mohit Soni, modifié il y a 11 années.

RE: Portlet problem

New Member Publications: 20 Date d'inscription: 28/02/14 Publications récentes
Hi,

What i can understand id you want to see the typed name in the label.
As you can see that both the functionalities like submitting the form and getting values belongs to one portlet. so in this way you won't be able to retrieve that because when you submit that page portlet refresh and calls render method. One way to achieve this by using PortlalPrefrences.


Thanks,
Mohit
thumbnail
Harish Kumar, modifié il y a 11 années.

RE: Portlet problem

Expert Publications: 483 Date d'inscription: 31/07/10 Publications récentes
As Nilang said, If you are using liferay portal 6.2, you need to set one property in liferay-portlet.xml file to make it work-

<requires-namespaced-parameters>false</requires-namespaced-parameters>
Nilang I Patel, modifié il y a 11 années.

RE: Portlet problem

Junior Member Publications: 31 Date d'inscription: 26/07/11 Publications récentes
Hi,

I am owner of www.opensource-techblog.com. I wrote blog and give example of portlet written on liferay 6.1. I guess starting from liferay 6.2, liferay had mandate to provide portlet name space while accessing parameter from request. By default this behavior is enable. To disable you need to disable one flag in liferay-portlet.xml file.I don't remember exact attribute name but it should be something like "namespace". Set it false and then try run the code. Hope it should work.

Let me know if still you face the issues

Regards
Nilang