Foros de discusión

Pass data on clicking hyperlink to a specific function in portlet Class

kishan sahu, modificado hace 11 años.

Pass data on clicking hyperlink to a specific function in portlet Class

New Member Mensajes: 6 Fecha de incorporación: 17/09/12 Mensajes recientes
Hi Friends,

I am having a hyperlink, and on its click i want to send some dynamic data( variables) to a function present in my portlet class,
Can anyone suggest me how I can achieve this.
thumbnail
Vishal Panchal, modificado hace 11 años.

RE: Pass data on clicking hyperlink to a specific function in portlet Clas (Respuesta)

Expert Mensajes: 289 Fecha de incorporación: 20/05/12 Mensajes recientes
kishan sahu:
Hi Friends,

I am having a hyperlink, and on its click i want to send some dynamic data( variables) to a function present in my portlet class,
Can anyone suggest me how I can achieve this.


First of all you need to learn how to call a specific method from a portlet class.
So , for that you should try as below..

(1) make <liferay-portlet:actionURL>

<liferay-portlet:actionURL name="portletClassMethodName" var="testURL"></liferay-portlet:actionURL>


(2) In your portlet class you should have a method which name is as same as you specified in name attribute of your <liferay-portlet:actionURL>.

public void portletClassMethodName(ActionRequest request, ActionResponse response)
{
// Your code goes here here
}


Now for passing dynamic values within URL all you need to do is to add <portlet:param> dynamically to your URL

So create your action:URL dynamically.
<liferay-portlet:actionURL name="portletClassMethodName" var="testURL">
<portlet:param name="dynamicAttrib" value="dynamicAttribValue" />
</liferay-portlet:actionURL>


(3)
Now your URL is ready just pass it to HREF.

<a href="<%= testURL %>"


(4) in your portlet class method you can get this parameter.

String dynamicAttribValue= ParamUtil.getString(actionRequest, "dynamicAttrib");



Thats it..!!

Thanks&Regards,
Vishal R. Panchal
kishan sahu, modificado hace 11 años.

RE: Pass data on clicking hyperlink to a specific function in portlet Clas

New Member Mensajes: 6 Fecha de incorporación: 17/09/12 Mensajes recientes
Thank you, this was really helpful. thanks