留言板

how versitile is the <liferay-ui:error> tag?

Fazle Khan,修改在17 年前。

how versitile is the <liferay-ui:error> tag?

Junior Member 帖子: 26 加入日期: 06-2-8 最近的帖子
I understand the basic usage of the <liferay-us:error> tag for example I have the following tag on my jsp

<liferay-ui:error exception="<%= EasyStreetUpgradeHelper.RoadSegmentOneMissing.class %>" message="road-segment-one-missing-exception" />

The thing is there are 8 tags that are very similiar that report errors for 8 very simliar pieces of data with 8 seperate 8 messages. I'd prefer to have a single tag and error message for these 8 pieces of data and just pass in text as a parameter when adding the error to the session.

does anyone have suggestion on how to do that? I see one case in the language.properties provided by liferay where it look like they have parameterized thier message because it include {0} and a {1} but I can't seem to get it to work for exceptions.

-fazle
thumbnail
Russ Danner,修改在17 年前。

RE: how versitile is the <liferay-ui:error> tag?

Regular Member 帖子: 149 加入日期: 06-2-7 最近的帖子
Fazel,

I'd like to help here but at least for me your message doesnt compute emoticon I think your example is missing which would provide a critical piece of information: which tag you are talking about.

Liferay does support localization and parameterized message hence the {0} items in the message definitions.

How do exceptions and jsp tags relate per se?
Jaipanos Thomas,修改在12 年前。

RE: how versitile is the <liferay-ui:error> tag?

New Member 帖子: 2 加入日期: 11-4-8 最近的帖子
Russ Danner:
Fazel,

I'd like to help here but at least for me your message doesnt compute emoticon I think your example is missing which would provide a critical piece of information: which tag you are talking about.

Liferay does support localization and parameterized message hence the {0} items in the message definitions.

How do exceptions and jsp tags relate per se?



You mean to say that there is no way we can dipaly an error message with parameter emoticon

I am looking for a way by which i can display error message with parameters using <liferay-ui:error> tag.

How can i add a parameter to SessionErrors

The method SessionErrors.add(PortletRequest portletRequest, String key, Object value) - what is the relevance of Object value . where it can be used?
thumbnail
Igor Beslic,修改在8 年前。

RE: how versitile is the <liferay-ui:error> tag?

New Member 帖子: 17 加入日期: 11-8-17 最近的帖子
Jaipanos Thomas:
You mean to say that there is no way we can dipaly an error message with parameter emoticon


For those who will bump into this question.
SessionErrors#add(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.Object)
and similar methods don't use third argument as parameter for language tool. Value object would be stored into taglib's internal map where key would be key passed to method, and value would be passed object.

So, to cut the story, here is how you can get parametrized error messages in Liferay MVC portlet based portlets:
1. Catch Exception and add error to SessionErrors

catch (Exception e) {
		SessionErrors.add(
			portletRequest, "generic-error-message-key",
			e.getMessage());
	}

2. JSP code that displays error message

<liferay-ui:error key="generic-error-message-key">
	<liferay-ui:message key="your-request-failed-with-message" arguments="<%= SessionErrors.get(liferayPortletRequest, &quot;generic-error-message-key&quot;) %>" />
</liferay-ui:error>

3. Language.properties
your-request-failed-with-message=Your request failed with message: {0}


Note that there is alternative to step 2 but you loose consistency with liferay css and html structure conventions:

<c:if test="<%= SessionErrors.contains(&quot;generic-error-message-key&quot;) %>">
</c:if>
<liferay-ui:message key="your-request-failed-with-message" arguments="<%= SessionErrors.get(liferayPortletRequest, &quot;generic-error-message-key&quot;) %>" < div> </liferay-ui:message>


Hope this helps!