2017-06-08 4 views
0

エラー「検証エラー:値が無効です」を受け取ったときに自分の誤りを見つけるのに問題があります。フォームを送信した後、デバッグ時に、選択したコンポーネントが正しい場合でも、このエラーが発生します。コンバーターもうまく動作しているようですが、私はここで本当に厳しい時間を過ごしています。ここで私はこれまで試してみましたです:@ManagedBeanするJSF検証エラー:値が無効です

  • 変更@RequestScopedをして@ViewScoped - これは@RequestScopedで起こることはありませんでした、なぜならNullpointerExceptionが発生するクラッシュ毎回beofore SelectOneMenueを作ったので、私はわかりません何が起こっているのですか...

  • 私はこのSelectedOneMenueのコンバーターをダブルチェックしました。動作しているようですが、私はそこで多くのデバッグを行いました。オブジェクトは文字列に変換されました。これは後でStringからObjectに変換されます。

  • equals()メソッド:equalsメソッドはわかりました。つまり、.idが同じかどうかを文字通りチェックします。コンバーターでこれをチェックすると、常に正しいです。もしかしたらここで間違っているかもしれないことを理解できなくても、私はむしろここでエラーを検索したいと思うかもしれません。ここで

は、私はあなたのために興味深いものになると思います私のコードの一部である、私はすでにかなりいくつかの研究を行っている、私はこの仕事を得ることができなかったけれども、私はかなり良いものを見つけましたが、これは意味してはいけませんJavaEEとJSF(+ Primefaces)を使用してプログラミングを始めたばかりなので、

成分()メソッド

@Override 
public boolean equals(Object obj) { 
    if(obj == null){ 
     //System.out.println("Component is NULL in equals() method"); 
    } 
    if(this.id == ((Component) obj).id) { 
     return true; 
    }else { 
     return false; 
    } 
} 

コンポーネントコンバータクラスに等しい

@ManagedBean(name = "componentConverterBean") 
@FacesConverter (value = "componentConverter") 
public class ComponentConverter implements Converter{ 

@PersistenceContext(unitName="PU") 
private EntityManager em; 

@Override 
public String getAsString(FacesContext context, UIComponent component, Object modelValue) { 
    if (modelValue == null) { 
     return ""; 
    } 
    return modelValue.toString(); 
} 

@Override 
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) { 
    if (submittedValue == null || submittedValue.isEmpty()) { 
     System.out.println("ComponentConverter: submittedValue is null"); 
     return null; 
    } 

    try { 
     System.out.println("ComponentConverter: Value to be found: " + submittedValue); 
     return em.find(Component.class, Integer.parseInt(submittedValue)); 
    } catch (NumberFormatException e) { 
     throw new ConverterException(new FacesMessage(submittedValue + " is not a valid Component ID", e.getMessage())); 
    } 
} 

} SelectOneMenues

<p:outputLabel for="facility" value="Facility: " /> 
<p:selectOneMenu id="facility" value="#{visualization.facility}" converter="#{facilityConverterBean}" style="width:150px"> 
    <p:ajax process="@this" partialSubmit="true" listener="#{visualization.onFacilityChange()}" update="component" /> 
    <f:selectItem itemLabel="Select Facility" noSelectionOption="true" /> 
    <f:selectItems value="#{visualization.facilities}" var="facility" itemLabel="#{facility.name}" itemValue="#{facility}" /> 
</p:selectOneMenu> 
<p:outputLabel for="component" value="Components: " /> 
<p:selectOneMenu id="component" value="#{visualization.component}" converter="#{componentConverterBean}" style="width:150px"> 
    <f:selectItem itemLabel="Select Component" noSelectionOption="true" /> 
    <f:selectItems value="#{visualization.components}" var="comp" itemLabel="#{comp.name}" itemValue="#{comp}" /> 
</p:selectOneMenu> 

「Coを含む.xhtmlファイルの

パート要素:Überprüfungsfehler:Wert istungültig。 " "コンポーネント:検証エラー:値が無効です"

私はここに助けてくれて非常に感謝しています。前もって感謝します。

+0

ので、施設関連selectOneMenu作品?そして、どのようにしていつ、そしていつあなたは、選択された「コンポーネント」がサーバに送信されるので、「コンポーネント」関連のものを提出しますか? – Kukeltje

+0

可能な複製https://stackoverflow.com/questions/9069379/validation-error-value-is-有効ではありません – Tonkichi

+0

施設は機能しているようですが、そのほとんどは同じConverter/Equalsメソッドですが、施設ではエラーが発生しません。すべてを選択した後、ユーザーはSubmitを押して、選択した施設、コンポーネント、日付/時刻に応じてデータベースから他のデータを収集します。それはあなたの質問に答えますか? @ MaxR。 –

答えて

0

value = "#{visualization.component}"のエンティティの代わりにコンテナオブジェクトを使用します。例:

class ComponentDto { 
    private Component componentEntity; 

    private Component getComponentEntity() { 
     return this.componentEntity; 
    } 

    private void setComponentEntity(Component componentEntity) { 
     this.componentEntity = componentEntity; 
    } 
} 

参照:https://github.com/primefaces/primefaces/issues/2756

関連する問題