簡體   English   中英

如何在JSF頁面中單擊行時打開新頁面?

[英]How to open a new page when row is clicked in a JSF page?

我有一個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輸出以確定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM