2015-03-02 102 views
3

的XPages我在Java中的驗證豆設置在那裏我可以做到以下幾點:驗證中使用Java

public void validateStatus(FacesContext facesContext, UIComponent component, Object value) { 
    if (value.toString().equals("Fail")) { 
     FacesMessage message = new FacesMessage("Invalid value!"); 
     throw new ValidatorException(message); 
    } 
} 

而且XPage上:

<xp:comboBox 
    id="Status" 
    validator="#{validatorsBean.validateStatus}"> 
</xp:comboBox> 
<xp:message 
    id="message2" 
    for="Status"> 
</xp:message> 

這是偉大的工作。但是,我也想要執行一些驗證邏輯,並在與特定字段無關的<xp:messages>控件中顯示錯誤消息。有沒有一種方法可以在我的Validator bean中實現這一點?感謝您的任何提示。

回答

3

替換行

throw new ValidatorException(message); 

((UIInput)component).setValid(false); 
facesContext.addMessage(component.getClientId(facesContext), message); 
+0

什麼參數做我傳遞的組成部分?我想要顯示與特定字段無關的錯誤消息。 – 2015-03-02 21:12:09

+2

使用隱藏的輸入字段並向其添加驗證程序。 – 2015-03-02 21:22:40