2017-10-09 8 views
1

複数の検証を形成primefacesは、私は時間内に複数のコンポーネントを検証するために問題を抱えている

ここ
<p:inputText id="actionNameInput" 
       title="TO DO" 
       value="#{repositoryBean.newActionName}" 
       label="Action name" 
       required="true" 
       requiredMessage="Action name is missing."> 
     <f:validator validatorId="inputTextValidator"/> 
     <f:attribute name="input1" value="Action name" /> 
    </p:inputText> 

    <p:inputText id="identifierInput" 
       title="TO DO" 
       value="#{repositoryBean.newActionRegex}" 
       label="Identifier" 
       required="true" 
       requiredMessage="Identifier is missing."> 
     <f:validator validatorId="inputTextValidator"/> 
     <f:attribute name="input1" value="Identifier" /> 
    </p:inputText> 

は、バリデータクラスがあります:

@FacesValidator(value = "inputTextValidator") 

public class AddActionValidatorInputText implements Validator{ 
    @Override 
    public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException { 

     if(((String)o).length() < 3){ 
      FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, 
        uiComponent.getAttributes().get("input1")+" should be longer than 3characters.", null); 
      FacesContext.getCurrentInstance().addMessage(null, message); 
      throw new ValidatorException(message); 
     } 
    } 
} 

それだけで...私はthisをtryiedている最初のinputTextを検証しますが、私はコンポーネント(常にnull)から値を取得するカント...、私はシームの顔についてsmthing読み取り、私はそれを適用した場合いくつかの大きなエラーがありました(それにはますます依存が必要です...)。私は自分のbeanクラスでそれを検証したくありません。

+0

'h:inputText'で動作しますか? – Kukeltje

答えて

0

Hereこの問題の解決方法を見つけることができます。

<p:inputText id="actionNameInput" 
      title="TO DO" 
      value="#{repositoryBean.newActionName}" 
      label="Action name" 
      required="true" 
      requiredMessage="Action name is missing." 
      valueChangeListener="#{repositoryBean.onNewActionNameChange}"> 
    <f:validator validatorId="inputTextValidator"/> 
    <f:attribute name="input1" value="Action name" /> 
</p:inputText> 

をしてバッキングBeanに::そしてNULLでない値を作るために、valueChangeListenerのは次のように属性を使用

public void onNewActionNameChange(ValueChangeEvent event) { 
    setNewActionName(event.getNewValue().toString()); 
} 

This articleをJSFのライフサイクルについてのあなたの中に何が起こっているか理解するのに役立つかもしれません。

関連する問題