2012-05-02 10 views
0

私は、データの行とJSF h:datatableを持っている:JSFページで行がクリックされたときに新しいページを開く方法は?

<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"); 
     }); 

問題は、私は、行をクリックしたときに新しいページを開いて、データを渡すためにはJavaScriptが使用するJSFタグを必要とするということです。この例では、hrefを使用して新しいウィンドウに移動します。私は同じ目的のために使用することができるJSFタグが必要です。適切なJSFタグはありますか?

お祈り申し上げます

答えて

1

あなただけのJSFでプレーンなHTML <a>を使用することができます。

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

やコンクリートの質問に

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

無関係<h:link>は、お使いのjQueryのセレクタのように、JSFはIDとクライアントIDを付加することを考慮に入れることを忘れないでください親命名コンテナコンポーネントの生成されたHTML出力を確認してください。

+0

新しいページを開く別の方法はありますか?たとえば、マネージドBeanからJavaメソッドを呼び出すためにローをクリックすることが可能です。 Javaメソッドは、たとえば "123acb"を返します。これをナビゲーションルールとしてfaces-config.xmlに設定します。 –

+0

JavaScriptを十分に活用しているわけではありません。たとえば、PrimeFacesの「」などの方が使いやすいです。 http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf – BalusC

+0

よく、私は純粋なJSFを使いたいと思っています。私の目標を達成するための可能な方法を考えてもらえますか? –

関連する問題