Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
SessionErrors always shows default Error Message Ricardo Vlh March 18, 2010 12:18 PM
RE: SessionErrors always shows default Error Message Ricardo Vlh March 18, 2010 12:18 PM
RE: SessionErrors always shows default Error Message Ricardo Vlh March 22, 2010 2:35 AM
RE: SessionErrors always shows default Error Message Amos Fong March 22, 2010 10:41 AM
RE: SessionErrors always shows default Error Message Ricardo Vlh March 23, 2010 9:32 AM
RE: SessionErrors always shows default Error Message Amos Fong March 24, 2010 11:04 AM
RE: SessionErrors always shows default Error Message Ricardo Vlh March 25, 2010 3:13 AM
RE: SessionErrors always shows default Error Message Sandeep Nair April 13, 2010 4:20 AM
RE: SessionErrors always shows default Error Message Ricardo Vlh April 14, 2010 2:29 AM
RE: SessionErrors always shows default Error Message Sandeep Nair April 14, 2010 2:58 AM
RE: SessionErrors always shows default Error Message Babu Janarthanan Ramachandran April 19, 2010 5:48 AM
RE: SessionErrors always shows default Error Message Loïc Dumont July 19, 2010 6:57 AM
RE: SessionErrors always shows default Error Message Denis Signoretto September 22, 2010 1:41 AM
RE: SessionErrors always shows default Error Message Arne Timmerman March 29, 2011 5:30 AM
RE: SessionErrors always shows default Error Message Prakash Khanchandani April 20, 2011 1:26 AM
RE: SessionErrors always shows default Error Message Olivier Spieser June 16, 2011 8:55 AM
RE: SessionErrors always shows default Error Message Harish D March 21, 2012 9:33 PM
RE: SessionErrors always shows default Error Message Prakash Khanchandani April 16, 2012 2:07 AM
RE: SessionErrors always shows default Error Message Rob Hall July 20, 2012 1:17 PM
RE: SessionErrors always shows default Error Message Abdelrahman Mohamed El Ghanam September 26, 2012 9:07 AM
RE: SessionErrors always shows default Error Message Atin Agarwal October 25, 2012 11:05 PM
RE: SessionErrors always shows default Error Message Manish Kumar Jaiswal January 4, 2013 5:55 AM
RE: SessionErrors always shows default Error Message Philipp Schwarz October 30, 2013 8:47 PM
RE: SessionErrors always shows default Error Message Pradeep P November 19, 2013 3:17 AM
RE: SessionErrors always shows default Error Message Harish Kumar November 19, 2013 11:18 PM
RE: SessionErrors always shows default Error Message Philipp Schwarz November 20, 2013 9:49 AM
RE: SessionErrors always shows default Error Message Philipp Schwarz May 26, 2014 4:28 AM
Ricardo Vlh
SessionErrors always shows default Error Message
March 18, 2010 12:18 PM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

I'm trying to use the SessionErrors class to handle validation messages in my configuration form.

However, when I add a custom error message my key is never shown and instead, the "you-have-entered-invalid-data" appears.

Here is how I'm adding:
1
2SessionErrors.add(actionRequest, "insertTitleError");


and showing in the JSP:
1
2<liferay-ui:error key="insertTitleError" message="error-please-insert-title" />


I have looked at the code in the error taglib and the "you-have-entered-invalid-data" message is shown when the key is null. Why is my session message disappearing?

 1
 2    <c:when test="<%= key == null %>">
 3        <c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
 4            <span class="portlet-msg-error">
 5            <liferay-ui:message key="you-have-entered-invalid-data" />
 6            </span>
 7
 8            <%= rowBreak %>
 9        </c:if>
10    </c:when>


Best Regards.
Ricardo Vlh
RE: SessionErrors always shows default Error Message
March 18, 2010 12:18 PM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

bump
Ricardo Vlh
RE: SessionErrors always shows default Error Message
March 22, 2010 2:35 AM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

bump

I spent a whole afternoon debugging this problem and I cannot figure out why this happens. Blergh!
Amos Fong
RE: SessionErrors always shows default Error Message
March 22, 2010 10:41 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1896

Join Date: October 7, 2008

Recent Posts

Your code looks correct to me. Is SessionErrors always empty?

Does the user go directly to the jsp with that error tag after you set a SessionError?
Ricardo Vlh
RE: SessionErrors always shows default Error Message
March 23, 2010 9:32 AM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

When it enters end.jsp in the tag's HTML key and message are null and SessionErrors is empty. I've put some breakpoints in the clear methods in the SessionErrors class and they are only called after end.jsp is executed.

I'm using SessionErrors for my portlet's configuration area. Here is the full code for configuration.jsp and the configuration class.

init.jsp
 1
 2<%@ page contentType="text/html; charset=UTF-8" %>
 3
 4<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 5<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
 6<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
 7<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
 8
 9<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
10<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
11<%@ page import="javax.portlet.PortletPreferences" %>
12<%@ page import="com.liferay.portal.kernel.util.Validator" %>
13<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
14<%@ page import="com.liferay.portal.kernel.util.PrefsParamUtil" %>
15<%@ page import="com.liferay.portal.PortalException" %>
16
17
18<%@ page import="com.liferay.portal.kernel.servlet.SessionErrors" %>
19<%@ page import="com.liferay.portal.kernel.servlet.SessionMessages" %>
20
21<portlet:defineObjects />
22<liferay-theme:defineObjects />
23
24<%
25
26PortletPreferences preferences = renderRequest.getPreferences();
27String portletResource = ParamUtil.getString(request, "portletResource");
28
29if (Validator.isNotNull(portletResource)) {
30    preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
31}
32
33%>


configuration.jsp
 1
 2<%@ include file="/jsp/init.jsp" %>
 3<%
 4String name = PrefsParamUtil.getString(preferences, request, "name", "");
 5
 6%>
 7
 8<liferay-ui:error key="baseErrorKey" message="error-message" />
 9<liferay-ui:success key="baseMessageKey" message="success-message" />
10
11<form action="<liferay-portlet:actionURL portletConfiguration="true" />" method="post" id="<portlet:namespace />fm" name="<portlet:namespace />fm">
12    <div>
13        <label for="<portlet:namespace />-name"><liferay-ui:message key="insert-your-name" /></label>
14        <input name="<portlet:namespace />name" id="<portlet:namespace />-name" type="text" value="<%= HtmlUtil.escape(name) %>" />
15    </div>
16    <input type="submit" value="<liferay-ui:message key="save-information" />" />
17</form>


<liferay-ui:error> doesn't work
<liferay-ui:success> works well

class
 1
 2package com.jump.base.configuration;
 3
 4import javax.portlet.ActionRequest;
 5import javax.portlet.ActionResponse;
 6import javax.portlet.PortletConfig;
 7import javax.portlet.PortletPreferences;
 8import javax.portlet.RenderRequest;
 9import javax.portlet.RenderResponse;
10
11import com.liferay.portal.PortalException;
12import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
13import com.liferay.portal.kernel.servlet.SessionErrors;
14import com.liferay.portal.kernel.servlet.SessionMessages;
15import com.liferay.portal.kernel.util.ParamUtil;
16import com.liferay.portlet.PortletPreferencesFactoryUtil;
17
18public class Configuration extends BaseConfigurationAction {
19    public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
20        String portletResource = ParamUtil.getString(actionRequest, "portletResource");
21        PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
22       
23        String name = ParamUtil.getString(actionRequest, "name");
24        preferences.setValue("name", name);
25        preferences.store();
26       
27        SessionErrors.add(actionRequest, "baseErrorKey");
28        SessionMessages.add(actionRequest, "baseMessageKey");
29    }
30
31    public String render(PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
32        return "/jsp/backend/configuration.jsp";
33    }
34}


Thank you.
Amos Fong
RE: SessionErrors always shows default Error Message
March 24, 2010 11:04 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1896

Join Date: October 7, 2008

Recent Posts

Strange...but SessionErrors can't be empty because this:

1    <c:when test="<%= key == null %>">
2        <c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
3            <div class="portlet-msg-error">
4                <liferay-ui:message key="you-have-entered-invalid-data" />
5            </div>


What version of Liferay are you using? Is this in a plugin?
Ricardo Vlh
RE: SessionErrors always shows default Error Message
March 25, 2010 3:13 AM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

I'm developing a Portlet using Liferay 5.2.3 with the Plugins SDK. I've also compiled and deployed the Portal and Ext (without any modifications).

You are correct but in the beginning of that JSP if I do a

1System.out.println(SessionErrors.isEmpty(portletRequest));


Its returns true and if I print

1SessionErrors.print(portletRequest);


it's empty.

I've also tried this portlet with a standard Liferay bundle (downloaded from the Website) and it's the same problem.

Thank you.
Sandeep Nair
RE: SessionErrors always shows default Error Message
April 13, 2010 4:20 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

Did you find a solution?

Regards,
Sandeep
Ricardo Vlh
RE: SessionErrors always shows default Error Message
April 14, 2010 2:29 AM
Answer

Ricardo Vlh

Rank: New Member

Posts: 17

Join Date: February 24, 2010

Recent Posts

No I didn't. Still have the same issue.
Sandeep Nair
RE: SessionErrors always shows default Error Message
April 14, 2010 2:58 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1721

Join Date: November 5, 2008

Recent Posts

It only creates problem for configuration.jsp. For normal jsps it works fine.

Regards,
Sandeep
Babu Janarthanan Ramachandran
RE: SessionErrors always shows default Error Message
April 19, 2010 5:48 AM
Answer

Babu Janarthanan Ramachandran

Rank: Regular Member

Posts: 132

Join Date: July 30, 2008

Recent Posts

Hi,
you can use the below mentioned code snippet.

SessionErrors.add(httpRequest, "baseErrorKey");

<c:if test="<%= SessionErrors.contains(request, "baseErrorKey") %>">

hope it works for you.
Loïc Dumont
RE: SessionErrors always shows default Error Message
July 19, 2010 6:57 AM
Answer

Loïc Dumont

Rank: Junior Member

Posts: 43

Join Date: April 27, 2010

Recent Posts

I'm having the same problem (Liferay 5.2.3, plugin-sdk). liferay-ui:error is not working in a configuration jsp but works in other jsps...

Is it a bug?
Denis Signoretto
RE: SessionErrors always shows default Error Message
September 22, 2010 1:41 AM
Answer

Denis Signoretto

Rank: Expert

Posts: 307

Join Date: April 21, 2009

Recent Posts

http://issues.liferay.com/browse/LPS-12402

Did you find any workaround?
Arne Timmerman
RE: SessionErrors always shows default Error Message
March 29, 2011 5:30 AM
Answer

Arne Timmerman

Rank: New Member

Posts: 1

Join Date: March 29, 2011

Recent Posts

This issue is still not resolved. If, for example, a required field in a configuration.jsp is not filled in and the error is added to the ActionRequest it is gone when the configuration.jsp is re-loaded (after submitting). This is a really annoying bug and affects all Liferay portlets. Did anyone found a solution?
Prakash Khanchandani
RE: SessionErrors always shows default Error Message
April 20, 2011 1:26 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

I am using Liferay 6.0.

This is a really annoying bug and affects all Liferay portlets.


It does not affect all liferay portlets, coz I can see it working in blogs portlet, you can check out the source of com.liferay.portlet.blogs.action.ConfigurationActionImpl and html/portlets/blogs/configuration.jsp.

But somehow I can't figure out why its not working in my portlet!!emoticon

is there a possibility that we might be missing some kind of configuration in the liferay-portlet.xml?? emoticon

Currently I have handled it manually by setting error key attributes directly in request, the following is a skeleton of the jsp code:
1<c:if test="${not empty customErrorKey}">
2  <div class="portlet-msg-error">
3    <liferay-ui:message key="my-custom-error-msg" />
4  </div>
5<c:if>


but this is a really crude method and hamper's code cleanliness, writing 4 lines of code and css instead of just one.

Also I have used a hook to customize the taglib/ui/error/end.jsp to not show the default error message
1<liferay-ui:message key="you-have-entered-invalid-data" />


Anyone's help is much appreciated.

Thank You
Olivier Spieser
RE: SessionErrors always shows default Error Message
June 16, 2011 8:55 AM
Answer

Olivier Spieser

Rank: New Member

Posts: 13

Join Date: June 6, 2011

Recent Posts

Hi,

I found a solution that worked for me.

1 - I overrided the file "porlet_message.jsp", I added some code to iterate over SessionErrors at the bottom of the file :

 1<liferay-ui:success key='<%= portletName + ".doConfigure" %>' message="you-have-successfully-updated-the-setup" />
 2<liferay-ui:success key='<%= portletName + ".doEdit" %>' message="you-have-successfully-updated-your-preferences" />
 3<%
 4Iterator<String> itErrors = SessionErrors.iterator(renderRequest);
 5while (itErrors.hasNext()){
 6    String errorKey =  itErrors.next();
 7    if (StringUtils.startsWith(errorKey , portletName)
 8            && StringUtils.endsWith(errorKey , ".doConfigure")) {
 9       
10        String errorMessage = StringUtils.substringBetween(errorKey ,portletName+".", ".doConfigure");
11       
12        %>
13            <liferay-ui:error key='<%=errorKey%>' message="<%=errorMessage%>" />
14        <%
15    }
16}
17%>
18
19<liferay-ui:error />


2 -Then, in the configure action I simply add SessionErrors I want to display :

1SessionErrors.add(actionRequest, portletConfig.getPortletName() + ".my-custom-error.doConfigure");


As you can see the sessionError key contains :
- the portlet Name
- The message
- The ".doConfigure" token

So, with these elements, you are sure the configure errors are only displayed in the configuration page of your portlet.
Harish D
RE: SessionErrors always shows default Error Message
March 21, 2012 9:33 PM
Answer

Harish D

Rank: New Member

Posts: 3

Join Date: July 28, 2009

Recent Posts

In liferay 6.1, default error message not get displayed after adding a key "portletName + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE" to SessionMessages.
This gives facility to disable default error messages at portlet level on need basis.

PortletConfig portletConfig = (PortletConfig)request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
SessionMessages.add(request, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

Harish
Prakash Khanchandani
RE: SessionErrors always shows default Error Message
April 16, 2012 2:07 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

Thanks Harish for the info.
Rob Hall
RE: SessionErrors always shows default Error Message
July 20, 2012 1:17 PM
Answer

Rob Hall

Rank: Junior Member

Posts: 47

Join Date: November 30, 2011

Recent Posts

Is there any way to define this through the portlet.properties configuration?
Abdelrahman Mohamed El Ghanam
RE: SessionErrors always shows default Error Message
September 26, 2012 9:07 AM
Answer

Abdelrahman Mohamed El Ghanam

Rank: Junior Member

Posts: 41

Join Date: September 30, 2010

Recent Posts

Does this have to be in a certain phase ? cause it doesnt work for me in the render phase .. emoticon
Atin Agarwal
RE: SessionErrors always shows default Error Message
October 25, 2012 11:05 PM
Answer

Atin Agarwal

Rank: Junior Member

Posts: 86

Join Date: February 19, 2012

Recent Posts


PortletConfig portletConfig = (PortletConfig)request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
SessionMessages.add(request, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);


Not working in Custom portlets.
I have tried this in hooks. It Worked perfectly.
However when i have tried this in my Custom portlet's Process Action it didn't worked..I wonder Why??
Any help wud be appreciated.


Regards
Manish Kumar Jaiswal
RE: SessionErrors always shows default Error Message
January 4, 2013 5:55 AM
Answer

Manish Kumar Jaiswal

Rank: Regular Member

Posts: 133

Join Date: November 25, 2008

Recent Posts

Hi Atin ,

Following didnt work for me as well in plugin portlet . Does any one have solved it ?

PortletConfig portletConfig = (PortletConfig)request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
SessionMessages.add(request, portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

Any help wud be appreciated.

Regards
Manish
Philipp Schwarz
RE: SessionErrors always shows default Error Message
October 30, 2013 8:47 PM
Answer

Philipp Schwarz

Rank: Junior Member

Posts: 29

Join Date: October 19, 2012

Recent Posts

Hey folks,

same here. I'm developing on Liferay 6.1.1 CE / emoticonTomcat 7.0.27 and followed the documentation here.

Here is my jsp:
1<liferay-ui:error key="tos-required" message="error.required.terms-of-service" />
2<liferay-ui:success key="form-processed" message="success.form-processed" />
3
4<liferay-portlet:actionURL var="processFormURL" name="processForm"/>
5<aui:form action="<%= processFormURL.toString() %>">
6    <aui:input name="termsofservice" type="checkbox" label="label.terms-of-service" checked="false"/>               
7    <aui:button value="button.submit" type="submit" />
8</aui:form>


Here are two methods from my action class:
 1public void processForm(ActionRequest actionRequest, ActionResponse actionResponse)
 2        throws IOException, PortletException{       
 3   
 4    if(ParamUtil.getBoolean(actionRequest, "termsofservice") == false)
 5        SessionErrors.add(actionRequest, "tos-required");
 6       
 7    else
 8        SessionMessages.add(actionRequest, "form-processed");
 9}


 1@Override
 2public void processAction(ActionRequest actionRequest,    ActionResponse actionResponse)
 3        throws IOException, PortletException {
 4
 5    LiferayPortletConfig config =
 6        (LiferayPortletConfig)actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
 7
 8    String hideDefaultMessage =
 9                config.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE;
10   
11    SessionMessages.add(actionRequest, hideDefaultMessage);
12   
13    super.processAction(actionRequest, actionResponse);
14   
15}


And this is what it looks like when the form is submitted without ticking the checkbox:


Strangely enough, the default success message doesn't get displayed, because when I do tick the checkbox, the result is the following:


It would be really helpful if someone from the liferay staff could shed some light onto this.

Thanks and happy coding,
Phil
Pradeep P
RE: SessionErrors always shows default Error Message
November 19, 2013 3:17 AM
Answer

Pradeep P

Rank: New Member

Posts: 7

Join Date: April 17, 2012

Recent Posts

Hi phil,


Try using the below code :

SessionMessages.add(request,
PortalUtil.getPortletId(actionRequest)
+ SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
Harish Kumar
RE: SessionErrors always shows default Error Message
November 19, 2013 11:18 PM
Answer

Harish Kumar

Rank: Expert

Posts: 471

Join Date: July 31, 2010

Recent Posts

Use the below code snippet to hide SessionErrors default error message

1
2PortletConfig portletConfig = (PortletConfig)renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
3LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;
4SessionMessages.add(renderRequest, liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);


hope this helps!
Philipp Schwarz
RE: SessionErrors always shows default Error Message
November 20, 2013 9:49 AM
Answer

Philipp Schwarz

Rank: Junior Member

Posts: 29

Join Date: October 19, 2012

Recent Posts

Hey Pradeep and Harish,

big thanks for your proposals!

I will have to wait for the next release cycle before I can test this, but it's definitely worth a shot. If it works we should also make an effort to update the documentation which clearly states to use the portlet name instead of the portlet id.

Anyways, thanks again,
happy coding,
Phil
Philipp Schwarz
RE: SessionErrors always shows default Error Message
May 26, 2014 4:28 AM
Answer

Philipp Schwarz

Rank: Junior Member

Posts: 29

Join Date: October 19, 2012

Recent Posts

Hey Harish,

I know it's been a while but I just wanted to let you know that your snippet did the job for me!

Thanks again,
Philipp