I need to validate two user input fields against each other in seam. Field1 must be greater than Field2 for each row in a ui:repeat tag. As of now, i have the two fields wrapped in an s:decorate tag that wraps all input in an s:validateAll tag. This allows me to float an error message out to the right of the fields if validation fails for any of them.
For example (i can't insert an image, so i have to use ascii picture, forgive the low-quality please, italics indicate red text):
Label: | Yellow | 0|% Red: | 0%| | Yellow and Red must be between 0 and 100, and Yellow must be greater than Red.
Label: | Yellow | 0|% Red: | 0%| | Yellow and Red must be between 0 and 100, and Yellow must be greater than Red.
The two controls and the decorate xhtml are below. NOTE: The "value between 0 and 100" validation is already taken care of via hibernate annotation. I only need to know how to validate these 2 fields against each other to make sure yellow is greater than red, and still have the error message show up.
My desired solution would be to set the #{invalid} property for the corresponding s:decorate tag, so the error message will show up, but i'll take any ideas.
The inputs:
<table>
<ui:repeat value="#{action.List}" var="var">
<s:decorate template="/layout/decorateMultipleInputs.xhtml" >
<ui:define name="label">
Label:
</ui:define>
<ui:define name="input">
<h:panelGrid columns="8" frame="border">
<h:outputText value="Yellow:" />
<h:inputText value="#{var.yellow}" style="width:25px; text-align:right" maxlength="3"/>
%
<h:outputText value="Red:" />
<h:inputText value="#{var.red}" style="width:25px; text-align:right" maxlength="3"/>
%
</h:panelGrid>
</ui:define>
<ui:define name="message">Yellow and Red must be between 0 and 100, and Yellow must be greater than Red.
</ui:define>
</s:decorate>
</ui:repeat>
</table>
and the decorateMultipleInputs.xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib">
<tr>
<td>
<s:label styleClass="#{invalid?'error':''}">
<ui:insert name="label"/>
<s:span styleClass="required" rendered="#{required}">*</s:span>
</s:label>
</td>
<td>
<s:validateAll>
<ui:insert name="input"/>
</s:validateAll>
</td>
<td>
<s:div styleClass="error" rendered="#{invalid}">
<h:graphicImage value="/images/error.gif" />
</s:div>
</td>
<td>
<s:div styleClass="error" rendered="#{invalid}">
<ui:insert name="message"/>
</s:div>
</td>
</tr>
</ui:composition>