Some Basic notes for liferay Portlet MVC development

Source: Internet
Author: User

1. Use redirection with Java code

Direct call

Result. jsp is the address of the page to be switched.

 String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest), portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);  redirectURL.setParameter("jspPage", "/result.jsp");

You can also add other parameters.
Redirecturl. setparameter ("test", "value ");
Redirecturl. setparameter ("jsppage", "/result. jsp ");
Actionresponse. sendredirect (redirecturl. tostring ());

2. Use include to add different JSP pages

No test is available to pass parameters.

Doview is called every time a page is refreshed. Of course, after the form is submitted.

Public void doview (renderrequest, renderresponse) throws ioexception, portletexception {system. Out. println ("doview !! "); Renderresponse. setcontenttype (" text/html "); string res = renderrequest. getparameter (" result "); If (res! = NULL) {renderrequest. setattribute ("result", Res); system. out. println ("successful"); Include ("/result. JSP ", renderrequest, renderresponse); // getportletcontext (). getrequestdispatcher ("/result. JSP "). forward (renderrequest, renderresponse);} elseinclude ("/view. JSP ", renderrequest, renderresponse); // super. doview (renderrequest, renderresponse );}

3. Display messages

This can be used in Java classes.

SessionMessages.add(actionRequest, "request_processed", "this-is-my-custom-success-message") 

SessionErrors.add(actionRequest, "error-key");

You can cancel displaying all messages in the configuration file:

<init-param><name>add-process-action-success-action</name><value>false</value></init-param>

And in the JSP of your Portlet:

<liferay-ui:error key="error-key" message="this-is-error-message-1" /><liferay-ui:error key="error-key-2" message="this-is-error-message-2" />

4. multi-language support

Welcome is the key, in the language properties.

1) JSP: <UI: Message key = "welcome"> </UI: Message>

<% = Languageutil. Get (locale, "welcome") %>

2) Java class

Or receivageutil. Get (renderrequest. getlocale (), "welcome ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.