Mandatory field in widget template

How can I make a field mandatory in a widget template? On the creation layout I have a widget template mapped to a schema field. In custom properties configuration I have added the property “required” with value “true”. At runtime, it shows the required star “*” in the creation form, but it doesn't validate that the value is not empty. How can I validate it?

1 votes

1 answers

1009 views

ANSWER



Hi,

Just add required=“#{widget.required}” to the JSF tag bound to the #{field} mapping.

Here's an example:

<h:selectOneMenu value="#{field}" id="#{widget.id}"
  required="#{widget.required}">
  <f:selectItem itemValue="deleted" itemLabel="#{messages['label.no']}" />
  <f:selectItem itemValue=" " itemLabel="#{messages['label.yes']}" />
</h:selectOneMenu>
<h:message styleClass="errorMessage" for="#{widget.id}"
  id="#{widget.id}_message" />
1 votes



Thanks, it worked. The only thing is that it doesn't show the "Value is required" message. How can I do that?
01/31/2012

Using a standard h:message tag. I modified my post to include an example.
01/31/2012

Thanks it worked.
02/06/2012