How to show error message in liferay portal?

戏子无情 提交于 2019-12-29 05:50:11

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/11032229/how-to-show-error-message-in-liferay-portal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!