看法
<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>
托管豆
@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 为空。
有机会访问组合框的选定值吗?
谢谢吉姆