Why is h:selectOneMenu onchange fired two times and why valueChangeListener is not fired without onchange?

187 Views Asked by At

It is my first post on stackoverflow, I hope i'm doing it right

I'm working with JSF and Xnet since some weeks (maybe 2 or 3) and I have two questions about h:selectOneMenu.

First question : the onchange event is called two times. First time is when I click to open the dropdown list and second time is when I select an option. I discover that it is called the first time because when I open the dropdown list the selected value change and it select the first value in the list. Is this a normal behavior ?
Second question : the valueChangeListener is not called if i did not put the onchange... Again, is this a normal behavior ?

I don't know exactly on which JSF version I work but I know it is before 2 (it's something like 1.X.... It's not my fault, I swear, it's my company's fault) Here is the code, I don't know if it can help... The code is not mine, i'm working on correcting a bug.

Here is the h:selectOneMenu on my jsp

<h:panelGrid columns="2">
    <h:selectOneMenu id="id_label" value="#{parentBean.bean.rapportId}"
        immediate="true" onchange="this.form.submit();" valueChangeListener="#{parentBean.refreshDisplay}">
        <f:selectItems id="list_label" value="#{parentBean.labelList}" />
    </h:selectOneMenu>
</h:panelGrid>

And here is the method called by the valueChangeListener in the bean

public String refreshDisplay(ValueChangeEvent event) {
    Integer id = (Integer) event.getNewValue();
        ObjectA process = (ObjectA) ObjectA.getInstance();
    try {
        BeanA rBean = (BeanA) process.findById(BeanA.class, new Object[] { id });
        setBean(rBean);
    } catch (MyException e) {
        e.printStackTrace();
        log.error(e, e);
    }
    return "";
}

I'm beginner on JSF, so there is many things I didn't understand well, this is why I didn't know if this is normal or not.

0

There are 0 best solutions below