Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

java - How to show error message in liferay portal?

How to show error message in liferay portal? I read on liferay.com site that for show error message I can use liferay-ui:error tag from tag library, but it's not working, how to use it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are right in about "liferay-ui:error" tag so on your JSP you will have:

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<liferay-ui:error key="some-error" message="Your error message goes here!" />

Then in your Java code you will need either the RenderRequest or ActionRequest normally however any type of HTTPServletRequest or PortletRequest can also be used. Then you pass your request object to the static SessionErrors.add() method, like so:

SessionErrors.add(actionRequest, "some-error");

Then error will appear next time the portlet enters it's Render Phase.

Also another variation of the tag would be:

<liferay-ui:error exception="<%= SomeException.class %>" message="This is Some Error" />

With the SessionErrors code like:

try {
    // ... your code which throws the exception goes here
} catch(SomeException se) {
    SessionErrors.add(actionRequest, se.getClass().getName());
}

You can check the full SessionErrors JavaDoc here: http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/kernel/servlet/SessionErrors.html

Any questions, just leave a comment!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...