CommandButton Onclick里面的选项卡总是带我到第一个选项卡Primefaces

时间:2014-11-25 04:15:22

标签: primefaces

以下是我的代码。这里CommandButton操作不起作用,总是移动第一个 标签

<h:head>
    <title>Alert Input</title>
</h:head>
<h:body>
    <h1 style="margin: auto;text-align: center">Fraud Alert Admin Page</h1>
    <p:separator style="height:5px;background-color:black;"/>
    <p:tabView id="tabs">
        <p:tab id="alertInput" title="Enter Alert">
            <h:form>
                <p:growl id="submitMessage" showDetail="true" sticky="true"/>
                <p:panel id="alertPanel">
                    <p:panelGrid columns="2" style="margin-bottom:10px">
                        <p:outputLabel for="sevLevel" value="Sev:" />
                        <p:selectOneMenu id="sevLevel" required="true" value="#{alertInputBean.alertSev}">
                            <f:selectItem itemLabel="Informational" itemValue="1"/>
                            <f:selectItem itemLabel="Warning" itemValue="2"/>
                            <f:selectItem itemLabel="Urgent" itemValue="3"/>
                            <f:selectItem itemLabel="Severe" itemValue="4"/>
                        </p:selectOneMenu>
                        <p:outputLabel for="alertName" value="Alert Name:"/>
                        <p:inputText id="alertName" required="true" label="Alert Name" value="#{alertInputBean.alertName}"/>
                        <p:outputLabel for="alertDescription" value="Alert Description:"/>
                        <p:inputText id="alertDescription" required="true" label="Description" value="#{alertInputBean.alertDesc}"/>
                    </p:panelGrid>
                    <p:toolbar>
                        <f:facet name="left">
                            <p:commandButton value="submit" actionListener="#{alertInputBean.submitAlert()}"
                                             update="submitMessage" ajax="false">
                            </p:commandButton>
                        </f:facet>
                        <f:facet name="right">
                            <h:commandButton value="Reset">
                                <p:ajax update="alertPanel" resetValues="true"/>
                            </h:commandButton>
                        </f:facet>
                    </p:toolbar>
                </p:panel>
            </h:form>
        </p:tab>
        <p:tab id="alertExisting" title="Current Alerts">
            <h:form id="form">
                <p:dataTable id="allAlerts" var="alerts" 
                             value="#{alertInputBean.retrieveAllAlerts()}"
                             emptyMessage="No alerts found with the given criteria."
                             selection="#{alertInputBean.selectedAlerts}" 
                             rowKey="#{alerts.alertName}" scrollable="true" scrollHeight="250">
                    <f:facet name="header">
                        Current Alerts
                    </f:facet>
                    <p:column selectionMode="multiple" style="width:16px;text-align:center"/>
                    <p:column headerText="Alert Severity">
                        <h:outputText value="#{alerts.sev}"/>
                    </p:column>
                    <p:column headerText="Alert Name">
                        <h:outputText value="#{alerts.alertName}"/>
                    </p:column>
                    <p:column headerText="Alert Description">
                        <h:outputText value="#{alerts.descrption}"/>
                    </p:column>
                    <p:column headerText="Creation Date">
                        <h:outputText value="#{alerts.createDate}"/>
                    </p:column>
                    <p:column headerText="Modify Date">
                        <h:outputText value="#{alerts.modifyDate}"/>
                    </p:column>
                    <p:column headerText="Enabled">
                        <h:outputText value="#{alerts.enabled}"/>
                    </p:column>
                    <f:facet name="footer">
                        <p:commandButton process="@this" value="Update" icon="ui-icon-search" 
                                         update=":tabs:form:multiAlertUpdate" onclick="PF('multiAlertDialog')show()"/>
                    </f:facet>
                </p:dataTable>
                <p:dialog header="Update Selected" widgetVar="multiAlertDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" width="200">
                    <p:outputPanel id="multiAlertUpdate" style="text-align: center">
                        <ui:repeat value="#{alertInputBean.selectedAlerts}" var="sAlerts">
                            <p:outputLabel value="#{sAlerts.sev}-#{sAlerts.alertName}" style="display: block"/>
                        </ui:repeat>
                    </p:outputPanel>
                </p:dialog>                 
            </h:form>
        </p:tab>
    </p:tabView>
</h:body>

以下是XHTML 我有上面的代码。问题是每当我点击命令按钮时,我都被重定向到第一个标签。意图onClick完全不起作用。

1 个答案:

答案 0 :(得分:1)

第一个命令按钮

之所以发生这种情况,是因为您已将ajax属性定义为false,并且您尝试使用actionListener调用使用ajax调用的方法。

设置ajax=true或只删除它(默认为true),您的页面可以正常工作

如果您不想要ajax行为,请使用action代替actionListener


上一个命令按钮

如果问题出现在最后一个命令按钮中(请在下次更清楚),您只需要定义type=button,这样它就可以作为一个简单的按钮。

<p:commandButton type="button" process="@this" value="Update" icon="ui-icon-search" 
 update=":tabs:form:multiAlertUpdate" onclick="PF('multiAlertDialog')show()"/>
相关问题