Laliwala IT Services

Laliwala IT Services
Website Development

Tuesday, February 22, 2011

liferay, liferay cloud, liferay portal development, liferay tutorial

liferay
liferay, liferay portal development, liferay developer india, liferay development, liferay development services, liferay developer consulting
Sam w :Happy holiday Easter everyone,











I created a SignUp portlet, and tried to pass a parameter into the portlet using method "get" in a form, but I can't retrieve this value in the Action class.

The method I want to retrieve this parameter is:








liferay tutorial








eg.


liferay portal tutorial








The first one returned empty string, the second one retured null.





Here is the url with parameters when the form is submitted (with get method):





http://localhost:8080/web/guest/sign_up?userId=10116&service_id=12001








Very appreciate for any suggestion and some code example...









THANKS

Sam






Samir Bhatt :Hi,








You need to generate get url by using <portlet:renderURL> tag in your jsp.








So in your form element or javascript submit method set action url as shown in below example. Then you will be able to access the parameter using ParamUtil.








liferay portlet tutorial, liferay developer tutorial








Regards,








Samir Bhatt








CIGNEX Technologies






Sam w :How to generate portlet:renderURL from a Velocity template file?

eg,








liferay development tutorial











Thank you very much for the prompt response.








Sam.






Samir Bhatt :You can use $request.get('render-url') to get render url in velocity templates.








Regards,








Samir Bhatt

CIGNEX Technologies






Sam w :Thank you for the quick response.

I have tried it, it generated the following url when I hit the submit button:








liferay weblogic tutorial, liferay alfresco tutorial








It doesn't go to the sign_up page.

This is how I coded according to your suggestion:













I have also tried the following coding:













the resulting url from this coding is same as get('render-url').








Thank you.

Sam






Sam w :Here is what I tried to do:













But signup_url is not pointing to the sign_up portlet.








Thanks

Sam






Sam w : Not sure if I can do something like this in vm?





<form method="GET" action="<portlet:signupURL></portlet:signupURL>&userId=10116&service_id=12001">






Samir Bhatt :Hi Sam,





Do you have this form on some portlet on hosting_service page and you want to submit the form to sign up portlet on sign_up page?








Regards,








Samir Bhatt

CIGNEX Technologies






Mazhar Anwar :Hi Sam,








A very simple solution for this problem can be get the HTTPServeletRequest instance from RenderRequest and get the parameter.








for example:








HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest);


String sp = request.getParameter("service_id");








HTH,

Mazhar






Sam w :Excellent suggestion.








Thanks

Sam






Sam w :Hi Mazhar,








It still returned null in the Action class.

Here is how I coded the form/submit clause in my velocity tempalte file:














Sandeep Nair :Hi Sam,





Is it because from template you are passing parameter named ServiceId and in render Method you are trying to get a parameter named service_id








Regards,

Sandeep






Sam w :I have changed it to service_id, stiill returned null.








Thanks

Sam






Sandeep Nair : Can i see what is your sign_up_page_full_url. Also when you submit the form you should be able to see the form parameters in url since its a get request. Do you see your form parameters with values being passed in URL








Regards,

Sandeep






Sam w :Hi Sandeep,








Thank you very much for the quick response.


The $sign_up_page_full_url is pointing to the page of sign_up portlet. I have tried GET before, where parameters are in the URL. Then I tried POST, still have no luck. The code is not in front of me now, but I will re-test it with method=GET when I get home tonight.








Thanks

Sam






Sandeep Nair :Since its a get request, Do you see your parameters in Browser URL?








Regards,

Sandeep






Sam w :Yes I did, but since the request.getParameter("...") returns null, I changed to method POST afterward. But I will re-test it with GET tonight and make sure the parameters in the form/submit match those parameters in the getParameter("..") in the Action class.








I will keep you posted,








Thank you very much.

Sam






Sam w :Hi,








Here is what I got - still returned null:








velocity template file:













render() method in Java Action class:
















$sign_up_full_url when submit button is pressed:








http://localhost:8080/web/guest/sign_up?userId=10116&service_id=12001








Any idea?





Thank you very much

Sam






Sandeep Nair :Hi,








Can you do a System.out.println in your render method.













Regards,

Sandeep






Mazhar Anwar :Hi Sam,





It should work,








Can you do a view source of html page and copy and paste only the form code what is getting generated?








Regards,

Mazhar






Sam w :Surprised it returns empty array - {}








Sam.






Sandeep Nair :Yeah,








Thats what i wanted to tell. Like the no parameters are recieved at all.








Regards,

Sandeep






Sam w :So what is happening there?








Sam






Sam w :is because <portlet:namespace/> missing with the parameter?

Then how to construct <portlet:namespace/> in a form/submit in velocity?








Thanks

Sam






Sam w :Very appreciate for further suggestion.








Thanks

Sam






Sam w :Here is the code in firefox viewsource:
















Thanks

Sam






Mazhar Anwar :Hi Sam,





Please check action url of the form. It should be a PortletURL to go to any of processAction/render/serveResource Method of the portlet. So I think this is the concern only how you will generate instance of portletURL inside velocity template.








Can you give a try to create something like follow;














Sam w :Fabulous! this should be the correct way.











Thanks

Sam






Sam w : It still not working with the method.








http://localhost:8080/web/guest/hosting_service?p_p_id=signUp&p_p_lifecycle=1








Any idea?



Thanks

Sam






Sam w : Just a note for the preivous post.








the $sign_up_portlet_url cannot find method setParameter(..), therefore when I navigate to that velocity template page, the page prints the name of $sign_up_portlet_url.setParameter(..) instead of its value.








eg. the page prints:








$sign_up_portlet_url.setParameter("userId", $userId) $sign_up_portlet_url.setParameter("service-id", $sp.getPackageId())








on to the screen.



Thanks

Sam






Mazhar Anwar :Hi Sam,








#set ($sign_up_portlet_url = $portletURLFactory.create($request, "signUp", $page.getPlid(), "ACTION_PHASE"))








Please have a look on PortletURLImpl.java and PortletURLFactoryImpl.java. $sign_up_portlet_url is nothing but jst an object of LiferayPortletURL class.








and $page is the current layout so you can use $layout.getPlid() in the method.








Anyway, if setParameter() is not working, can you put those values in hidden input tag inside the form and try? something like,
















If we are able to pass these values to your method i think thats the success. emoticon






Mazhar Anwar :Hi Sam,








$sign_up_portlet_url.setParameter("userId", $userId, "true")






Sam w :Hi,








I am still stuck.








Here I am using following form/submit code in velocity template file:
















The $sign_up_portlet_url is pointing to the following url:
















When I pressed the Submit button, it stays on the same page (the velocity template page) rather than going to the signUp portlet page.





Thanks

Sam






Mazhar Anwar :Hi Sam,








Could you please have a look in emoticon








http://www.liferay.com/community/forums/-/message_boards/message/669150






Sam w :Do you know where should I create a PortletURL?

ref. PortletURL actionURL = res.createActionURL();








In the sign_up Action class? and then use serviceLocator like this:

#set($signUpClass = $serviceLocator.findService("au.com.ip6.ext.portlet.Action.SignUpAction"))








or put it in the SignUpLocalServiceUtil class?

eg.








#set($signUpUtil = $serviceLocator.findService("au.com.ip6.ext.portlet.signup.service.IP6SignUpLocalServiceUtil"))








Thanks

Sam






Sam w :Now I ‘ve consutructed a reasonable URL .

Vm code:
















Constructed URL:
















When the submit button is clicked, the new url is consutructed as shown above, but the page is not move to the signup portlet page. It stay at the same page ( the vm page).








Any idea?








Thanks

Sam






Sam w :I found a problem with the returned portletURL.








As I said in the previous posts, the following portletURL makes the navigation stay on the same page (hosting_service page):








it works perfectly.








Now the problem is how to return a portletURL with the destination's portlet name, eg. it should be sign_up rather than hosting_service in this case?








Thanks

Sam






Sam w :Hi,








Can anyone tell me why the portletURL returned from PortletURLFactory is not the destination portlet url?








Here is the code in the velocity template file:








where FRONT_PAGE in the URL is a velocity template page used to trigger the submit action.

I actually expect the name of the destination portlet name "sign_up" rather than "FRONT_PAGE" in the above URL.








Does anyone know how to correct this error or how to replace FRONT_PAGE with "sign_up" in the above URL?








I have tried to look for a method in velocity for replacing a sub string , but I couldn't find this method from Velocity.








Your help is very much appreciated.








Thanks

Sam






Sam w :To clarify more about my problem,

The URL of my velocity template file is here:

http://localhost:8080/web/guest/home








The form/submit code is written in this template file.








When I click the submit button within this template file, the navigation stay in the same file (http://localhost:8080/web/guest/home) rather than go to the sign_up portlet page.








eg. the new url should be:

http://localhost:8080/web/guest/sign_up? ...








Further suggestion is very much appreciated.








Thanks

Sam






















No comments:

Post a Comment