2
votes

My selectOneMenu isn't fireing an onchange event. Here is the code:

 <p:selectOneMenu id="select_preset" 
                  value="#{JobMgmtBean.presetGroupName}" 
                  valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}" 
                  onchange="submit();">
    <f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
</p:selectOneMenu>

The selectOneMenu is nicely populated, and I can select different values. But I would expect that after I change a selection, page would be refreshed, i.e. backing bean (RequestScoped) would be recreated (onchange="submit();")? But nothing happens when selection in the selectOneMenu is changed.

Also, value change listener PresetGroupChangeEvent() is not called.

Did I go wrong somewhere?

I'm using Tomcat 7.0.25 + MyFaces 2.1.6 + PrimeFaces 3.2.

4
Please check the similar issue : stackoverflow.com/questions/7687980/…rags
Did you try with h:selectOneMenu?Oscar Castiblanco

4 Answers

9
votes

try to remove

onchange="submit();"

and to add

<p:ajax update="@this"/>

from your p:selectOneMenu when you using primefaces

<p:selectOneMenu id="select_preset" 
              value="#{JobMgmtBean.presetGroupName}" 
              valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}">
    <f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
    <p:ajax update="@this"/>
</p:selectOneMenu>

check your listener signature (starts from big "P" ?)

import javax.faces.event.ValueChangeEvent;
public void PresetGroupChangeEvent(ValueChangeEvent event) { }
1
votes

why you are not adding update attribute using p:ajax? I think rerendering components more better solution than refreshing, also you can just rerender needed components. But if you still want to refresh page you can also use javascript:

<p:selectOneMenu id="select_preset" value="#{JobMgmtBean.presetGroupName}" onchange="window.location.reload();">
    <f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
</p:selectOneMenu>

and just for updating necessary components:

 <p:selectOneMenu id="select_preset" value="#{JobMgmtBean.presetGroupName}">
    <f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
    <p:ajax event="change" update="@form" />
</p:selectOneMenu>
1
votes

this works for me

<p:selectOneMenu id="select_preset" 
                  value="#{JobMgmtBean.presetGroupName}" 
                  valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}">
        <f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
        <p:ajax process="select_preset" partialSubmit="true" event="valueChange"  update="yourComponentName"/>
    </p:selectOneMenu>
0
votes

try to use ajax from primefaces and refresh only what you want to refresh