Forums de discussion

Liferay MVC load default view

Beppo Ivel, modifié il y a 9 années.

Liferay MVC load default view

Regular Member Publications: 112 Date d'inscription: 09/04/14 Publications récentes
Hi.

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


public class UploadPortlet extends MVCPortlet {

	protected String editJSP;
	protected String viewJSP;
	private static Log _log = LogFactory.getLog(UploadPortlet.class);
	
	

	public void init() throws PortletException {

		editJSP = getInitParameter("edit-jsp");
		viewJSP = getInitParameter("view-jsp");

	}

	public void doView(RenderRequest renderRequest,
			RenderResponse renderResponse) throws IOException, PortletException {

		PortletPreferences prefs = renderRequest.getPreferences();
		String username = (String) prefs.getValue("name", "no");
		if (username.equalsIgnoreCase("no")) {
			username = "";
		}
		renderRequest.setAttribute("userName", username);

		include(viewJSP, renderRequest, renderResponse);
	}

	protected void include(String path, RenderRequest renderRequest,
			RenderResponse renderResponse) throws IOException, PortletException {

		PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
				.getRequestDispatcher(path);

		if (portletRequestDispatcher == null) {
			_log.error(path + " is not a valid include");
		} else {
			portletRequestDispatcher.include(renderRequest, renderResponse);
		}
	}

	public void doEdit(RenderRequest renderRequest,
			RenderResponse renderResponse) throws IOException, PortletException {

		renderResponse.setContentType("text/html");
		PortletURL addNameURL = renderResponse.createActionURL();
		addNameURL.setParameter("addName", "addName");
		renderRequest.setAttribute("addNameURL", addNameURL.toString());
		include(editJSP, renderRequest, renderResponse);
	}
}


But I want to schow the view.jsp by the MVC way. I know I can change in some action the via
response.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.
thumbnail
Zsigmond Rab, modifié il y a 9 années.

RE: Liferay MVC load default view

Liferay Master Publications: 727 Date d'inscription: 05/01/10 Publications récentes
Hi Beppo,

have you read this doc already?

Regards,
Zsigmond
thumbnail
Andew Jardine, modifié il y a 9 années.

RE: Liferay MVC load default view

Liferay Legend Publications: 2416 Date d'inscription: 22/12/10 Publications récentes
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).
thumbnail
Sandip Patel, modifié il y a 9 années.

RE: Liferay MVC load default view

Regular Member Publications: 205 Date d'inscription: 05/01/11 Publications récentes
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