开发者

JSF form validation easy way to use custom text

I am using this to valida开发者_StackOverflow中文版te my form <h:message for="username" showDetail="false" showSummary="true"/> with required="true" but I get really ugly text because these cryptic ids are shown.

Can I somehow check if any error was throw at all and then just print some basic message hardcoded into the xthml?


Those "cryptic" IDs are controllable by the label attribute.

<h:inputText value="#{bean.user.name}" required="true" label="Username" />

You can also use the requiredMessage attribute to provide a full custom message.

<h:inputText value="#{bean.user.name}" required="true" requiredMessage="Please enter this field" />

There exist also the validatorMessage and converterMessage attributes for the case you'd like to define a common validation or conversion failure message in the view side.

See also:

  • JSF validation. can this be simplified?
  • JSF 2.0 tutorial - Finetuning validation
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜