p:p中的commandLink:subTable标题仅针对第一个p:subTable触发

时间:2012-12-21 02:24:51

标签: datatable primefaces commandlink

我需要在subTable标头中显示一个commandlink。页面呈现正确但是只有第一个commandlink触发并且调用了action方法。所有后续的commandlinks都没有调用action方法。我查看了前两个锚元素的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>

2 个答案:

答案 0 :(得分:0)

我做了一个解决方法:

在您的链接/按钮(在您的subTable中)放置一个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"/>

答案 1 :(得分: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));" ... >