Question

I have a managedbean AddDeviceBean where in instantiating all domain objects used in screen in the constructor

public AddDeviceBean() {
    device = new DeviceVO();
    deviceacct = new DeviceAccountsVO();
    deviceconfig = new DeviceConfigVO();
    devicecurr =new DeviceCurrencyVO();
    devicelink = new DeviceLinkVO();
    devicetran = new DeviceTranVO();
    devicecd = new DeviceCDVO();
    deviceBlank = new DeviceBlankVO();
    comments = new ArrayList<DeviceCommentsVO>();

}

I have a DB2 sequence whose next value has to be set for a property on pageload

I am using @PostConstruct annotation to generate the next value and setting the value.

Problem is I have commandButton on the screen which invokes some method in same bean and @PostConstruct is called twice after submitting and the DB2 next value is called

I need to get next value only once during page load and not during submit

Was it helpful?

Solution

That will indeed happen when your managed bean is request scoped. A request scoped bean is constructed on every single HTTP request. The initial request counts as one request. The form submit (the postback) counts as another request.

If you want to make the bean to live as long as you're interacting with the same view, then you should be making it a view scoped one instead.

@ManagedBean
@ViewScoped
public class AddDeviceBean {
    // ...
}

See also:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top