Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ravi Kiran
Liferay : How can i call the Method inside the MVC Portlet class on onclick
July 5, 2012 4:30 AM
Answer

Ravi Kiran

Rank: Junior Member

Posts: 98

Join Date: December 11, 2011

Recent Posts

Hi

I am using Liferay 6 for the development . I have added JQuery support to the Liferay this way inside the file liferay-portlet.xml file

<header-portlet-javascript>https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js</header-portlet-javascript>
<header-portlet-javascript>https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js</header-portlet-javascript>


Now i have a form with Username and password as shown below :

<form>
<div>
<input class="default-value" type="text" name="Name" value="Name" />
<input class="default-value" type="text" name="Password" value="Password" />
</div>
</form>

<div class="fieldgroup">
<input type="submit" value="Register" class="submit">
</div>


<liferay-portlet:actionURL name="registerUser" var="registerUserURL"></liferay-portlet:actionURL>

I have a CustomPortlet as shown below , and added this inside the portlet.xml file as shown

<portlet>
<portlet-name>Second</portlet-name>
<display-name>Second</display-name>
<portlet-class>com.SecondPort</portlet-class>


public class SecondPort extends MVCPortlet {

public void registerUser(ActionRequest request, ActionResponse response)
{
// Some code here with respect to the registerUser .
}
}

Now please tell me on click of the Submit Button on to the JSP Page , how can i call this registerUser method ??

<input type="submit" value="Register" class="submit">

Please let me know , thanks in advance .
Amit Doshi
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
July 5, 2012 4:43 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 549

Join Date: December 29, 2010

Recent Posts

Just use it as below :-

public class SecondPort extends MVCPortlet {

@ProcessAction(name ="registerUser")
public void registerUser(ActionRequest request, ActionResponse response)
{
// Some code here with respect to the registerUser .
}
}

Hope it will work.

Thanks & Regards,
Amit Doshi
Ravi Kiran
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
July 5, 2012 4:56 AM
Answer

Ravi Kiran

Rank: Junior Member

Posts: 98

Join Date: December 11, 2011

Recent Posts

Hi ,
Thanks for the response
I forgot to mention i am using Liferay 6 for the development .

This is my JSP Page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<portlet:defineObjects />

<liferay-portlet:actionURL name="registerUser" var="registerUserURL"></liferay-portlet:actionURL>

<form>

<a
href="<portlet:renderURL>
<portlet:param name="goto" value="IpByHourPage"/>
<portlet:param name="jspPage" value="/page2.jsp" />
</portlet:renderURL>">
Click here to go to Second Page </a>

<div>
<input type="text" name="Name" value="Name" />
<input type="text" name="Password" value="Password" />
</div>

<div>
<input type="submit" value="Register" class="submit">
</div>



</form>



This is my MVCPortlet class


package com;

public class SecondPort extends MVCPortlet {

@ProcessAction(name = "registerUser")
public void registerUser(ActionRequest request, ActionResponse response) {

System.out.println("Hi My Name is Billa");
}
}



When i clicked on the Register Button shown on the Portal nothing happened
Tejas Kanani
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
July 5, 2012 4:56 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 655

Join Date: January 6, 2009

Recent Posts

It should work as is.

As you've specify name as "registerUser" in
<liferay-portlet:actionURL name="registerUser" var="registerUserURL"></liferay-portlet:actionURL>


And in your controller your method name is registerUser only.
public void registerUser(ActionRequest request, ActionResponse response)
{
// Some code here with respect to the registerUser .
}


Are you getting any error ?
Tejas Kanani
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
July 5, 2012 5:00 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 655

Join Date: January 6, 2009

Recent Posts

Ohhh !! Here is the problem. You've not added action in form.

<form action="<%= registerUserURL%>">

<a
href="<portlet:renderURL>
<portlet:param name="goto" value="IpByHourPage"/>
<portlet:param name="jspPage" value="/page2.jsp" />
</portlet:renderURL>">
Click here to go to Second Page </a>

<div>
<input type="text" name="Name" value="Name" />
<input type="text" name="Password" value="Password" />
</div>

<div>
<input type="submit" value="Register" class="submit">
</div>



</form>
Vaibhav Mittal
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
January 8, 2013 7:39 AM
Answer

Vaibhav Mittal

Rank: Junior Member

Posts: 54

Join Date: July 16, 2012

Recent Posts

Hi Tejas,

I tried with the above code but I am geting an exception "registerUserURL cannot be resolved to a variable" in my view.jsp at line <form action="<%= registerUserURL%>">. I have extended GenericPortlet not MVC, if this is the reason.
Gwowen Fu
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
January 8, 2013 9:14 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 315

Join Date: December 27, 2010

Recent Posts

Here is the problem, the prefix is "portlet"
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

but "liferay-portlet" is used for actionURL.
<liferay-portlet:actionURL name="registerUser" var="registerUserURL"></liferay-portlet:actionURL>
Vaibhav Mittal
RE: Liferay : How can i call the Method inside the MVC Portlet class on onc
January 14, 2013 1:34 AM
Answer

Vaibhav Mittal

Rank: Junior Member

Posts: 54

Join Date: July 16, 2012

Recent Posts

Thanks Gwowen. That mean var="registerUserURL" not work because of prefix.

Anyhow, I am using action="<portlet:actionURL/>" now and this is working perfectly.