简体   繁体   English

如何在liferay门户中显示错误消息?

[英]How to show error message in liferay portal?

How to show error message in liferay portal? 如何在liferay门户中显示错误消息? 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.com网站上看到,对于显示错误消息,我可以使用liferay-ui:标记库中的错误标记,但是它不起作用,如何使用它?

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. 然后在您的Java代码中,您通常需要RenderRequest或ActionRequest,但也可以使用任何类型的HTTPServletRequest或PortletRequest。 Then you pass your request object to the static SessionErrors.add() method, like so: 然后将请求对象传递给静态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! 有任何疑问,请发表评论!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM