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 ");