Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Anônimo
Forward to JSP page from processAction()
15 de Novembro de 2011 04:41
Resposta

Anônimo

Hi there guys,

The thread heading pretty much says it all. How to I forward/redirect to a certain JSP page from whithin my processAction() method in my porlet?
I'm guessing it has something to do with the dispatcher, but in all honesty. I don't have a clue.

Any help would greatly be appreciated!
Thanks in advance,
Oliver Bayer
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 05:11
Resposta

Oliver Bayer

Ranking: Liferay Master

Mensagens: 867

Data de entrada: 18 de Fevereiro de 2009

Mensagens recentes

Hi Dean,

if you extend your portlet from GenericPortlet you should be able to use the following code snippet:
 1
 2...
 3private String newJSP;
 4
 5public void init() throws PortletException
 6{
 7    ...
 8    // read the path to the new jsp from the init-params of the portlet.xml
 9    newJSP = getInitParameter("new-jsp");
10    ...
11}
12
13...
14
15public void yourProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
16{
17    ...
18    actionResponse.setRenderParameter("jspPage", destGroupsSelectJSP);
19}

HTH Oli
Sandeep Nair
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 05:40
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1691

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

If you are using MVCPortlet you can use actionResponse.setRenderParameter("jspPage",pathToJSP); inside your processAction

Regards,
Sandeep
Prabodhini Tare
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 05:54
Resposta

Prabodhini Tare

Ranking: New Member

Mensagens: 6

Data de entrada: 29 de Setembro de 2010

Mensagens recentes

try using actionResponse.sendRedirect(<<url>>);
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 22:41
Resposta

Anônimo

Hi there again,

I tried what you guys suggested but couldn't come right. I have my code attached here at the bottom, if anyone can just have a look at it and just see what my method looks like:

 1public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 2   
 3        //form variables
 4        String formType = request.getParameter("formType");
 5        String buttonClicked = request.getParameter("button");
 6       
 7        //check what page to forward to
 8        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
 9       
10        //forward to "/WEB-INF/jsp/"+jsp;
11        //but how?
12       
13    }


Any help would greatly be appreciated emoticon
Puneet Upadhyay
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 22:49
Resposta

Puneet Upadhyay

Ranking: Regular Member

Mensagens: 234

Data de entrada: 22 de Outubro de 2011

Mensagens recentes

Make any folder in docroot and place your jsp's there.
and then put this below code into your class....

"response.setRenderParameter("jspPage", "/Any_Folder/view.jsp"); "
Sandeep Nair
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:05
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1691

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

Hi
Is it possible to attach the portlet. Which portlet are you using? Is it Generic, MVC or Struts portlet

Regards,
Sandeep
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:27
Resposta

Anônimo

It is a Generic portlet:

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 4   
 5        //from variables      
 6        String formType = request.getParameter("formType");
 7        String buttonClicked = request.getParameter("button");
 8       
 9        //check what page to forward to
10        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
11       
12        //forward to "/WEB-INF/jsp/"+jsp;
13        //but how?
14       
15    }
16   
17    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
18
19        //get current tab value
20        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
21       
22        //gets data only for requested table
23        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
24        String javaScript = Tablerize.create(rs);
25        request.setAttribute("generatedScript", javaScript);
26
27        //prints out javascript in console for reference
28        System.out.println("----------------------------------------------");
29        System.out.println(javaScript);
30        System.out.println("----------------------------------------------");
31
32        response.setContentType("text/html");
33        PortletRequestDispatcher dispatcher =
34        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
35        dispatcher.include(request, response);
36
37
38    }
39
40}
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:29
Resposta

Anônimo

It's a Generic portlet:

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 4   
 5        //from variables      
 6        String formType = request.getParameter("formType");
 7        String buttonClicked = request.getParameter("button");
 8       
 9        //check what page to forward to
10        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
11       
12        //forward to "/WEB-INF/jsp/"+jsp;
13        //but how?
14       
15    }
16   
17    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
18
19        //get current tab value
20        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
21       
22        //gets data only for requested table
23        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
24        String javaScript = Tablerize.create(rs);
25        request.setAttribute("generatedScript", javaScript);
26
27        //prints out javascript in console for reference
28        System.out.println("----------------------------------------------");
29        System.out.println(javaScript);
30        System.out.println("----------------------------------------------");
31
32        response.setContentType("text/html");
33        PortletRequestDispatcher dispatcher =
34        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
35        dispatcher.include(request, response);
36
37
38    }
39
40}
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:30
Resposta

Anônimo

It's a Generic portlet:

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 4   
 5        //from variables      
 6        String formType = request.getParameter("formType");
 7        String buttonClicked = request.getParameter("button");
 8       
 9        //check what page to forward to
10        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
11       
12        //forward to "/WEB-INF/jsp/"+jsp;
13        //but how?
14       
15    }
16   
17    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
18
19        //get current tab value
20        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
21       
22        //gets data only for requested table
23        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
24        String javaScript = Tablerize.create(rs);
25        request.setAttribute("generatedScript", javaScript);
26
27        //prints out javascript in console for reference
28        System.out.println("----------------------------------------------");
29        System.out.println(javaScript);
30        System.out.println("----------------------------------------------");
31
32        response.setContentType("text/html");
33        PortletRequestDispatcher dispatcher =
34        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
35        dispatcher.include(request, response);
36
37
38    }
39
40}


Thanks for looking at this
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:31
Resposta

Anônimo

It's a Generic portlet:

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 4   
 5        //from variables      
 6        String formType = request.getParameter("formType");
 7        String buttonClicked = request.getParameter("button");
 8       
 9        //check what page to forward to
10        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
11       
12        //forward to "/WEB-INF/jsp/"+jsp;
13        //but how?
14       
15    }
16   
17    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
18
19        //get current tab value
20        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
21       
22        //gets data only for requested table
23        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
24        String javaScript = Tablerize.create(rs);
25        request.setAttribute("generatedScript", javaScript);
26
27        //prints out javascript in console for reference
28        System.out.println("----------------------------------------------");
29        System.out.println(javaScript);
30        System.out.println("----------------------------------------------");
31
32        response.setContentType("text/html");
33        PortletRequestDispatcher dispatcher =
34        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
35        dispatcher.include(request, response);
36
37
38    }
39
40}
Sandeep Nair
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:46
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1691

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

Try this

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 4   
 5        //from variables      
 6        String formType = request.getParameter("formType");
 7        String buttonClicked = request.getParameter("button");
 8   
 9   
10        //check what page to forward to
11        String jsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
12      
13        actionResponse.setRenderParameter("jsp",jsp);
14        //forward to "/WEB-INF/jsp/"+jsp;
15        //but how?
16      
17    }
18   
19    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
20
21        //get current tab value
22        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
23      
24        //gets data only for requested table
25        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
26        String javaScript = Tablerize.create(rs);
27        request.setAttribute("generatedScript", javaScript);
28
29        //prints out javascript in console for reference
30        System.out.println("----------------------------------------------");
31        System.out.println(javaScript);
32        System.out.println("----------------------------------------------");
33
34        response.setContentType("text/html");
35
36    String jsp = ParamUtil.getString(request,"jsp","MedelogGetAdmin_view.jsp");
37        PortletRequestDispatcher dispatcher =
38        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/"+jsp);
39        dispatcher.include(request, response);



}
Anônimo
RE: Forward to JSP page from processAction()
15 de Novembro de 2011 23:50
Resposta

Anônimo

Thanks Sandeep emoticon

I just read now on another site that the doView method is called everytime before a portlet renders, even after the processAction method.
I then went ahead and changed the code a bit:

 1public class MedelogGetAdmin extends GenericPortlet {
 2   
 3    String actionJsp = "";
 4   
 5    public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
 6   
 7        //from variables      
 8        String formType = request.getParameter("formType");
 9        String buttonClicked = request.getParameter("button");
10       
11        //check what page to forward to
12        actionJsp = Action.forwardTo(formType, buttonClicked); //jsp = consumers.jsp
13       
14        //forward to "/WEB-INF/jsp/"+jsp;
15        //but how?
16       
17       
18    }
19   
20    public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
21
22        //get current tab value
23        String currentTab = ParamUtil.getString(request, "currentTab", "Consumers");
24       
25        //gets data only for requested table
26        ResultSet rs = queryDb.queryDb(currentTab.replace(" ",""));
27        String javaScript = Tablerize.create(rs);
28        request.setAttribute("generatedScript", javaScript);
29
30        //prints out javascript in console for reference
31        System.out.println("----------------------------------------------");
32        System.out.println(javaScript);
33        System.out.println("----------------------------------------------");
34
35        response.setContentType("text/html");
36       
37        if(actionJsp == null || actionJsp.equals("")){
38            PortletRequestDispatcher dispatcher =
39            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");      
40            dispatcher.include(request, response);
41        }else{
42            PortletRequestDispatcher dispatcher =
43            getPortletContext().getRequestDispatcher("/WEB-INF/jsp/"+actionJsp);      
44            dispatcher.include(request, response);
45        }
46         
47        //set the actionJsp back to default
48        actionJsp = "";
49
50    }
51
52}


and it now seems to be working perfectly. Briefly looked at your reply and looks like the same general idea is being used.
Thanks for all your help!
Puneet Upadhyay
RE: Forward to JSP page from processAction()
16 de Novembro de 2011 00:29
Resposta

Puneet Upadhyay

Ranking: Regular Member

Mensagens: 234

Data de entrada: 22 de Outubro de 2011

Mensagens recentes

MVC Portlet
Sandeep Nair
RE: Forward to JSP page from processAction()
26 de Setembro de 2013 22:28
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1691

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

Resource phase of portlet lifecycle should only be use to serve binary content or make ajax calls. If you want to forward to a jsp after performing your business logic please use the Action phase and then redirect to a view.
asif aftab
RE: Forward to JSP page from processAction()
15 de Outubro de 2013 08:54
Resposta

asif aftab

Ranking: Junior Member

Mensagens: 74

Data de entrada: 2 de Setembro de 2013

Mensagens recentes

I am using mvcportlet and to redirect to another jsp I am using setrenderparameter, each and every thing is working and path is looks like path/to/my/view.jsp
but at the time of execution I am getting an error that pat/to/my/view.jsp&quot; not found
from where "&quot" is this one is coming. I searched alot in net but no satisfactory answer that resolve my problem.
please help me
I want to navigate from second.jsp to view.jsp but by using button, I have remedy but by using anchor tag but the problem is I have to use button to navigate
my second.jsp code is
 1
 2<portlet:actionURL var="viewCall" name="returnView">
 3     <portlet:param name="jspPage" value="/html/shop_searc/view.jsp"/>
 4</portlet:actionURL>
 5
 6<aui:script>
 7function viewFun()                                                                                        //redirect to insert action class
 8{
 9     document.getElementById("<portlet:namespace />viewDisplayd").action='<%=viewCall.toString()%>';
10     document.getElementById('<portlet:namespace />viewDisplayd').submit();
11    
12}
13</aui:script>
14
15<aui:form name="viewDisplayd"  method="post">
16       
17                       <tr><td><aui:input type="button" value="back" name="hello" onclick="viewFun();"></aui:input></td></tr>
18         
19    </aui:form>

my action class code is
1
2@ProcessAction(name="returnView")
3    public void returnView(ActionRequest req, ActionResponse res)
4            throws PortletException, SystemException, RemoteException
5            {
6                res.setRenderParameter("jspPage","/Shop_Search/html/shop_searc/view.jsp");
7            
8            }
Muhammad Taha
RE: Forward to JSP page from processAction()
15 de Outubro de 2013 10:46
Resposta

Muhammad Taha

Ranking: Junior Member

Mensagens: 65

Data de entrada: 1 de Maio de 2012

Mensagens recentes

Hi Asif, I you just want to navigate to another jsp file you don't have to use action url. u can simply navigate using renderURL.
1
2<portlet:renderURL var="viewCall">
3       <portlet:param name="jspPage" value="/html/shop_searc/view.jsp"/>
4</portlet:renderURL>
asif aftab
RE: Forward to JSP page from processAction()
15 de Outubro de 2013 11:32
Resposta

asif aftab

Ranking: Junior Member

Mensagens: 74

Data de entrada: 2 de Setembro de 2013

Mensagens recentes

thanks for your quick reply