I'm approaching JSF binding argument in PrimeFaces.
This is my form:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h1 class="title ui-widget-header ui-corner-all">
<p:spacer width="100" height="10" />
PrimeFaces Test Binding
</h1>
<title><ui:insert name="title">PrimeFaces Test</ui:insert></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:form id="form1">
<h:panelGroup binding="#{bindingTestClass.panelGroup}" />
</h:form>
</h:body>
</html>
And that's the body:
@ManagedBean(name="bindingTestClass")
@ViewScoped
public class BindingTestClass implements Serializable{
transient HtmlOutputLabel testValue = null;
transient HtmlSelectOneMenu menu = null;
transient HtmlPanelGroup panelGroup = null;
@PostConstruct
private void makeUp(){
menu = new HtmlSelectOneMenu();
panelGroup = new HtmlPanelGroup();
testValue = new HtmlOutputLabel();
panelGroup.setId("B");
panelGroup.setLayout("block");
panelGroup.setStyleClass("grid-form");
//LINE 0
testValue.setId("A");
testValue.setValue("BasicLabel");
panelGroup.getChildren().add(testValue);
HtmlOutputText linebreak = new HtmlOutputText();
linebreak.setValue("<br/>");
linebreak.setEscape(false);
panelGroup.getChildren().add(linebreak);
menu.setId("F");
// populate the drop down list
UISelectItems items = new UISelectItems();
List comboList = new ArrayList();
comboList.add(new SelectItem("---"));
for(int a = 0; a <10; a++){
comboList.add(new SelectItem( a+1 + " test"));
}
items.setId("ss");
items.setValue(comboList);
menu.getChildren().add(items);
//Add list to combobox
/*this first attempt doesn't work either, only change backend values
menu.addValueChangeListener(new ValueListenerTest());
menu.setOnchange("submit()");
*/
AjaxBehavior ajaxBehavior = (AjaxBehavior) FacesContext.getCurrentInstance().getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
ajaxBehavior.addAjaxBehaviorListener(new CustomAjaxListener());
//ajaxBehavior.setTransient(true);
ajaxBehavior.setUpdate("form1");
menu.addClientBehavior("change",ajaxBehavior);
panelGroup.getChildren().add(menu);
}
//Getters,Setters
public HtmlPanelGroup getPanelGroup() {
return panelGroup;
}
public HtmlOutputLabel getTestValue() {
return testValue;
}
public void setTestValue(HtmlOutputLabel testValue) {
this.testValue = testValue;
}
public void setPanelGroup(HtmlPanelGroup panelGroup) {
this.panelGroup = panelGroup;
}
public HtmlSelectOneMenu getMenu() {
return menu;
}
public void setMenu(HtmlSelectOneMenu menu) {
this.menu = menu;
}
}
The fact is that if and only if i put the separate binding code in my view this way:
<h:outputLabel binding="#{bindingTestClass.testValue}" />
and obviously take out the corresponding child from panelgroup, when I change the selectOneMenu value, the listener change the value in the backing bean, and then it updates the form which updates indeed the value of the "testValue" label.
I've tried different attempts but still didn't catch why it won't work in this way, putting everything in a single panelgroup.
Can anybody point me in the right direction?
Many many thanks in advance!
EDIT: the code above works with @RequestScoped scope and obviously putting all attributes variabile in "private" modifier mode. But there's no chance with the @ViewScoped?