我需要在接縫中驗證兩個用戶輸入字段。對於ui:repeat標記中的每一行,Field1必須大於Field2。到目前爲止,我有兩個字段包裝在s:decorate標籤中,該標籤將所有輸入包裝在s:validateAll標籤中。這使我可以將錯誤消息浮動到字段右側,如果任何一個驗證失敗的話。如何使接縫中的字段失效?
例如(我不能插入圖像,所以我必須使用ASCII圖片,原諒低質請,斜體字表示紅色文本):
標籤: |黃色| 0 |%紅色:| 0%| | 黃色和紅色必須介於0和100之間,黃色必須大於紅色。
標籤: |黃色| 0 |%紅色:| 0%| | 黃色和紅色必須介於0和100之間,黃色必須大於紅色。
這兩個控件和裝飾xhtml如下。注意:「0到100之間的值」驗證已通過hibernate註釋處理。我只需要需要知道如何驗證這兩個字段以確保黃色大於紅色,並且仍然顯示錯誤消息。
我希望的解決方案是設置相應的s:decorate標籤的#{invalid}屬性,這樣錯誤信息就會顯示出來,但我會採取任何想法。
的輸入:
<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>
和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>
偉大的想法,我會嘗試,謝謝! – 2009-06-30 19:17:47