I wanted to test if an ajaxified <p:selectOneListBox>
element works fine or not. On a JSF+PrimeFaces based portlet I've created the above code. Basically, on a item selection from a <p:selectOneListBox>
list, I want to update a label with the value of the previously selected item. Unfortunately, it doesn't seem to work as expected.
.xhtml side:
<form id="myform">
<p:selectOneListbox id="myselect" value="#{bean.optionSelected}">
<p:ajax listener="#{bean.onChange}" process="myselect" update="toupdate" onstart="onstart()" oncomplete="oncomplete()" onerror="onerror()" onsuccess="onsuccess()"/>
<f:selectItem itemLabel="Option 1" itemValue="1" />
<f:selectItem itemLabel="Option 2" itemValue="2" />
<f:selectItem itemLabel="Option 3" itemValue="3" />
</p:selectOneListbox>
<h:outputText id="toupdate" value=">#{bean.optionSelected}" />
</form>
Bean side:
@ManagedBean(name = "bean")
@ViewScoped
public class Bean implements Serializable {
private static final long serialVersionUID = 201709131528L;
private static Logger logger = Logger.getLogger(Bean.class);
private String optionSelected = "-1";
public Bean() {
logger.trace("bean created");
}
@PostConstruct
private void onPostConstruct() {
logger.trace("start");
}
public String getOptionSelected() {
return this.optionSelected;
}
public void setOptionSelected(String optionSelected) {
logger.trace("start");
this.optionSelected = optionSelected;
}
public void onChange() {
logger.trace("start");
}
}
Every time I select an option from the list I've got the following log from the console:
Bean:<init>():bean created
Bean:onPostConstruct():start
And from the console of my browser I've got the following log:
onstart():
onerror():
oncomplete():
As a newcomer to the JSF+PF world, I'd like to know:
1) why the onChange()
listener is not invoked.
2) why the property optionSelected
is not set.
3) why the bean bean
is created on each option selection.
4) why the ajax request fails.
Any clarification would be really apreciated. Thanks.