VIEW
<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>
Managed 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
}
}
- I want to check the URL depending of the selected scope before submitting the form. But the called method can access the
inputTextvalues of the object. Not the value chosen inselectOneMenu. - I have tried it with
getExternalContext().getSessionMap().get("scope")but the SessionMap is null at that time.
Any chance to access the selected value of the combo box?
Thanks
Jim
The
<p:ajax>(and<f:ajax>) inside anUIInputcomponent executes/processes by default the currentUIInputcomponent (@this) only, not others.If you want to execute/process all those
UIInputcomponents when the listener method is to be invoked, then you should specify that as such in<p:ajax process>(or<f:ajax execute>) attribute:Unrelated to the concrete problem, I wonder how all those
immediate="true"attributes are useful in this context. Are you certain you need them?