Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Beppo Ivel
Liferay MVC load default view
June 3, 2014 6:26 AM
Answer

Beppo Ivel

Rank: Regular Member

Posts: 112

Join Date: April 9, 2014

Recent Posts

Hi.

If I use doView and doEdit methods I get a working Portlet:

 1
 2public class UploadPortlet extends MVCPortlet {
 3
 4    protected String editJSP;
 5    protected String viewJSP;
 6    private static Log _log = LogFactory.getLog(UploadPortlet.class);
 7   
 8   
 9
10    public void init() throws PortletException {
11
12        editJSP = getInitParameter("edit-jsp");
13        viewJSP = getInitParameter("view-jsp");
14
15    }
16
17    public void doView(RenderRequest renderRequest,
18            RenderResponse renderResponse) throws IOException, PortletException {
19
20        PortletPreferences prefs = renderRequest.getPreferences();
21        String username = (String) prefs.getValue("name", "no");
22        if (username.equalsIgnoreCase("no")) {
23            username = "";
24        }
25        renderRequest.setAttribute("userName", username);
26
27        include(viewJSP, renderRequest, renderResponse);
28    }
29
30    protected void include(String path, RenderRequest renderRequest,
31            RenderResponse renderResponse) throws IOException, PortletException {
32
33        PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
34                .getRequestDispatcher(path);
35
36        if (portletRequestDispatcher == null) {
37            _log.error(path + " is not a valid include");
38        } else {
39            portletRequestDispatcher.include(renderRequest, renderResponse);
40        }
41    }
42
43    public void doEdit(RenderRequest renderRequest,
44            RenderResponse renderResponse) throws IOException, PortletException {
45
46        renderResponse.setContentType("text/html");
47        PortletURL addNameURL = renderResponse.createActionURL();
48        addNameURL.setParameter("addName", "addName");
49        renderRequest.setAttribute("addNameURL", addNameURL.toString());
50        include(editJSP, renderRequest, renderResponse);
51    }
52}


But I want to schow the view.jsp by the MVC way. I know I can change in some action the via
1response.setRenderParameter("jspPage", "path/to/your/view");
but where I can set the default view? Because if I load my portlet without the methods above I see nothing.
Zsigmond Rab
RE: Liferay MVC load default view
June 5, 2014 12:06 PM
Answer

Zsigmond Rab

LIFERAY STAFF

Rank: Liferay Master

Posts: 650

Join Date: January 4, 2010

Recent Posts

Hi Beppo,

have you read this doc already?

Regards,
Zsigmond
Andrew Jardine
RE: Liferay MVC load default view
June 5, 2014 2:23 PM
Answer

Andrew Jardine

Community Moderator

Rank: Liferay Legend

Posts: 1062

Join Date: December 22, 2010

Recent Posts

The nice thing about using the MVCPortlet is that you don't have to override the gross doView method. YOu can overrider the render(RenderRequest, RenderResponse) method. In there simply call include("jspPage", <YOUR_PAGE_REFERENCE>); and you should be good. Just dont forget to make sure that the last statement in the method should be a call to super.doView(renderRequest, renderResponse).
Sandip Patel
RE: Liferay MVC load default view
June 6, 2014 1:27 AM
Answer

Sandip Patel

Rank: Regular Member

Posts: 191

Join Date: January 4, 2011

Recent Posts

If you are not definfing doView method then It will direct take default doView from super class and will redirect to jsp file which is define in
<init-param>
<name>view-jsp</name>
<value>/view.jsp</value>
</init-param>

If you want to redirect to your own way then you have to use include("jspPage", <YOUR_PAGE_REFERENCE>);

HTH