I need to perform a web service (method) call just before load of a jsf page. The call will return a list of input fields that have to be displayed on my jsf page. The user can fill in the form and on click of next I need the values entered on the form to be sent back to another web service (method).
My approach was to have a request scoped bean for the jsf page(which consists of a blank form and a binding to the bean), and perform the web service call in the setter method of my form method and dynamically create UIInput fields
//call web service
//Loop
UIInput input = new HtmlInputText();
//set unique Id
form.getChildren().add(input);
//End Loop
It does create the Input fields, but if I perform browser back or refresh it keeps adding Input fields. So clearly my approach is wrong.
Also I found out that when I try to get the values for these dynamically created Input fields on Submit action like
List<UIComponent> dynamicFields = form.getChildren();
for(int i=0;i<form.getChildCount();i++){
if("javax.faces.Input".equals(componentFamily)){
UIInput input = (UIInput)dynamicFields.get(i);
System.out.println("Input Field: ID = "+input.getId() + " , Value="+ input.getValue());
}
}
The Id of the fields is printed properly, However value is always null. Clearly doing it all wrong.
Kindly let me know when and at what point do I create fields and how do I capture those values
P.S Am using JSF 2.0, Jdeveloper, Glassfish and/or Weblogic Server