2017-03-23 14 views
0

commandButtonをクリックするとデータテーブルを表示したい。私のファイルは次のようになります:ボタンを押した後でデータテーブルを表示する

<h:commandButton value="List all students"></h:commandButton> 

<h:panelGroup id="table-wrapper"> 
    <h:dataTable value = "#{jSFDatabase.students}" var="s" border="1"> 

     <h:column><f:facet name = "header"><h:outputText value="ID"/></f:facet> 
      <h:outputLabel value="#{s.id }"></h:outputLabel> 
     </h:column> 

     <h:column><f:facet name = "header"><h:outputText value="Firstname"/></f:facet> 
      <h:outputLabel value="#{s.firstname }"></h:outputLabel> 
     </h:column> 

     <h:column><f:facet name = "header"><h:outputText value="Lastname"/></f:facet> 
      <h:outputLabel value="#{s.lastname }"></h:outputLabel> 
     </h:column> 

     <h:column><f:facet name = "header"><h:outputText value="Birthdate"/></f:facet> 
      <h:outputLabel value="#{s.birthdate }"></h:outputLabel> 
     </h:column> 
    </h:dataTable> 
</h:panelGroup> 

どうすれば問題を解決できますか?私はデータテーブルを更新しようとしましたが、うまくいきませんでした。

答えて

-1

これはcssを使用して実行できます。によると、トグルメソッドを呼び出して、あなたのコマンドボタンで

@ManagedBean 
public class Mybean { 
private boolean show = false; 
public void toggle() { 
    show= !show; 
} 

public boolean isShow() { 
    return show; 
} 

public void setRender(boolean show) { 
    this.show = show; 
} 
} 

をテーブルを更新して見えるように、あなたのテーブルにCSSスタイルを追加したり、隠された: トグル方式で、管理対象Bean内のブールフラグを追加します。フラグboolean

<h:commandButton value="List all students" action="#{myBean.show}" update="table-wrapper"></h:commandButton> 

<h:panelGroup id="table-wrapper" style="display: #{mybean.show ? 'none' : 'block'}"> 
... 
</h:panelGroup>