I have the next question!
I want to create inputtext dynamically from my backing bean, they would be inside of the a tabs also dynamic created which will be constructed in execution time.
I manage to add the components dynamically using the input
classes corresponding.
But I have not manage to add the value tag to the component, a valueExpresion
language which binds the value to the managedBean
itself.
I have found some code which I can summerize like this.
@ManagedBean
@ViewScoped
public MyManagedBean(){
private TabView tabsi;
HtmlOutputLabel hol = new HtmlOutputLabel();
InputText txt2 = new InputText();
private String value;
/* getter and setters */
public void MyManagedBean{
tabsi = new TabView();
Tab tab1 = new Tab();
tab1.setTitle("Tab1");
Tab tab2 = new Tab();
tab2.setTitle("Tab2");
tabsi.getChildren().add(tab1);
tabsi.getChildren().add(tab2);
hol.setValue("label");
hol.setStyleClass("label");
txt2.setValueExpression("value",
TestController.getExpression("#{myManagedBean.value}"));
txt2.setValue(value);
tab1.getChildren().add(hol);
tab1.getChildren().add(txt2);
}
public static ValueExpression getExpression(String expression) {
FacesContext fc = FacesContext.getCurrentInstance();
ELContext ctx = fc.getELContext();
ExpressionFactory factory = fc.getApplication().getExpressionFactory();
return factory.createValueExpression(ctx, expression, Object.class);
}
public void test1() {
System.out.println(value);
}
}
I successfully manage to build the components but I can not bind it to set the ValueExpression
. When I call the test1 function from a button it print null
How can I bind the value to the ManagedBean
???