myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Brainard <>
Subject Re: ValueChangeListener is executed three times
Date Mon, 22 Oct 2007 16:24:22 GMT
Wolfgang wrote:
> Hi,
> I have three different SelectOneMenu components with 
> ValueChangeListeners.
> Each ValueChangeListener calles the same method!
> If you now change the value from one of the selectOneMenus all three 
> ValueChangeListener
> will be called, so the processValueChangePosResult method is called 
> three times.
> I tried it also with three different ValueChangeListener methods. But 
> each time you change
> one of the selectOneMenu's values all three changeListeners will be 
> called.
> I suppose it depends on the onchange="submit()" method,  because it 
> appears in all three menus...
> Any suggestions?
> Thanks!
> Wolfgang
> <h:selectOneMenu id="itemPosPicr"
>                            rendered="#{currentData.renderedPicrPos}"
> valueChangeListener="#{siteChanger.processValueChangePosResult"
>                            onchange="submit()">
>               <f:selectItems value="#{currentData.itemPosPicr}"/>
>           </h:selectOneMenu>
> public void processValueChangePosResult(ValueChangeEvent value) throws 
> IOException {
>       String selectedValue = (String) value.getNewValue();
>       System.out.print(selectedValue);
> FacesContext.getCurrentInstance().getExternalContext().redirect("");

>   }
Hi Wolfgang,

There are two workaround for this problem:
1) rather than doing onchange="submit" you can call another javascript 
method which will click an invisible button(use CSS to hide the button) 
which will have the required method to call as action binding. Here the 
method which we want to call is cald only once.
jsp:call clickMe() a js method

<h:selectOneMenu id="itemPosPicr_3" onchange="clickMe()"
            <f:selectItems value="#{selectOneBean.map3}" />

button: click is the method we want to call.

<t:commandButton forceId="true" id="displayRecords"
            action="#{}" styleClass="searchButton">

js: Use this to click . this will be inside the js method clickMe()


2) another way is to use the same way as you had implemented but add a 
default value to the dropdown so that we can check with a condition.

public void processValueChangePosResult(ValueChangeEvent value) throws 
IOException {
        String selectedValue = (String) value.getNewValue();

Where default is the value of the default selected item. This will help 
us to prevent the line ; System.out.println(selectedValue);  to be 
executed 3 times.

Anyhw we cant prevent the method being cald 3 times but we can assure 
that the portion to be executed is done only once.

Personally i prefer the 1st way. I have implemented like that in many 

David Brainard Sounthiraraj.

View raw message