2

見る

<h:form id="main_form">
    <p:inputText id="title" required="true" label="Title" value="#{myBean.myLink.title}" immediate="true" />

    <p:selectOneMenu id="scope" required="true" label="Scope" value="#{myBean.myLink.scope}" immediate="true" >
        <f:selectItem itemLabel="Please choose" itemValue="" />
        <f:selectItems value="#{myBean.availableScopes}" id="selScope"/>
    </p:selectOneMenu>

    <p:inputText id="link" required="true" label="URL" value="#{myBean.myLink.link}" immediate="true">      
        <p:ajax event="blur" update="msgLink" listener="#{myBean.checkUrl}" />
    </p:inputText>

    ... msgLink and other (required) elements

    ... submit button
</h:form>

マネージド Bean

@Component("myBean")
@Scope("session")
public class MyBean implements Serializable {

    private Link myLink;
    private Map<String, String> availableScopes;

    public MyBean() {
        this.availableScopes = new HashMap<String, String>();
        this.availableScopes.put("Intranet", "Intranet");
        this.availableScopes.put("Internet", "Internet");   
    }

    // setter/getters etc.

    public void checkUrl() {
        System.out.println(myLink.getTitle());  // works
        System.out.println(myLink.getScope());  // DOES NOT work
        System.out.println(myLink.getLink());   // works
    }

}
  • フォームを送信するに、選択したスコープに応じて URL を確認したい。ただし、呼び出されたメソッドinputTextはオブジェクトの値にアクセスできます。で選択した値ではありませんselectOneMenu
  • 試してみましたgetExternalContext().getSessionMap().get("scope")が、その時点で SessionMap は null です。

コンボ ボックスの選択した値にアクセスする機会はありますか?

ありがとうジム

4

1 に答える 1

4

コンポーネント内の<p:ajax>(and )は、デフォルトで現在のコンポーネント ( ) のみを実行/処理し、他のコンポーネントは実行/処理しません。<f:ajax>UIInput UIInput@this

リスナーメソッドが呼び出されるときにこれらすべてのコンポーネントを実行/処理する場合は、 (または) 属性UIInputでそのように指定する必要があります。<p:ajax process><f:ajax execute>

<p:inputText id="title" ... />

<p:selectOneMenu id="scope" ... >
    ...
</p:selectOneMenu>

<p:inputText id="link" ...>      
    <p:ajax process="title scope link" ... />
</p:inputText>

具体immediate="true"的な問題とは関係ありませんが、これらすべての属性がこのコンテキストでどのように役立つのか疑問に思います。それらが必要だと確信していますか?

于 2012-09-06T10:36:56.840 に答える