Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Cameron McBride
How to use SessionErrors in a portlet's configuration?
March 5, 2012 12:43 PM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

Recent Posts

That sounds like it should be super easy right? SessionMessages seems to work perfectly but SessionErrors does not work as you would expect.

Here is my small config.jsp. It contains two buttons, one to submit a success and one to submit an error.
 1<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
 2<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
 3<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
 4
 5<liferay-ui:success key="my-success" message="my-success" />
 6<liferay-ui:error key="my-error" message="my-error" />
 7
 8<liferay-portlet:actionURL portletConfiguration="true" var="successURL" />
 9<aui:form action="<%= successURL %>" method="POST" name="fm">
10    <aui:input type="hidden" name="formName" value="success" />
11    <aui:button type="submit" value="Success" />
12</aui:form>
13
14<liferay-portlet:actionURL portletConfiguration="true" var="errorURL" />
15<aui:form action="<%= errorURL %>" method="POST" name="fm">
16    <aui:input type="hidden" name="formName" value="error" />
17    <aui:button type="submit" value="Error" />
18</aui:form>

Here is my Configuration Action class. All it does is set a SessionMessages or SessionErrors.
 1public class ConfigurationActionImpl implements ConfigurationAction {
 2
 3    @Override
 4    public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
 5            ActionResponse actionResponse) throws Exception {
 6       
 7        String formName = ParamUtil.getString(actionRequest, "formName");   
 8        if (formName != null && formName.equals("success")) {
 9            SessionMessages.add(actionRequest, "my-success");
10        } else if (formName != null && formName.equals("error")) {
11            SessionErrors.add(actionRequest, "my-error");
12        }
13    }
14   
15    @Override
16    public String render(PortletConfig arg0, RenderRequest arg1,
17            RenderResponse arg2) throws Exception {
18        return "/config.jsp";
19    }
20}

Clicking the Success button will show the correct success message. Clicking Error will show "You have entered invalid data" but will not show the specific error message. I have not tested this in 6.1 to see if it is a problem there, this is currently 6.0.6 CE.
Attachment

Attachments: error.png (8.6k)
Cameron McBride
RE: How to use SessionErrors in a portlet's configuration?
March 5, 2012 1:15 PM
Answer

Cameron McBride

Rank: Expert

Posts: 273

Join Date: February 8, 2011

Recent Posts

I've been able to product a crotchety workaround using this thread and some extra code: http://www.liferay.com/community/forums/-/message_boards/message/5948953

Doesn't seem like this is how Liferay intended it to be.