0

h:inputText、h:selectonemenu、および commandbuton があります。Inputtext は必須フィールドで、immediate="true" と定義しています。次に、ボタンをクリックすると、selectonemenu の現在の値をマネージド Bean に渡します。しかし、そのパッシグはヌルです。マネージド Bean で selectOneMenu の値を取得できるように、この検証をどのように管理できますか。

私のコードは..

<h:inputText id="inputSome" required="true" requiredMessage="Pls enter something"/>
        <h:message for="inputSome"></h:message>
        <h:selectOneMenu id="recepients" value="#{controller.selected}" immediate="true">
            <f:selectItem itemLabel="Select" itemValue=""/>
            <f:selectItems value="#{controller.tempNameList1}"></f:selectItems>


        </h:selectOneMenu>

        <p:commandButton value="Add" action="#{controller.submit}"
            immediate="true"/>
4

1 に答える 1

5

immediate=truecommandButtonを入力すると、検証後(および検証を含む)のフェーズをスキップしてInvoke Application、フェーズが直接実行されます。そのため、「モデル値の適用」フェーズもスキップされ、管理対象Beanのプロパティは初期化されないままになります。これにより、の値にnullが渡されますselectOneMenuselected解決策は、次のように、コントローラーのプロパティの値を手動で取得する必要があることです。

 Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

    for (String key : paramMap.keySet()) {
        if (key.contains("recepients")) {
            selected = Integer.parseInt(paramMap.get(key));
        }
    } 
于 2013-02-24T19:14:58.217 に答える