Tim Holloway wrote:
If I want to use the first (default) value I need to change it to sth. else and then change again to the first one .
I do not understand what that means. Could you please explain?
The problem is that when the page loads the "selected" param has a null value. When an onchange event occurs at the SelectOneMenu it re-renders the button tag, ergo setting the param value to current indexBean.model.selected_id - this works. However if the user does not change the value of selectOneMenu (leaving it at the default first one) and clicks the button, the "selected" param won't be set and remains at null. So what I meant above is that in order to pass the first default selectOneMenu value to the "selected" param, the user must change the SelectOneMenu value to sth. else and than again to the first value - this would trigger the onchange event, the button is re-rendered and the param is set. It is obviously a bug and a undesired behavior. If I would find a way to initialize the parameter in Java with the first value of selectOneMenu it won't be the case.
Tim Holloway wrote:
@PostConstruct isn't really the best way to handle stuff like this. Generally, it's a good practice to have the requesting function invoke a method in the backing bean to load an existing record or create a new one, and initialize the bean's properties at that time. That does require injecting the editing bean to be injected into the requesting bean, however.
Ok this got me lost somehow. Where should I initialize my bean's fields and value if not in @PostConstruct annotations? The SelectOneMenu values are populated form a database, with some other input parameters - so where is the Java place to run the initialization code? Surely not the bean's constructor. I though @PostConstruct annotation was exactly for this purpose...
I added a snippet form the faces-config.xml file in the first post for further clarification.