Fóruns

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

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
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: 883

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: 1721

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"); "
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()
15 de Novembro de 2011 23:05
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1721

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: 1721

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!