Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sohil Ladhani
Cannot call method of a portlet using <portlet:actionURL>
April 21, 2013 2:37 AM
Answer

Sohil Ladhani

Rank: New Member

Posts: 6

Join Date: November 16, 2012

Recent Posts

I've been trying to call a method 'signinAction' of the portlet using <portlet:actionURL> with the help of this little tutorial Developing Portlet with Multiple Actions.
But when I try to do it, I get Portlet is temporarily unavailable error. I cannot see anything in the Tomcat's server console. Also when I use processAction() I don't get the error. I don't know what is wrong.

JSP:


 1<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 2        pageEncoding="ISO-8859-1" isELIgnored="false"%>
 3    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 4   
 5    <portlet:actionURL var="signinAction" name="signinAction">
 6    </portlet:actionURL>
 7   
 8   
 9   
10    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
11    <html>
12    <head>
13    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
14    <title>Login</title>
15   
16   
17    </head>
18    <body onload="load()" id="body1">
19    <form action="<%=signinAction.toString() %>" name="signinForm" method="post" onsubmit="return signin(this)">
20   
21    <center>
22   
23    <div class="div-upside-down" id="div-style">   
24   
25    <table  width="95%">
26    <tr>
27        <td colspan="3"><p class="pp"></p>
28        </td>
29    </tr>
30    <tr>
31        <td id="td1">
32            <input type="text"  id="email" name="email"  placeholder="Email" />
33            <p id="one"></p>
34        </td>
35       
36        <td id="td2">
37            <input type="password"  id="password" name="password"  placeholder="Password" />
38            <p id="one"></p>
39        </td>
40       
41        <td id="td3">
42            <input type= "submit" name= "submit" value="Login"/>
43            <p id="one"></p>
44        </td>
45    </tr>
46    </table>
47    </div>
48    </center>
49    </form>
50    </html>


Portlet:

 1public class HelloWorldPortlet extends GenericPortlet {
 2   
 3    ThemeDisplay td;
 4   
 5
 6     public void signinAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException{
 7           long companyId=10154;
 8           String email = actionRequest.getParameter("email");
 9           String password = actionRequest.getParameter("password");
10          
11           try
12            {
13            int authResult = 0;
14            long userId = 0;
15            Company company = PortalUtil.getCompany(actionRequest);
16            Map headerMap = new HashMap();
17
18
19            Map parameterMap = actionRequest.getParameterMap();
20
21          
22
23            authResult = UserLocalServiceUtil.authenticateByEmailAddress(company.getCompanyId(), email, password,headerMap, parameterMap, null);
24            userId = UserLocalServiceUtil.getUserIdByEmailAddress(company.getCompanyId(), email);
25            User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email);
26            String screenId = user.getScreenName();
27            td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); 
28            
29            MethodKey key = new MethodKey("com.liferay.portlet.login.util.LoginUtil", "login", HttpServletRequest.class, HttpServletResponse.class, String.class, String.class, boolean.class, String.class);
30            PortalClassInvoker.invoke(false, key, new Object[] { PortalUtil.getHttpServletRequest(actionRequest), PortalUtil.getHttpServletResponse(actionResponse),screenId, password, true, CompanyConstants.AUTH_TYPE_SN});
31            actionResponse.sendRedirect(td.getPathMain());
32          
33            }
34            catch (Exception e)
35            {
36            e.printStackTrace();
37            }
38            }
39    }


Please Help.
Sohil Ladhani
RE: Cannot call method of a portlet using <portlet:actionURL>
April 21, 2013 6:52 AM
Answer

Sohil Ladhani

Rank: New Member

Posts: 6

Join Date: November 16, 2012

Recent Posts

Got the solution from Stack Overflow. Here is the link:

http://stackoverflow.com/questions/16129546/cannot-call-method-of-a-portlet-using-portletactionurl
Apoorva Prakash
RE: Cannot call method of a portlet using <portlet:actionURL>
April 23, 2013 12:04 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Sohil Ladhani:
I've been trying to call a method 'signinAction' of the portlet using <portlet:actionURL> with the help of this little tutorial Developing Portlet with Multiple Actions.
But when I try to do it, I get Portlet is temporarily unavailable error. I cannot see anything in the Tomcat's server console. Also when I use processAction() I don't get the error. I don't know what is wrong.

JSP:


 1<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 2        pageEncoding="ISO-8859-1" isELIgnored="false"%>
 3    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 4   
 5    <portlet:actionURL var="signinAction" name="signinAction">
 6    </portlet:actionURL>
 7   
 8   
 9   
10    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
11    <html>
12    <head>
13    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
14    <title>Login</title>
15   
16   
17    </head>
18    <body onload="load()" id="body1">
19    <form action="<%=signinAction.toString() %>" name="signinForm" method="post" onsubmit="return signin(this)">
20   
21    <center>
22   
23    <div class="div-upside-down" id="div-style">   
24   
25    <table  width="95%">
26    <tr>
27        <td colspan="3"><p class="pp"></p>
28        </td>
29    </tr>
30    <tr>
31        <td id="td1">
32            <input type="text"  id="email" name="email"  placeholder="Email" />
33            <p id="one"></p>
34        </td>
35       
36        <td id="td2">
37            <input type="password"  id="password" name="password"  placeholder="Password" />
38            <p id="one"></p>
39        </td>
40       
41        <td id="td3">
42            <input type= "submit" name= "submit" value="Login"/>
43            <p id="one"></p>
44        </td>
45    </tr>
46    </table>
47    </div>
48    </center>
49    </form>
50    </html>


Portlet:

 1public class HelloWorldPortlet extends GenericPortlet {
 2   
 3    ThemeDisplay td;
 4   
 5
 6     public void signinAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException{
 7           long companyId=10154;
 8           String email = actionRequest.getParameter("email");
 9           String password = actionRequest.getParameter("password");
10          
11           try
12            {
13            int authResult = 0;
14            long userId = 0;
15            Company company = PortalUtil.getCompany(actionRequest);
16            Map headerMap = new HashMap();
17
18
19            Map parameterMap = actionRequest.getParameterMap();
20
21          
22
23            authResult = UserLocalServiceUtil.authenticateByEmailAddress(company.getCompanyId(), email, password,headerMap, parameterMap, null);
24            userId = UserLocalServiceUtil.getUserIdByEmailAddress(company.getCompanyId(), email);
25            User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email);
26            String screenId = user.getScreenName();
27            td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); 
28            
29            MethodKey key = new MethodKey("com.liferay.portlet.login.util.LoginUtil", "login", HttpServletRequest.class, HttpServletResponse.class, String.class, String.class, boolean.class, String.class);
30            PortalClassInvoker.invoke(false, key, new Object[] { PortalUtil.getHttpServletRequest(actionRequest), PortalUtil.getHttpServletResponse(actionResponse),screenId, password, true, CompanyConstants.AUTH_TYPE_SN});
31            actionResponse.sendRedirect(td.getPathMain());
32          
33            }
34            catch (Exception e)
35            {
36            e.printStackTrace();
37            }
38            }
39    }


Please Help.


Hello Sohil,

You are supposed to import MVCPortlet, not GenericPortlet. See this for reference.
And another important point, you should not <HTML> and <TITLE> and <BODY> tags inside portlet's JSP.

HTH.

Thanks and Regards,
Apoorva Prakash