【问题标题】:ActionListener method of a CommandButton inside Datatable (within TabView) don't workDatatable 内(TabView 内)的 CommandButton 的 ActionListener 方法不起作用
【发布时间】:2013-06-06 05:00:22
【问题描述】:

我在 Datatable 中有一个 CommandButton 组件,它位于 TabView 组件中。 CommandButton 组件的 ActionListener 方法不起作用。永远不会被解雇。

这是我的 XHTML 页面:

<p:dialog id="dlgView" widgetVar="wvDlgView"
    modal="true" closable="true" resizable="false">
    <p:outputPanel id="opViewUser">
    <h:form>
        <p:tabView id="tabViewUser">
            <p:tab title="DATOS PERSONALES">
                <p:dataTable id="dtUsuarios" rows="5" paginator="true"
                    selectionMode="single" selection="#{personController.system}">
                    ....
                    <p:column>

                        <p:commandButton value="Bloquear"  actionListener="#{personController.block}" />
                    </p:column>
                </p:dataTable>
            </p:tab>
        <p:tabView>
    </h:form>
    </p:outputPanel>
</p:dialog>

提前致谢:)

PD:PF 3.5,JSF (Mojarra) 2.1.3,Tomcat:6.0.10

【问题讨论】:

  • 没有 bean 代码很难说,但可能是一个糟糕的 bean 范围?
  • Bean 范围是@ViewScoped。我不放 bean 代码,因为错误我们永远不会触发该方法。如果有一个 sintaxis 错误会显示错误消息,但这不会发生。因此,我认为这是 primefaces 问题
  • 您有重现错误的SSCCE 吗?当前视图和 bean 的简化示例。
  • 更有可能是您在代码中犯了错误。由于到目前为止发布的代码看起来不错,并且您没有发布 SSCCE,因此问题无法回答,这里只是一个包含所有可能原因的链接,以便您可以自己排除一个和另一个:stackoverflow.com/questions/2118656/…
  • 感谢@BalusC!。选项 3 是我的问题

标签: jsf-2 primefaces commandbutton


【解决方案1】:

很抱歉没有发布完整的代码并稍后回答。无论如何,我认为已经没有必要了,因为我解决了我的问题。更详细地解释问题:

我在标签组件上有一个类似的结构:

<p:tab>
<h:form id="formTab" prependId="false">
    <h:panelGrid columns="3">
        <p:outputLabel value="Sistema " for="sltSystem"/>
        <p:selectOneMenu id="sltSistema" required="true"
            value="#{personController.idSistema}" >
            <f:selectItems value="#{personController.listSistemas" 
                var="s" itemLabel="#{s.valor}" itemValue="#{s.id}"/>
        </p:selectOneMenu>

        <p:outputLabel value="Rol " for="sltRol"/>
        <p:selectOneMenu id="sltRol" required="true" 
            value="#{personController.idRol}" >
            <f:selectItems value="#{personController.listRoles}" 
                var="r" itemLabel="#{r.valor}" itemValue="#{r.id}"/>
        </p:selectOneMenu>
    </h:panelGrid>


    <p:dataTable id="dtUsersSystems" rows="5" paginator="true"
        value="#{personController.userSystems}" var="s" rowKey="#{s.id}" >

        <p:column headerText="SISTEMA">
            <h:outputText value="#{s.sistema}" />
        </p:column>

        <p:column headerText="ROL">
            <h:outputText value="#{s.rol}" />
        </p:column>

        <p:column headerText="ESTADO">
            <h:outputText value="#{s.estado}"/>
        </p:column>

        <p:column>

            <p:commandButton value="Bloquear" icon="ui-icon-cancel" actionListener="#{personController.blocked}"></p:commandButton>
        </p:column>
    </p:dataTable>
<h:form>
</p:tab>

如您所见,sltSystemsltRol 组件在 true 中具有 required 属性。为此,当我单击“Bloquear”按钮时,它的 ActionListener 方法没有被调用,因为我应该在 sltSystem 和 sltRol 组件上选择一个值。

因此新的页面结构是这样的:

<p:tab>
<h:form id="formSelect" prependId="false">
    <h:panelGrid columns="3">
        <p:outputLabel value="Sistema " for="sltSystem"/>
        <p:selectOneMenu id="sltSistema" required="true"
            value="#{personController.idSistema}" >
            <f:selectItems value="#{personController.listSistemas" 
                var="s" itemLabel="#{s.valor}" itemValue="#{s.id}"/>
        </p:selectOneMenu>

        <p:outputLabel value="Rol " for="sltRol"/>
        <p:selectOneMenu id="sltRol" required="true" 
            value="#{personController.idRol}" >
            <f:selectItems value="#{personController.listRoles}" 
                var="r" itemLabel="#{r.valor}" itemValue="#{r.id}"/>
        </p:selectOneMenu>
    </h:panelGrid>
</h:form>
<h:form id="formDataTable" prependId="false">
    <p:dataTable id="dtUsersSystems" rows="5" paginator="true"
        value="#{personController.userSystems}" var="s" rowKey="#{s.id}" >

        <p:column headerText="SISTEMA">
            <h:outputText value="#{s.sistema}" />
        </p:column>

        <p:column headerText="ROL">
            <h:outputText value="#{s.rol}" />
        </p:column>

        <p:column headerText="ESTADO">
            <p:graphicImage value="#{s.estado}"/>
        </p:column>

        <p:column>

            <p:commandButton value="Bloquear" icon="ui-icon-cancel" actionListener="#{personController.blocked}"></p:commandButton>
        </p:column>
    </p:dataTable>
<h:form>
</p:tab>

selectonemenu 组件的表单和数据表组件的其他表单。

谢谢大家:)

【讨论】:

    猜你喜欢
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多