1

我需要在 subTable 标题中显示一个命令链接。页面正确呈现,但是只有第一个命令链接会触发并调用操作方法。所有后续命令链接都不会调用操作方法。我查看了前两个锚元素的 html 源代码。生成的 id 略有不同。第一个链接的 id 在 j_dt68 之后没有数字,而第二个链接的 id 有 j_dt68:0。不确定它是否重要。请帮忙!

First commandlink's html code:
                    <a id="center_content_form:equipment_tabview:equipment-table:0:j_idt68:equipment_details_link" href="#" class="ui-commandlink"   onclick="PrimeFaces.ab({source:'center_content_form:equipment_tabview:equipment-table:0:j_idt68:equipment_details_link'});return false;">DGI5120_GI:SB-5120 | 06634CVJTKH5</a>

Second commandlink's html code:
<a id="center_content_form:equipment_tabview:equipment-table:1:j_idt68:0:equipment_details_link" href="#" class="ui-commandlink" onclick="PrimeFaces.ab({source:'center_content_form:equipment_tabview:equipment-table:1:j_idt68:0:equipment_details_link'});return false;">DAR502G_ARRIS:TM502G | 6A7BMU47P225361</a>


<p:dataTable id="equipment-table" styleClass="list-datatable"
var="equipment" value="#{equipmentBean.equipmentList}"
emptyMessage="#{equipment_msgs['equipment.table.emptyMessage']}">

<f:facet name="header">
    <p:commandButton immediate="true" id="assign_equipment"
        icon="add-sign" styleClass="table-header-button-class"
        title="#{equipment_msgs['assign.equipment.tooltip.text']}"
        action="#{equipmentBean.navigateToAssignEquipmentPage()}" />
    <h:outputText
        value="#{equipment_msgs['assign.equipment.button.label']}"
        styleClass="table-header" />
</f:facet>

<p:column id="port_number"
    headerText="#{equipment_msgs['port.number.column.label']}"
    styleClass="col10 table_text" />
<p:column id="port_address"
    headerText="#{equipment_msgs['address.column.label']}"
    styleClass="co20 table_text" />
<p:column id="port_type"
    headerText="#{equipment_msgs['type.column.label']}"
    styleClass="col20 table_text" />
<p:column id="port_category"
    headerText="#{equipment_msgs['port.category.column.label']}"
    styleClass="col20 table_text" />
<p:column id="service_category"
    headerText="#{equipment_msgs['service.category.column.label']}"
    styleClass="col20 table_text" />
<p:column id="occurrence"
    headerText="#{equipment_msgs['occurrence.column.label']}"
    styleClass="col20 table_text" />
<p:column id="modem"
    headerText="#{equipment_msgs['modem.column.label']}"
    styleClass="col10 table_text" />
<p:subTable var="port" value="#{equipment.portList}">
    <f:facet name="header">
        <p:separator styleClass="header-separator" />
        <p:commandLink  id="equipment_details_link"
            value="#{equipment.detailLinkValue}"
            action="#{equipmentBean.navigateToEquipmentDetailsPage()}" >
            <f:setPropertyActionListener value="#{equipment}"
                target="#{equipmentBean.selectedEquipment}" />
        </p:commandLink>
        <p:separator styleClass="header-separator" />
    </f:facet>
    <p:column>
        <p:commandLink immediate="true" id="equipment_port_details_link"
            value="#{port.portNumber}"
            action="#{equipmentBean.navigateToEquipmentPortDetailsPage(port.portNumber)}">
            <f:setPropertyActionListener value="#{equipment}"
                target="#{equipmentBean.selectedEquipment}" />
        </p:commandLink>
    </p:column>
    <p:column>
        <p:commandLink immediate="true" id="equipment_port_addressable_transaction_details_link1"
            value="#{port.portAddress}"
            action="#{equipmentBean.navigateToEquipmentAddressPortDetailsPage(port.portNumber)}">
            <f:setPropertyActionListener value="#{equipment}"
                target="#{equipmentBean.selectedEquipment}" />
        </p:commandLink>
    </p:column>
    <p:column>#{port.portType}</p:column>
    <p:column>#{port.portDetails.portCategory}</p:column>
    <p:column>#{port.portDetails.serviceCategory}</p:column>
    <p:column>#{port.portDetails.occurrence}</p:column>
    <p:column>#{port.portDetails.modemText} </p:column>
</p:subTable>
 </p:dataTable>
4

2 回答 2

0

我做了一个解决方法:

在您的链接/按钮(在您的子表内)上放置一个 onclick 属性以从 id 中删除额外的数字并调用 PrimeFaces.ad(..) 函数

像这样:

    <script type="text/javascript">
        function deleteMsg(id) {
            var pattern = /(\w+:\w+:\d+:\w+)(:\d+)(:\w+)/g;
            var newId = id;
            if (pattern.test(id)) {
                newId = id.replace(pattern, "$1$3");
            }

            PrimeFaces.ab({source:newId,update:'formTable'});
            return false;
        }
    </script>

在你的按钮上:

<p:commandButton onclick="return deleteMsg($(this).attr('id'))" actionListener="#{pSMsgController.removeMsg(_msg)}" icon="ui-icon-trash"/>
于 2013-03-18T13:58:46.320 回答
0

尝试这个。

id replace js:

<script type="text/javascript">
        function deleteMsg(link) {
            var id = link.attr('id'); 

            var pattern = /(\w+:\w+:\d+:\w+)(:\d+)(:\w+)/g;
            var newId = id;
            if (pattern.test(id)) {
                newId = id.replace(pattern, "$1$3");
            }

            PrimeFaces.ab({source:newId,update:link.attr('id', newId)});
            return false;
        }

子表标题中的 CommandLink:

  <p:commandLink onclick="return deleteMsg($(this));" ... >                 
于 2017-12-14T13:47:56.243 回答