1
我在其中之一中有兩個h:形式和單個h:消息。我如何才能顯示來自該表單的驗證錯誤?我想忽略來自其他表單的所有消息。兩種形式和h:消息,決定要顯示什麼消息
我在其中之一中有兩個h:形式和單個h:消息。我如何才能顯示來自該表單的驗證錯誤?我想忽略來自其他表單的所有消息。兩種形式和h:消息,決定要顯示什麼消息
由於您已經使用JSF2,因此請考慮在必要位置引入<f:ajax execute="@form" render="@form">
來替代異步請求的同步請求。
E.g.
<h:form>
<h:messages />
<h:inputText required="true" />
...
<h:commandButton value="submit">
<f:ajax execute="@form" render="@form">
</h:commandButton>
</h:form>
<h:form>
<h:messages />
<h:inputText required="true" />
...
<h:commandButton value="submit">
<f:ajax execute="@form" render="@form">
</h:commandButton>
</h:form>
這種方式在只提交當前<h:form>
的內容將被重新呈現。由於使用ajax,額外的好處是可以加快反饋速度並改善用戶體驗。
如果這不是出於某種原因的選項,最好的辦法是使用rendered
屬性有條件地顯示根據調用按鈕<h:messages>
組件(其名稱=值對(該名稱是客戶端ID)將出席然後在請求參數映射中)。例如,
<h:form>
<h:messages rendered="#{not empty param[button1.clientId]}" />
<h:inputText required="true" />
...
<h:commandButton binding="#{button1}" value="submit" />
</h:form>
<h:form>
<h:messages rendered="#{not empty param[button2.clientId]}" />
<h:inputText required="true" />
...
<h:commandButton binding="#{button2}" value="submit" />
</h:form>
謝謝,修改了第二溶液'的 ' –
mm1
2012-01-08 19:53:32