Fórum

Is it possible to pass form data from template to portlet?

Zsolt Vilhelm, modificado 12 Anos atrás.

Is it possible to pass form data from template to portlet?

New Member Postagens: 16 Data de Entrada: 30/08/11 Postagens Recentes
Hello!

What I would like to know, is that If I have a form, hardcoded in my template... is it possible to somehow pass the form data to , lets say a search portlet?
The action url should be something like this:
<liferay-portlet:actionURL portletName="stdSearchPortlet_WAR_stdSearchPortlet_INSTANCE_NJ2w"/>
but i belive it's not gonna work if I embed it into a template......

Thanks in advance!
thumbnail
Christianto Sahat, modificado 12 Anos atrás.

RE: Is it possible to pass form data from template to portlet?

Regular Member Postagens: 179 Data de Entrada: 25/09/07 Postagens Recentes
Should be possible with PortletURLFactory instance.

This instance is set as one of Velocity's variables, so you can use it in your template.



#set ( $target_layout_plid = 1089)
#set ( $search_portlet_name = "3_instance_3f01" );

#set ($search_portlet_url = $portletURLFactory.create($request, $search_portlet_name, $themeDisplay.getPlid(), "ACTION_PHASE"))
                                
$search_portlet_url.setWindowState("normal")
$search_portlet_url.setPortletMode("view")
$search_portlet_url.setParameter("userId", "$userId")

<form method="POST" action="$search_portlet_url.toString()" name="sign_up">
Name : <input type="text" name="my_name">
<input value="Sign Up" type="submit"> 
</form>
Zsolt Vilhelm, modificado 12 Anos atrás.

RE: Is it possible to pass form data from template to portlet?

New Member Postagens: 16 Data de Entrada: 30/08/11 Postagens Recentes
I'm new to liferay. Could you please tell me , what exactly :
#set ( $target_layout_plid = 1089) is? Thanks
Nitu Saksena, modificado 12 Anos atrás.

RE: Is it possible to pass form data from template to portlet?

New Member Postagens: 11 Data de Entrada: 02/02/11 Postagens Recentes
Hi Zsolt,

Do you mean velocity template? or Web content template?
Zsolt Vilhelm, modificado 12 Anos atrás.

RE: Is it possible to pass form data from template to portlet?

New Member Postagens: 16 Data de Entrada: 30/08/11 Postagens Recentes
Velocity!
Nitu Saksena, modificado 12 Anos atrás.

RE: Is it possible to pass form data from template to portlet?

New Member Postagens: 11 Data de Entrada: 02/02/11 Postagens Recentes
You could set actionURL on your component in the .vm file using JavaSrcipt.

Eg:

<a href="" onclick="submitURL()" id="id">Search</a>


Here, the portlet containing the definition of submitURL() must be loaded before this statement as shown below:

    $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
    #set($locRenderedPortletContent = $theme.runtime("yourSearch_WAR_portlet", "", $velocityPortletPreferences.toString()))
    $locRenderedPortletContent
    $velocityPortletPreferences.reset()
    #end


The code in the portlet to set the URL could be as mentioned below:

	
<portlet:renderurl name="searchURL" var="searchURL">
	<portlet:param name="action" value="xyz" />
</portlet:renderurl>


<script type="text/javascript">
function submitURL(){
		document.getElementById("id").href='<%=searchURL%>';
	}
</script>


Hope this helps.

BR