[英]JSF strange message from <h:message for=“someID”>
I'm using inputText to get input from a user 我正在使用inputText来获取用户的输入
<h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true" style="font-size: 15px"></h:inputText>
and then I've added a message tag 然后我添加了一个消息标记
<h:message for="firstName"></h:message>
but when the inputtext is blank and I press submit I get this error message: 但是当inputtext为空并且我按下提交时,我收到以下错误消息:
> j_id_jsp_1382885624_1:ID: Validation Error: Value is required.
how can I display the error message only as this? 如何才能显示错误消息?
> Validation Error: Value is required.
here is the code: 这是代码:
<f:view>
<h:form>
<h:panelGrid border="1" columns="3" style="width: 643px; ">
<h:outputText value="First Name" style="font-size: 25px; font-weight: bold"></h:outputText>
<h:outputText value="Last Name" style="font-size: 25px; font-weight: bold"></h:outputText>
<h:outputText value="ID" style="font-size: 25px; font-weight: bold"></h:outputText>
<h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true" requiredMessage="Enter a Valid First Name" style="font-size: 15px"></h:inputText>
<h:inputText id="LastName" value="#{beanManager.currentUser.lastName }" required="true" requiredMessage="Enter a Valid Last Name" style="font-size: 15px"></h:inputText>
<h:inputText id="ID" value="#{beanManager.currentUser.ID}" required="true" requiredMessage="Enter a Valid ID" style="font-size: 15px">
</h:inputText>
<h:form><h:commandButton action="#{beanManager.save }" value="Save Changes" style="height: 30px; width: 100px"></h:commandButton>
</h:form>
</h:panelGrid>
<h:commandLink action="backtopersonalview" value="Back To Users" style="height: 30px; width: 100px">
</h:commandLink>
</h:form>
</f:view>
Yes, it's possible. 是的,这是可能的。
To the current message, I can say that it consists out of form id
, item id
and default message
. 对于当前消息,我可以说它包含
form id
, item id
和default message
。
<form_id>:<item_id>: <default_message:javax.faces.component.UIInput.REQUIRED>
If you want to change the default message, you could do this with a message bundle, which you have to define in your faces-config.xml
. 如果要更改默认消息,可以使用消息包执行此操作,必须在
faces-config.xml
定义消息包。
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.stackoverflow.messages.language</base-name>
</resource-bundle>
</application>
And change the value for javax.faces.component.UIInput.REQUIRED
. 并更改
javax.faces.component.UIInput.REQUIRED
的值。
For example your message bundle language.properties
could contain: 例如,您的消息包
language.properties
可以包含:
javax.faces.component.UIInput.REQUIRED=Your new required message!
Mostly all JSF
implementations comes with the following default message, which I've copied from Mojarra
: 大多数
JSF
实现都带有以下默认消息,我从Mojarra
复制了Mojarra
:
javax.faces.component.UIInput.REQUIRED={0}: Validation Error: Value is required.
It's also possible to define a required message to an single item with the requiredMessage
attribute. 还可以使用
requiredMessage
属性为单个项定义所需的消息。 Then your <h:inputText />
should look like this: 然后你的
<h:inputText />
应如下所示:
<h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true" requiredMessage="Your new required message!" style="font-size: 15px">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.