0

I am having a problem with the SelectOneMenu control. I want the the selected item to be be displayed via the valueChange Ajax event listen. But this is not happening.

However, when I change the value in the SelectOneMenu and then click on the Submit button, then selected value is getting displayed via the 'save' bean function

Cannot figure out why this is not working. Would appreciate any help on this.

Thanks.

The relevant xhtml code is as follows:

<h:form>
<h:dataTable value="#{dynamicList.myData}" var="item" >
    <h:column>
        <h:outputText value="#{item.oracleType}"></h:outputText>
    </h:column>         
    <h:column>
        <h:selectOneMenu value="#{item.coffeeFlavour}" rendered="#{item.showLov}" >
            <f:selectItems value="#{item.coffeeList}"></f:selectItems>
            <f:ajax event="valueChange" listener="#{dynamicList.listen}" ></f:ajax>

        </h:selectOneMenu>
        <h:inputText value="#{item.coffeeFlavour}" rendered="#{item.showText}">       
        </h:inputText>

    </h:column>

    </h:dataTable>

    <p:commandButton  value="Submit" action="#{dynamicList.save}" ></p:commandButton>   

</h:form>

The relevant bean code is as follows:

@ManagedBean
@ViewScoped

public class DynamicList implements Serializable{
private List<OraclePrfl> oracleList=new ArrayList<OraclePrfl>();
private String coffee;
private  Map<String,String> coffeeList=new LinkedHashMap<String,String>();

public List<OraclePrfl> getOracleList() {       
return oracleList;
}

public List<OraclePrfl> getMyData()
{
oracleList.clear();
oracleList.add(new OraclePrfl("Oracle Lot Number",new HashMap<String,String>(){
{
 put("Coffee2 - Cream Latte", "Cream Latte");
 put("Coffee2 - Extreme Mocha", "Extreme Mocha");
 put("Coffee2 - Buena Vista", "Buena Vista");
 }
},true,false));

oracleList.add(new OraclePrfl("Oracle Product Number",new HashMap<String,String>(){
{
 put("ABC", "abc");put("PQR", "pqr");put("XYZ", "xyz");
}
},true,false));
oracleList.add(new OraclePrfl("Oracle Specification",new HashMap<String,String>(){
{
 put("MNP", "mnp");put("WXY", "wxy");put("XYZ", "xyz");
}
},true,false));

oracleList.add(new OraclePrfl("Address",false,true));

return oracleList;
}

public void setOracleList(List<OraclePrfl> oracleList) {
this.oracleList = oracleList;
}   

public String getCoffee() {
return coffee;
}

public void setCoffee(String coffee) {
this.coffee = coffee;
}

public Map<String,String> getCoffeeList() {
coffeeList.clear();
coffeeList.put("Coffee2 - Cream Latte", "Cream Latte"); //label, value
coffeeList.put("Coffee2 - Extreme Mocha", "Extreme Mocha");
coffeeList.put("Coffee2 - Buena Vista", "Buena Vista");
return coffeeList;
}

public void setCoffeeList(Map<String,String> coffeeList) {
this.coffeeList = coffeeList;
}

 public void save(){
 for(OraclePrfl oracle:oracleList){
  System.out.println("oracle type------"+oracle.getOracleType()+"------coffee----    
  "+oracle.getCoffeeFlavour());
  }
}

public void listen(AjaxBehaviorEvent event){        

System.out.println("calling listener "+event.getSource().toString());


for(OraclePrfl oracle:oracleList){
System.out.println("type....."+oracle.getOracleType()+"----value-----
"+oracle.getCoffeeFlavour());

    }
}

}

Sv Prasad
  • 31
  • 2

1 Answers1

0

Try removing the event:

<f:ajax listener="#{dynamicList.listen}" ></f:ajax>

It should default to event="change".

Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
  • Thanks for the response. Removing the even did not work. – Sv Prasad Aug 18 '14 at 02:22
  • @SvPrasad Do you have a h:head? Which JSF version are you using? Maybe you can find inspiration here: http://stackoverflow.com/questions/6089924/the-fajax-listener-method-in-hselectonemenu-is-not-executed – Jaqen H'ghar Aug 18 '14 at 05:40
  • 1
    Sorry for the delay in responding. We have solved the problem. Thanks a lot for you response and interest. – Sv Prasad Aug 23 '14 at 05:47