Question

I have problems with SelectOneMenu. I write this:

<h:selectOneMenu id="listaEstados"
        styleClass="comboboxStyle" 
        value="#{detalleSistemaBean.sistema.indEstado}" 
        immediate="true">
    <f:selectItems value="#{detalleSistemaBean.indEstados}" />
</h:selectOneMenu>
<h:commandButton id ="SubmitModificar"
    value="Modificar"
    styleClass="botonPeque"
    action="#{detalleSistemaBean.modificaSistema}">
</h:commandButton>  

But when I choose one value from the list "indEstados" and I submit the form, the bean "sistema.indEstado" doesn't change. I have seen that the bean property changes just before the method modificaSistema, but inside this method (where I have a database connection and a sql sentence), "sistema.indEstado" returns to its original value. Why this happens? I have tried to save the value using valueChangeListener, and that works, but I guess that is not a neat solution.

Was it helpful?

Solution

That can happen when you're doing data loading inside the getter method instead of inside the (post)constructor of the bean class.

Fix your managed bean code to not do anything else inside getter methods than just returning the property.

I.e. do not do

public Sistema getSistema() {
    return sistemaService.find(someSistemaId);
}

but rather do

private Sistema sistema;

@PostConstruct
public void init() {
    sistema = sistemaService.find(someSistemaId);
}

public Sistema getSistema() {
    return sistema;
}

OTHER TIPS

Can you try without setting

 immediate="true"

JSF commandButton with immediate="true"

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