Ajax JSF2-commandButton在渲染后不执行操作

Ajax JSF2-commandButton在渲染后不执行操作,ajax,jsf-2,primefaces,cdi,Ajax,Jsf 2,Primefaces,Cdi,嘿,我一整天都在挣扎,但我还没找到答案。因此,我的问题是我的xhtml页面中有两个表单,第一个表单显示一个primefaces数据表,其中填充了来自我的DB的数据,第二个表单则填充了来自所选用户的数据以进行编辑。问题是,第二个表单有2个commandButtons,但在我渲染它之后(通过ajax调用),这些按钮似乎并没有调用action属性中的方法 这是我的代码,让它更清晰 这是我在xhtml页面中的第一个表单 <h:form id="form" style="width:710px;"&

嘿,我一整天都在挣扎,但我还没找到答案。因此,我的问题是我的xhtml页面中有两个表单,第一个表单显示一个primefaces数据表,其中填充了来自我的DB的数据,第二个表单则填充了来自所选用户的数据以进行编辑。问题是,第二个表单有2个commandButtons,但在我渲染它之后(通过ajax调用),这些按钮似乎并没有调用action属性中的方法

这是我的代码,让它更清晰

这是我在xhtml页面中的第一个表单

<h:form id="form" style="width:710px;">
    <p:dataTable id="dataTable" var="supervisor" value="#{tablaBean.modeloUsuario}"  
                             paginator="true" rows="15" paginatorPosition="bottom" selection="#{tablaBean.usuarioSel}"
                             paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {NextPageLink} {LastPageLink}"
                             rendered="#{tablaBean.showAll}">  
                    <f:facet name="header">  
                        <h:outputText value="Supervisores" />
                    </f:facet>  
                    <p:column  selectionMode="single" style="width:18px" />
                    <p:column headerText="Id" filterBy="#{supervisor.idUsuario}" filterStyle="width:35px;">  
                        <h:outputText value="#{supervisor.idUsuario}" />  
                    </p:column>   
                    <p:column headerText="Nombre" filterBy="#{supervisor.nombre}" id="nombreh">  
                        <h:outputText value="#{supervisor.nombre}" />  
                    </p:column>   
                    <p:column headerText="Ap. Paterno" filterBy="#{supervisor.apaterno}" id="apat">  
                        <h:outputText value="#{supervisor.apaterno}" />  
                    </p:column>   
                    <p:column headerText="Ap. Materno" filterBy="#{supervisor.amaterno}" id="amat">  
                        <h:outputText value="#{supervisor.amaterno}" />  
                    </p:column>   
                    <p:column headerText="Usuario" filterBy="#{supervisor.nombreUsuario}" id="user">  
                        <h:outputText value="#{supervisor.nombreUsuario}" />  
                    </p:column>    
                    <p:column headerText="Depto." filterBy="#{supervisor.departamento.nombre}" id="deptoh">  
                        <h:outputText value="#{supervisor.departamento.nombre}" />  
                    </p:column>
                    <f:facet name="footer">
                        <p:commandButton id="ver" value="Ver" icon="ui-icon-search" update=":form:userData" oncomplete="user.show()" />
                        <p:commandButton id="editar" value="Editar" icon="ui-icon-pencil" update=":form,:formEdit" action="#{tablaBean.edit()}" />
                    </f:facet>
                </p:dataTable>
            </h:form>
任何关于我可能做错什么的建议,我们都将不胜感激,提前谢谢

编辑 我做了更多的调试,发现我的托管bean在我每次点击第一个表单中的编辑按钮时都会被调用,所以我猜问题出在我的对话bean上

编辑2
我将backingbean的作用域更改为Application,现在它在点击编辑按钮时没有被调用,但是命令按钮仍然不起作用

不确定您使用的是哪个版本的PrimeFaces。在以前的版本中,我已经看到了使用PrimeFaces ajax正确传播CDI对话的问题。也看到了以前版本的Mojarra的问题。看来这可能有关系

发现了我的错误,
行中出现了一些错误,验证器中出现了NullPointerException错误(我已经修复了),但是。。。我现在觉得自己很愚蠢!xD,我必须将commandButton设置为none ajax,才能真正看到错误,因为它没有显示在服务器日志中。无论如何,感谢您的回答。

您好,谢谢您的回答,我正在使用Primefaces 3.3、Mojarra 2.1.6和Glassfish 3.1.2是否需要在命令按钮上设置ajax=true?不,这是命令按钮上的默认值
<h:form id="formEdit">
<p:growl />
<p:fieldset legend="Editar Usuario" style="margin: auto;" rendered="#{!tablaBean.showAll}">
    <h:panelGrid columns="3">
        <h:outputText value="Id" />
        <h:outputText value="#{tablaBean.usuarioSel.idUsuario}" id="id" />
        <p:message for="id" />
        <p:outputLabel for="nombre" value="Nombre" />
        <p:inplace>
            <p:inputText value="#{tablaBean.usuarioSel.nombre}" id="nombre" required="true" />
        </p:inplace>
        <p:message for="nombre" />
        <p:outputLabel for="appat" value="Apellido Paterno" />
        <p:inplace>
            <p:inputText value="#{tablaBean.usuarioSel.apaterno}" id="appat" required="true"/> 
        </p:inplace>
        <p:message for="appat" />
        <p:outputLabel for="apmat" value="Apellido Materno" />
        <p:inplace>
            <p:inputText value="#{tablaBean.usuarioSel.amaterno}" id="apmat" required="true"/> 
        </p:inplace>
        <p:message for="apmat" />
        <p:outputLabel for="usuario" value="Usuario" />
        <p:inplace>
            <p:inputText value="#{tablaBean.usuarioSel.nombreUsuario}" id="usuario" required="true"> 
                <f:ajax render="msgUsuario" event="blur" />
                <f:validator binding="#{userNameValidator}" />
            </p:inputText>
        </p:inplace>
        <p:message for="usuario" id="msgUsuario" />
        <p:outputLabel for="depto" value="Departamento" />
        <p:inplace>
            <p:inputText value="#{tablaBean.usuarioSel.departamento.nombre}" id="depto" required="true" /> 
        </p:inplace>
        <p:message for="depto" />
    </h:panelGrid>
    <p:commandButton value="Guardar" icon="ui-icon-disk" action="#{tablaBean.editarUsuario()}" />
    <p:commandButton id="editar" value="Cancelar" update=":form,:formEdit" icon="ui-icon-pencil" action="#{tablaBean.edit()}" />
</p:fieldset>
    @Named(value = "tablaBean")
    @ConversationScoped

public class TablaBean implements Serializable {

    @Inject
    private UsuariosDao usuario;
    @Inject
    private Usuarios usuarioSel;
    @Inject
    private Conversation conversation;
    private UserDataModel modeloUsuario;
    private boolean showAll;

    /**
     * Creates a new instance of TablaBean
     */
    public TablaBean() {
    }

    @PostConstruct
    public void init() {
        start();
        modeloUsuario = new UserDataModel(usuario.findSupers());
        showAll = true;
    }

    public void start(){
        conversation.begin();
    }

    public void end(){
        conversation.end();
    }

    public Usuarios getUsuarioSel() {
        return usuarioSel;
    }

    public void setUsuarioSel(Usuarios usuarioSel) {
        this.usuarioSel = usuarioSel;
    }

    public UserDataModel getModeloUsuario() {
        return modeloUsuario;
    }

    public boolean isShowAll() {
        return showAll;
    }

    public void setShowAll(boolean showAll) {
        this.showAll = showAll;
    }

    public UsuariosDao getUsuario() {
        return usuario;
    }

    public void setUsuario(UsuariosDao usuario) {
        this.usuario = usuario;
    }

    public String edit() {
        System.out.println("holis");
        showAll = !showAll;
        return "";
    }

    public String editarUsuario(){
        System.out.println("hola");
        end();
        return "";
    }
}