小编Car*_*los的帖子

即使我没有更改值,也会在selectOneMenu上调用valueChangeListener方法

我有以下问题.当我单击"Enviar"按钮时,这将调用与selectOneMenu相关联的另一个方法(在属性valueChangeListener中称为"validarSelect"),然后调用此按钮在属性actionListener中关联的方法"validarBoton".我想知道,为什么会这样.我希望valueChangeListener不会被调用,因为我没有更改下拉列表.

这是我的页面JSF:

<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<html xmlns="http://www.w3.org/1999/xhtml">
    <h:head></h:head>
    <h:body>
        <h:form>
            <h:commandButton value="Enviar..." id="validar" actionListener="#{Domiciliacion.validarBoton}"/>
            <h:selectOneMenu valueChangeListener="#{Domiciliacion.validarSelect}"
                             binding="#{Domiciliacion.selectCombo}">
                <f:selectItems value="#{Domiciliacion.lista}"/>
                <f:ajax event="valueChange" render="@this"/>
            </h:selectOneMenu>
        </h:form>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

这就是ManagedBean:

package domiciliaciontest;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlSelectOneMenu;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

@ManagedBean(name = "Domiciliacion")
@ViewScoped

public class MB0001 {


private HtmlSelectOneMenu selectCombo;
private List<String> lista = new ArrayList<String>();

public MB0001() {
    super();
    System.out.println("Entro al constructor..."); …
Run Code Online (Sandbox Code Playgroud)

jsf jsf-2

5
推荐指数
1
解决办法
7297
查看次数

标签 统计

jsf ×1

jsf-2 ×1