ValueChangeListener ne fonctionne pas

C'est mon code dans mon managed bean :-

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <center>
            <h:form>
                <h2> <u>Select Fruit(s). </u> </h2>

                <!-- Value Change Listener is entirely superflous. You can make a full blown project without requiring the need to ever use this...This is
                just for demo purpose..-->

                <h:selectManyMenu onchange="document.forms[0].submit();" style="height: 200px;font-size: 1.5em;width: 200px;"   >
                    <f:selectItems value="#{actionValueLisBean.fruitsList}" var="fruit" itemLabel="#{fruit}" itemValue="#{fruit}"/>

                    <f:valueChangeListener type="beans.ActionValueLisBean"/>
                </h:selectManyMenu>

                <h3> Your previous selection is :<h:outputText value="#{actionValueLisBean.prevSel}"/></h3>
                <h3>Your current selection is :<h:outputText value="#{actionValueLisBean.currSel}"/></h3>

            </h:form>
        </center>
    </h:body>
</html>

C'est mon haricot :-

package beans;
import com.sun.jmx.remote.internal.ArrayQueue;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
@ManagedBean
@RequestScoped
public class ActionValueLisBean implements ValueChangeListener {
private List<String> fruitsList;
private String currSel;
private String prevSel;
public String getCurrSel() {
return currSel;
}
public void setCurrSel(String currSel) {
this.currSel = currSel;
}
public String getPrevSel() {
return prevSel;
}
public void setPrevSel(String prevSel) {
this.prevSel = prevSel;
}
public List<String> getFruitsList() {
return fruitsList;
}
public void setFruitsList(List<String> fruitsList) {
this.fruitsList = fruitsList;
}
public ActionValueLisBean() {
fruitsList = new ArrayQueue<String>(5);
fruitsList.add("Apple");
fruitsList.add("Mango");
fruitsList.add("Banana");
fruitsList.add("Peach");
fruitsList.add("Plum");
}
@Override
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
if(event.getOldValue() != null)
prevSel = event.getOldValue().toString();
if(event.getNewValue() != null)
currSel  = "abc";
}
}

Et puis j'ai prevSel et currSel est lié à h:outputText. Mais la valeur n'est pas arriver, même si la processValueChange est déclenché correctement et System.out.println(event.getNewValue()); est aussi bien fonctionner. J'ai essayé différents champs de haricot trop, mais pas de l'utiliser. Je sais ValueChangeListener est totalement inutile. Encore je veux savoir comment il fonctionne.

Merci d'avance 🙂

InformationsquelleAutor TCM | 2010-08-29