Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jsf数据表列中的javascript访问commandLink_Javascript_Jsf 2_Datatable - Fatal编程技术网

如何使用jsf数据表列中的javascript访问commandLink

如何使用jsf数据表列中的javascript访问commandLink,javascript,jsf-2,datatable,Javascript,Jsf 2,Datatable,我的表单中有一个jsf数据表,如下所示 <h:form id="personId"> <h:dataTable id="hdatatable" value="#{Person.personList}" border="0" cellpadding="10" cellspacing="5" var="per" styleClass="order-table" headerClass="order-

我的表单中有一个jsf数据表,如下所示

<h:form id="personId">
     <h:dataTable id="hdatatable" value="#{Person.personList}" 
            border="0" cellpadding="10" cellspacing="5"
            var="per" styleClass="order-table"
            headerClass="order-table-header"
            rowClass="order-table-odd-row,order-table-even-row"
            syle="width: 950px" >


      <h:column id="tcoulm">
        <f:facet name="header">Action</f:facet>
        <h:commandLink id="editLink" value="Edit" action="#{person.editAction(per)}"/>
        <h:commandLink id="cancelLink" value="Undo" action="#{person.undoAction()}"/>
 </h:column>

</h:datatable>
</h:form>

行动
在上表中,我试图使用javascript访问编辑和撤消操作。因此,我为它们分配了Id。但是当我在html源代码中看到这些元素的Id时,它是这样的。这里的意思是我猜表的第三行。我可以在源代码中看到列Id

personId:hdatatable:3:editLink

若我只给命令链接提供Id,并在表单中提供'prependId=“false”,那个么我仍然看到commdndLink的Id,如下所示

j_id1267631877_14a2c285:编辑链接

如果我只使用表单Id和commandLink Id

formId:j_id1267631877_14a2c285:editLink

如何准确访问DataTaTable列中的元素?

只需使用

var editLink = document.getElementById("personId:hdatatable:3:editLink");
?

如果您不想单独访问它们,但想全部访问它们,那么给它们一个样式类就容易多了

<h:commandLink ... styleClass="editLink" />

我本来想使用jquery,但我在应用程序中使用了一些primefaces组件。因此,当我使用jquery时,primefaces组件不起作用。primefaces已经绑定了jquery。因此,如果您捆绑自己的,可能是不同版本的,那么它当然会冲突,导致所有颜色的错误。只是不要把你自己的打包。jQuery已经自动包含在包含PrimeFaces组件的页面上。当您的页面不包含PrimeFaces组件时,您可以通过
var $editLinks = $(".editLink");