java 如何在 liferay 门户中显示错误消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11032229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show error message in liferay portal?
提问by test1604
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?
如何在 liferay 门户中显示错误消息?我在 liferay.com 网站上读到,为了显示错误消息,我可以使用标签库中的 liferay-ui:error 标签,但它不起作用,如何使用它?
回答by Jonny
You are right in about "liferay-ui:error" tag so on your JSP you will have:
您对“liferay-ui:error”标签是正确的,因此在您的 JSP 上,您将拥有:
<%@ 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:
然后在您的 Java 代码中,您通常需要 RenderRequest 或 ActionRequest,但也可以使用任何类型的 HTTPServletRequest 或 PortletRequest。然后将请求对象传递给静态 SessionErrors.add() 方法,如下所示:
SessionErrors.add(actionRequest, "some-error");
Then error will appear next time the portlet enters it's Render Phase.
那么下次 portlet 进入它的渲染阶段时就会出现错误。
Also another variation of the tag
would be:
的另一个变体tag
是:
<liferay-ui:error exception="<%= SomeException.class %>" message="This is Some Error" />
With the SessionErrors
code like:
有了SessionErrors
这样的代码:
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
您可以在此处查看完整的 SessionErrors JavaDoc:http: //docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/kernel/servlet/SessionErrors.html
Any questions, just leave a comment!
有任何问题,只需发表评论!