0

I have a screen in which am using

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>

    <h:form>
    <f:event listener="#{pageload.getPageLoad}" type="preRenderView" />
    <h:dataTable value="#{pageload.fieldConfig}" var="field" 
    columnClasses="lblFirstCol,lblSecondCol,lblThirdCol,lblFourthCol" id="table1" styleClass="tblSecond" >
        <h:column >
        <h:outputText value="#{field.label_name}" />
        </h:column>
        <h:column>              
            <h:inputText value="#{searchdevice.device.terminal_name}" />
        </h:column>

    </h:dataTable> 

    <h:commandButton value="Submit" action="#{searchdevice.searchButtonAction}"/>
    </h:form>
</h:body>

And my backing bean

@ManagedBean(name="pageload")
@RequestScoped
public class PageLoadBean {

private List<FieldConfigVO> fieldconfig;
      //getters and setters

      // method  to populate the ArrayList
      public void getPageLoad(){
                   //getting populated from Database
         fieldconfig = common.getFieldConfig("001");        
      }  
  }

The other input bean

@ManagedBean(name="searchdevice")
@RequestScoped
 public class SearchDeviceBean {

private DeviceVO device;




public SearchDeviceBean() {
    device = new DeviceVO();
}

public DeviceVO getDevice() {
    return device;
}

public void setDevice(DeviceVO device) {
    this.device = device;
}

public String searchButtonAction(){
    System.out.println(device.getTerminal_name()+"****TERMINAL NAME******");
            FacesContext context = FacesContext.getCurrentInstance();
    if (context.getMessageList().size() > 0) {
        return(null);
    }else {

        return("success");
    }

}
     }

My Device Object has the terminal_name property.I have a command button which invokes method in SearchDeviceBean and on submitting the form whatever value I enter doesn't get populated

Any help appreciated

user2462959
  • 75
  • 11
  • are you using h:commadButton if yes then are you calling it from a h:form or not. if this does not solve your problem please post complete page info – ankit Sep 16 '13 at 07:21
  • Please provide your entire form code and your `SearchDeviceBean` class code. – Aritz Sep 16 '13 at 07:37
  • Please provide a [SSCCE](http://www.sscce.org/). Otherwise it's unlikely you'll get help, as there are too many places where the mistake could be. – sleske Sep 16 '13 at 07:53
  • yes I using commandButton .My full code is – user2462959 Sep 16 '13 at 08:08
  • It is working if I make my backing bean SessionScoped.Not working in RequestScoped – user2462959 Sep 16 '13 at 09:56

1 Answers1

0

You're performing data initialization logic in preRenderView event. This is the wrong place for code which needs to prepare the model for the postback. When JSF needs to update the model values during form submit, it is encountering a completely empty fieldConfig and therefore JSF can't set the submitted/converted/validated values in there. The fieldConfig is in your case only prepared during a later phase, the render response phase, which is thus too late.

You need to initialize it in @PostConstruct instead. It's invoked immediately after bean's construction and dependency in jection. Get rid of the whole <f:event> altogether and put a @PostConstruct annotation on the getPageLoad() method. I'd by the way also rename that method to init() or loadFieldConfig() as it isn't a getter method at all and therefore a very confusing name to other people reading/maintaining your code.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555