I have a jsf containing two <p:selectOneMenu ...>
components.
Part of JSF:
<p:selectOneMenu id="speakerLanguage"
value="#{speakerAddFormView.currentSpeaker.nativLang1}">
<f:selectItem itemLabel="Select Language" itemValue="-1" />
<f:selectItems value="#{speakerAddFormView.languages.entrySet()}"
var="languages" itemLabel="#{languages.key}"
itemValue="#{languages.value}" />
<p:ajax listener="#{speakerAddFormView.updateStateSecondNativeLangSOM}"
update="speakerLanguage2" />
</p:selectOneMenu>
<p:selectOneMenu id="speakerLanguage2"
value="#{speakerAddFormView.currentSpeaker.nativLang2}"
disabled="#{speakerAddFormView.disableSecondNativeLangSOM}">
<f:selectItem itemLabel="Select second Language" itemValue="-1" />
<f:selectItems value="#{speakerAddFormView.languages.entrySet()}"
var="languages" itemLabel="#{languages.key}"
itemValue="#{languages.value}"/>
</p:selectOneMenu>
Within my bean I have a public static final Map<String, String> LANGUAGE_CODES = new TreeMap<String, String>();
containing native languages. This TreeMap
is referenced at initialization of the bean at:
@PostConstruct
public void init() {
this.languages = ConstantCodes.LANGUAGE_CODES;
}
When I reload the page, the both <p:selectOneMenus >
are seleected not to the default <f:selectItem itemLabel="Select Language" itemValue="-1" />
or <f:selectItem itemLabel="Select second Language" itemValue="-1" />
.
Edit: These two items are selected from the beginning.
Is there a way to force the default selected value ?
Set your nativLang1
and nativLang2
to -1
in your @PostConstruct
method.
@PostConstruct
public void init() {
System.out.println("initializing");
this.languages = ConstantCodes.LANGUAGE_CODES;
nativLang1 = "-1";
nativLang2 = "-1";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.