如何向用户显示警告消息(并强调情况的严重性)

时间:2022-08-24 23:06:36

I've been trying to show a warning message to the customer in a way that he'll know that it is a warning, or something that he did wrong. But all I know how to do is a info message. How can I make it looks more severe?

我一直试图向客户展示一条警告信息,他知道这是一个警告,或者他做错了什么。但我知道该怎么做才是一条信息消息。我怎么能让它看起来更严重?

if (this.instance.getName().trim().equals("")){
    addFacesMessage("You must type a name!");
    return null;
}

This looks too friendly.

这看起来太友好了。

5 个解决方案

#1


2  

As Shervin told you should use StatusMessages instead of FacesMessages. StatusMessages has a lot of nice methods, you can also look at them.

正如Shervin所说,你应该使用StatusMessages而不是FacesMessages。 StatusMessages有很多很好的方法,你也可以查看它们。

import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.international.StatusMessage.Severity;
....
StatusMessages.instance().add(Severity.ERROR, "Message");

after that you can use errorStyle, fatalStyle, warnStyle of the to customize look and feel of the messages.

之后你可以使用errorStyle,fatalStyle,warnStyle来自定义消息的外观。

<h:messages errorStyle="yourStyle" />

#2


1  

Use Status Messages like this

使用这样的状态消息

StatusMessages.instance().add(Severity.ERROR, "Incorrect answers below.");

don't use FacesMessages .

不要使用FacesMessages。

Thanks

#3


0  

Inject:

@In
FacesMessages facesMessages;
facesMessages.add(Severity.WARN, "Your message");

Severity is a enum containing several warning levels.

严重性是包含多个警告级别的枚举。

#4


0  

You could use a logger?

你可以使用记录器吗?

logger = Logger.getLogger(getClass().getName());
logger.severe(message);

#5


0  

Make sure your imports are correct

确保您的导入正确无误

import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;

Then inject facesMessages component.

然后注入facesMessages组件。

@In(create = true)
FacesMessages facesMessages;

Then you can set the error message and severity as below

然后,您可以设置错误消息和严重性,如下所示

facesMessages.add(Severity.ERROR, "You must type a name!");

Now display the message as below

现在显示如下消息

<h:messages errorStyle="color:red"/>

For Ajax requests use rich:messages component.

对于Ajax请求,请使用rich:messages组件。

<rich:messages errorClass="yourErrClass"/>

#1


2  

As Shervin told you should use StatusMessages instead of FacesMessages. StatusMessages has a lot of nice methods, you can also look at them.

正如Shervin所说,你应该使用StatusMessages而不是FacesMessages。 StatusMessages有很多很好的方法,你也可以查看它们。

import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.international.StatusMessage.Severity;
....
StatusMessages.instance().add(Severity.ERROR, "Message");

after that you can use errorStyle, fatalStyle, warnStyle of the to customize look and feel of the messages.

之后你可以使用errorStyle,fatalStyle,warnStyle来自定义消息的外观。

<h:messages errorStyle="yourStyle" />

#2


1  

Use Status Messages like this

使用这样的状态消息

StatusMessages.instance().add(Severity.ERROR, "Incorrect answers below.");

don't use FacesMessages .

不要使用FacesMessages。

Thanks

#3


0  

Inject:

@In
FacesMessages facesMessages;
facesMessages.add(Severity.WARN, "Your message");

Severity is a enum containing several warning levels.

严重性是包含多个警告级别的枚举。

#4


0  

You could use a logger?

你可以使用记录器吗?

logger = Logger.getLogger(getClass().getName());
logger.severe(message);

#5


0  

Make sure your imports are correct

确保您的导入正确无误

import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;

Then inject facesMessages component.

然后注入facesMessages组件。

@In(create = true)
FacesMessages facesMessages;

Then you can set the error message and severity as below

然后,您可以设置错误消息和严重性,如下所示

facesMessages.add(Severity.ERROR, "You must type a name!");

Now display the message as below

现在显示如下消息

<h:messages errorStyle="color:red"/>

For Ajax requests use rich:messages component.

对于Ajax请求,请使用rich:messages组件。

<rich:messages errorClass="yourErrClass"/>