Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to invalidate a field in seam?
    primarykey
    data
    text
    <p>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.</p> <p>For example (i can't insert an image, so i have to use ascii picture, forgive the low-quality please, italics indicate red text):</p> <p><em>Label:</em> | Yellow | 0|% Red: | 0%| | <em>Yellow and Red must be between 0 and 100, and Yellow must be greater than Red.</em><br/><br/> <em>Label:</em> | Yellow | 0|% Red: | 0%| | <em>Yellow and Red must be between 0 and 100, and Yellow must be greater than Red.</em><br/><br/></p> <p>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 <strong>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.</strong></p> <p>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.</p> <p>The inputs:</p> <pre><code>&lt;table&gt; &lt;ui:repeat value="#{action.List}" var="var"&gt; &lt;s:decorate template="/layout/decorateMultipleInputs.xhtml" &gt; &lt;ui:define name="label"&gt; Label: &lt;/ui:define&gt; &lt;ui:define name="input"&gt; &lt;h:panelGrid columns="8" frame="border"&gt; &lt;h:outputText value="Yellow:" /&gt; &lt;h:inputText value="#{var.yellow}" style="width:25px; text-align:right" maxlength="3"/&gt; % &lt;h:outputText value="Red:" /&gt; &lt;h:inputText value="#{var.red}" style="width:25px; text-align:right" maxlength="3"/&gt; % &lt;/h:panelGrid&gt; &lt;/ui:define&gt; &lt;ui:define name="message"&gt;Yellow and Red must be between 0 and 100, and Yellow must be greater than Red. &lt;/ui:define&gt; &lt;/s:decorate&gt; &lt;/ui:repeat&gt; &lt;/table&gt; </code></pre> <p>and the decorateMultipleInputs.xhtml:</p> <pre><code>&lt;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"&gt; &lt;tr&gt; &lt;td&gt; &lt;s:label styleClass="#{invalid?'error':''}"&gt; &lt;ui:insert name="label"/&gt; &lt;s:span styleClass="required" rendered="#{required}"&gt;*&lt;/s:span&gt; &lt;/s:label&gt; &lt;/td&gt; &lt;td&gt; &lt;s:validateAll&gt; &lt;ui:insert name="input"/&gt; &lt;/s:validateAll&gt; &lt;/td&gt; &lt;td&gt; &lt;s:div styleClass="error" rendered="#{invalid}"&gt; &lt;h:graphicImage value="/images/error.gif" /&gt; &lt;/s:div&gt; &lt;/td&gt; &lt;td&gt; &lt;s:div styleClass="error" rendered="#{invalid}"&gt; &lt;ui:insert name="message"/&gt; &lt;/s:div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/ui:composition&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload