Oam Psy
Oam Psy

Reputation: 8663

Validation on selectOneMenu to display message in a SPAN

I have a drop down box in a JSF 1.2 web application:

<h:selectOneMenu value=“#{value}" required="true" requiredMessage="Please select a value.">
  <f:selectItem itemValue="#{null}" itemLabel=“Please Select" />
  <f:selectItem itemValue=“1" itemLabel=“£1" />
  <f:selectItem itemValue=“2" itemLabel=“£2" />
  <f:selectItem itemValue=“3" itemLabel=“£3" />
  <f:selectItem itemValue=“4" itemLabel=“£4" />
  <f:selectItem itemValue=“5" itemLabel=“£5" />
</h:selectOneMenu>
<h:messages/>

Which when a value is not selected, the message Please select a value is displayed.

However, is message is displayed in a <ul> <li>. How can i display this message in a <span>

Upvotes: 1

Views: 1240

Answers (1)

BalusC
BalusC

Reputation: 1109655

That's indeed the default output of a <h:messages>.

Just use <h:message> instead of <h:messages> if you intend to display a single message instead of a list of messages (click the links, you'll see that it clearly describes how they are encoded to HTML).

<h:selectOneMenu id="foo" ... />
<h:message for="foo" />

Note that the for attribute must refer the (relative) client ID of the target component you'd like to display the message for.

Upvotes: 2

Related Questions