JSF offers the possibility to use so called value holders in the interface of a composite. You can then configure the validation in the usage of the component.
More precisely, you can use cc:valueHolder
in a cc:interface
of a composite component. Define the name
attribute which will be used to reference the value holder later. With the targets
attribute you define which of the input fields should use the validation.
<cc:interface componentType="IvyComponent">
<cc:valueHolder name="fullname" targets="form:firstname form:lastname"></cc:valueHolder>
<cc:valueHolder name="comment" targets="form:comment"></cc:valueHolder>
</cc:interface>
<cc:implementation>
<h:form id="form">
<p:messages></p:messages>
<p:panelGrid columns="2">
<p:outputLabel for="firstname" value="Firstname"></p:outputLabel>
<p:inputText id="firstname" value="#{data.firstname}"></p:inputText>
<p:outputLabel for="lastname" value="Lastname"></p:outputLabel>
<p:inputText id="lastname" value="#{data.lastname}"></p:inputText>
<p:outputLabel for="comment" value="Comment"></p:outputLabel>
<p:inputText id="comment" value="#{data.comment}"></p:inputText>
...
</p:panelGrid>
</h:form>
</cc:implementation>
In the Html User Dialog that embeds the component you can now use f:validateRequired
and its for
attribute to reference to the value holder in the interface.
<ic:forms.ConfigureValidationComponent>
<f:validateRequired for="fullname"></f:validateRequired>
<f:validateLength for="comment" minimum="0" maximum="10"></f:validateLength>
</ic:forms.ConfigureValidationComponent>
Note: This question and answer was originally posted by Heinrich Spreiter on his Xpert.ivy Hacker blog. Henry, many thanks to you for your enthusiastic work.
answered
09.10.2013 at 09:25
SupportIvyTeam ♦♦
1.4k●102●118●122
accept rate:
77%