我有一个带有行数据的JSF h:datatable

  <h:dataTable id="dataTable" value="#{SessionsController.dataList}" binding="#{table}" var="item">
                    <!-- Check box -->
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Select" />
                        </f:facet>
                        <h:selectBooleanCheckbox  onclick="highlight(this)" value="#{SessionsController.selectedIds[dataItem.id]}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="№" actionListener="#{SessionsController.sort}">
                                <f:attribute name="№" value="№" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{table.rowIndex + SessionsController.firstRow + 1}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="Account Session ID" actionListener="#{SessionsController.sort}">
                                <f:attribute name="sortField" value="Account Session ID" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{item.aSessionID}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="User ID" actionListener="#{SessionsController.sort}">
                                <f:attribute name="sortField" value="User ID" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{item.userID}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="Activity Start Time" actionListener="#{SessionsController.sort}">
                                <f:attribute name="sortField" value="Activity Start Time" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{item.activityStart}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="Activity End Time" actionListener="#{SessionsController.sort}">
                                <f:attribute name="sortField" value="Activity End Time" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{item.activityEnd}" />
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:commandLink value="Activity" actionListener="#{SessionsController.sort}">
                                <f:attribute name="sortField" value="Activity" />
                            </h:commandLink>
                        </f:facet>
                        <h:outputText value="#{item.activity}" />
                    </h:column>
                </h:dataTable>


我想赋予用户单击行时打开新页面的能力。
我发现JavaScript代码很有用:

   $("table#dataTable tbody tr").click(function () {
            window.location = $(this).find("a:first").attr("href");
        });


问题是我需要一个JSF标记,当单击该行并传递数据时,JavaScript将使用它来打开新页面。在此示例中,href用于导航到新窗口。我需要可以用于相同目的的JSF标签。有合适的JSF标签吗?

最好的祝愿

最佳答案

您只能在JSF中使用纯HTML <a>

<a href="page.xhtml">link</a>


<h:link>

<h:link value="link" outcome="page" />




与具体问题无关,就您的jQuery选择器而言,请不要忘记考虑JSF在客户端ID之前加上父命名容器组件的ID。检查生成的HTML输出以确保。

10-07 18:59
查看更多