Fórumok
SessionErrors always shows default Error Message
Ricardo Jorge Vandelay, módosítva 14 év-val korábban
SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
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:
and showing in the JSP:
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?
Best Regards.
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:
SessionErrors.add(actionRequest, "insertTitleError");
and showing in the JSP:
<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?
<c:when test="<%= key == null %>">
<c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
<span class="portlet-msg-error">
<liferay-ui:message key="you-have-entered-invalid-data" />
</span>
<%= rowBreak %>
</c:if>
</c:when>
Best Regards.
Ricardo J. Vandelay, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
bump
Ricardo J. Vandelay, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
bump
I spent a whole afternoon debugging this problem and I cannot figure out why this happens. Blergh!
I spent a whole afternoon debugging this problem and I cannot figure out why this happens. Blergh!
Amos Fong, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
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?
Does the user go directly to the jsp with that error tag after you set a SessionError?
Ricardo J. Vandelay, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
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
configuration.jsp
<liferay-ui:error> doesn't work
<liferay-ui:success> works well
class
Thank you.
I'm using SessionErrors for my portlet's configuration area. Here is the full code for configuration.jsp and the configuration class.
init.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import="com.liferay.portal.kernel.util.PrefsParamUtil" %>
<%@ page import="com.liferay.portal.PortalException" %>
<%@ page import="com.liferay.portal.kernel.servlet.SessionErrors" %>
<%@ page import="com.liferay.portal.kernel.servlet.SessionMessages" %>
<portlet:defineobjects />
<liferay-theme:defineobjects />
<%
PortletPreferences preferences = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");
if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}
%>
configuration.jsp
<%@ include file="/jsp/init.jsp" %>
<%
String name = PrefsParamUtil.getString(preferences, request, "name", "");
%>
<liferay-ui:error key="baseErrorKey" message="error-message" />
<liferay-ui:success key="baseMessageKey" message="success-message" />
<form action="<liferay-portlet:actionURL portletConfiguration=" true">" method="post" id="<portlet:namespace />fm" name="<portlet:namespace />fm">
<div>
<label for="<portlet:namespace />-name"><liferay-ui:message key="insert-your-name" /></label>
<input name="<portlet:namespace />name" id="<portlet:namespace />-name" type="text" value="<%= HtmlUtil.escape(name) %>">
</div>
<input type="submit" value="<liferay-ui:message key=" save-information">" />
</form>
<liferay-ui:error> doesn't work
<liferay-ui:success> works well
class
package com.jump.base.configuration;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.PortalException;
import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portlet.PortletPreferencesFactoryUtil;
public class Configuration extends BaseConfigurationAction {
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
String portletResource = ParamUtil.getString(actionRequest, "portletResource");
PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
String name = ParamUtil.getString(actionRequest, "name");
preferences.setValue("name", name);
preferences.store();
SessionErrors.add(actionRequest, "baseErrorKey");
SessionMessages.add(actionRequest, "baseMessageKey");
}
public String render(PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
return "/jsp/backend/configuration.jsp";
}
}
Thank you.
Amos Fong, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
Strange...but SessionErrors can't be empty because this:
What version of Liferay are you using? Is this in a plugin?
<c:when test="<%= key == null %>">
<c:if test="<%= !SessionErrors.isEmpty(portletRequest) %>">
<div class="portlet-msg-error">
<liferay-ui:message key="you-have-entered-invalid-data" />
</div></c:if></c:when>
What version of Liferay are you using? Is this in a plugin?
Ricardo J. Vandelay, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
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
Its returns true and if I print
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.
You are correct but in the beginning of that JSP if I do a
System.out.println(SessionErrors.isEmpty(portletRequest));
Its returns true and if I print
SessionErrors.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, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
Liferay Legend Bejegyzések: 1744 Csatlakozás dátuma: 2008.11.06. Legújabb bejegyzések
Did you find a solution?
Regards,
Sandeep
Regards,
Sandeep
Ricardo J. Vandelay, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 17 Csatlakozás dátuma: 2010.02.24. Legújabb bejegyzések
No I didn't. Still have the same issue.
Sandeep Nair, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
Liferay Legend Bejegyzések: 1744 Csatlakozás dátuma: 2008.11.06. Legújabb bejegyzések
It only creates problem for configuration.jsp. For normal jsps it works fine.
Regards,
Sandeep
Regards,
Sandeep
Babu Janarthanan, módosítva 14 év-val korábban
RE: SessionErrors always shows default Error Message
Regular Member Bejegyzések: 128 Csatlakozás dátuma: 2008.07.31. Legújabb bejegyzések
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.
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, módosítva 13 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 43 Csatlakozás dátuma: 2010.04.27. Legújabb bejegyzések
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?
Is it a bug?
Denis Signoretto, módosítva 13 év-val korábban
RE: SessionErrors always shows default Error Message
Expert Bejegyzések: 375 Csatlakozás dátuma: 2009.04.21. Legújabb bejegyzések
http://issues.liferay.com/browse/LPS-12402
Did you find any workaround?
Did you find any workaround?
Arne Timmerman, módosítva 13 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzés: 1 Csatlakozás dátuma: 2011.03.29. Legújabb bejegyzések
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, módosítva 13 év-val korábban
RE: SessionErrors always shows default Error Message
Expert Bejegyzések: 329 Csatlakozás dátuma: 2011.02.10. Legújabb bejegyzések
I am using Liferay 6.0.
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!!
is there a possibility that we might be missing some kind of configuration in the liferay-portlet.xml??
Currently I have handled it manually by setting error key attributes directly in request, the following is a skeleton of the jsp code:
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
Anyone's help is much appreciated.
Thank You
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!!
is there a possibility that we might be missing some kind of configuration in the liferay-portlet.xml??
Currently I have handled it manually by setting error key attributes directly in request, the following is a skeleton of the jsp code:
<c:if test="${not empty customErrorKey}">
<div class="portlet-msg-error">
<liferay-ui:message key="my-custom-error-msg" />
</div>
<c:if></c:if></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
<liferay-ui:message key="you-have-entered-invalid-data" />
Anyone's help is much appreciated.
Thank You
olivier spieser, módosítva 12 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 13 Csatlakozás dátuma: 2011.06.06. Legújabb bejegyzések
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 :
2 -Then, in the configure action I simply add SessionErrors I want to display :
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.
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 :
<liferay-ui:success key="<%= portletName + ".doConfigure" %>" message="you-have-successfully-updated-the-setup" />
<liferay-ui:success key="<%= portletName + ".doEdit" %>" message="you-have-successfully-updated-your-preferences" />
<%
Iterator<string> itErrors = SessionErrors.iterator(renderRequest);
while (itErrors.hasNext()){
String errorKey = itErrors.next();
if (StringUtils.startsWith(errorKey , portletName)
&& StringUtils.endsWith(errorKey , ".doConfigure")) {
String errorMessage = StringUtils.substringBetween(errorKey ,portletName+".", ".doConfigure");
%>
<liferay-ui:error key="<%=errorKey%>" message="<%=errorMessage%>" />
<%
}
}
%>
<liferay-ui:error /></string>
2 -Then, in the configure action I simply add SessionErrors I want to display :
SessionErrors.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 Dhulipalla, módosítva 12 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 3 Csatlakozás dátuma: 2009.07.29. Legújabb bejegyzések
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
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, módosítva 12 év-val korábban
RE: SessionErrors always shows default Error Message
Expert Bejegyzések: 329 Csatlakozás dátuma: 2011.02.10. Legújabb bejegyzések
Thanks Harish for the info.
Rob Hall, módosítva 11 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 47 Csatlakozás dátuma: 2011.11.30. Legújabb bejegyzések
Is there any way to define this through the portlet.properties configuration?
Abdelrahman Mohamed El Ghanam, módosítva 11 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 41 Csatlakozás dátuma: 2010.09.30. Legújabb bejegyzések
Does this have to be in a certain phase ? cause it doesnt work for me in the render phase ..
Atin Agarwal, módosítva 11 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 86 Csatlakozás dátuma: 2012.02.20. Legújabb bejegyzések
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, módosítva 11 év-val korábban
RE: SessionErrors always shows default Error Message
Regular Member Bejegyzések: 153 Csatlakozás dátuma: 2008.11.25. Legújabb bejegyzések
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
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, módosítva 10 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 29 Csatlakozás dátuma: 2012.10.19. Legújabb bejegyzések
Hey folks,
same here. I'm developing on Liferay 6.1.1 CE / Tomcat 7.0.27 and followed the documentation here.
Here is my jsp:
Here are two methods from my action class:
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
same here. I'm developing on Liferay 6.1.1 CE / Tomcat 7.0.27 and followed the documentation here.
Here is my jsp:
<liferay-ui:error key="tos-required" message="error.required.terms-of-service" />
<liferay-ui:success key="form-processed" message="success.form-processed" />
<liferay-portlet:actionurl var="processFormURL" name="processForm" />
<aui:form action="<%= processFormURL.toString() %>">
<aui:input name="termsofservice" type="checkbox" label="label.terms-of-service" checked="false" />
<aui:button value="button.submit" type="submit" />
</aui:form>
Here are two methods from my action class:
public void processForm(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException{
if(ParamUtil.getBoolean(actionRequest, "termsofservice") == false)
SessionErrors.add(actionRequest, "tos-required");
else
SessionMessages.add(actionRequest, "form-processed");
}
@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
LiferayPortletConfig config =
(LiferayPortletConfig)actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
String hideDefaultMessage =
config.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE;
SessionMessages.add(actionRequest, hideDefaultMessage);
super.processAction(actionRequest, actionResponse);
}
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, módosítva 10 év-val korábban
RE: SessionErrors always shows default Error Message
New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.04.17. Legújabb bejegyzések
Hi phil,
Try using the below code :
SessionMessages.add(request,
PortalUtil.getPortletId(actionRequest)
+ SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
Try using the below code :
SessionMessages.add(request,
PortalUtil.getPortletId(actionRequest)
+ SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
Harish Kumar, módosítva 10 év-val korábban
RE: SessionErrors always shows default Error Message
Expert Bejegyzések: 483 Csatlakozás dátuma: 2010.07.31. Legújabb bejegyzések
Use the below code snippet to hide SessionErrors default error message
hope this helps!
PortletConfig portletConfig = (PortletConfig)renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;
SessionMessages.add(renderRequest, liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
hope this helps!
Philipp Schwarz, módosítva 10 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 29 Csatlakozás dátuma: 2012.10.19. Legújabb bejegyzések
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
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, módosítva 9 év-val korábban
RE: SessionErrors always shows default Error Message
Junior Member Bejegyzések: 29 Csatlakozás dátuma: 2012.10.19. Legújabb bejegyzések
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
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