2013-11-26 34 views
10

我爲某些統計開發了一個接口JEE/JSF。 我創建了複選框來選擇用戶希望顯示的引用,但問題是我使用基於數據庫中的數據生成複選框Arraylist。渲染p:selectManyCheckbox有10列

我無法按照自己的意願放置它們。我想,經過10複選框,其他直接產生於線等..

我有這樣的結果

http://image.noelshack.com/fichiers/2013/48/1385458240-after.jpg

,我希望我能做到這一點

enter image description here

MTBFBEAN

private List<String> selectedReference = new ArrayList<String>(); 
private List<String> listReference = new ArrayList<String>(); 
private Boolean afficher = false; // Déclaration du bool pour le rendered de 
            // ma vue dans MTBF 

@SuppressWarnings("deprecation") 
public StatisticsBeanMTBF() { 
    this.beginDate = new Date(2001, 00, 01); 
    List<ProductConfModel> listtmp = this.moduleGlobal.getProductConfModels(2); 
    for (ProductConfModel pcm : listtmp) { 

     this.listReference.add(pcm.getReference()); 
     } 
    } 

public void mTBFByType() { 
    this.afficher = true; 
    this.listMTBF = new ArrayList<StatistiquesMTBF>(); 
    List<StatistiquesMTBF> suspense = this.moduleGlobal.getMTBFByType(nbHeure, nbJour, NS, DAE, beginDate, endDate); 
    for (StatistiquesMTBF smtbf : suspense) { 
     for (String s : this.selectedReference) { 
      if (smtbf.getReference().equals(s)) { 
       this.listMTBF.add(smtbf); 
      } 

JSF XHTML

<h:outputText value="Date début :* " /> 
        <p:calendar value="#{statisticsBeanMTBF.beginDate}" 
         navigator="true" required="true" /> 
        <h:outputText value="Date fin:* " /> 
        <p:calendar value="#{statisticsBeanMTBF.endDate}" navigator="true" 
         required="true" /> 

       </h:panelGrid> 
       <h:panelGrid columns="1"> 
        <h:outputText value="Selectionner votre référence : " /> 

        <p:selectManyCheckbox id="grid" columns="5" 
         value="#{statisticsBeanMTBF.selectedReference}"> 
         <f:selectItems value="#{statisticsBeanMTBF.listReference}" /> 
         </p:selectManyCheckbox> 
       </h:panelGrid> 
       <p:separator /> 

如果任何人都可以幫助我,那就太好了。

謝謝!

回答

12

我得到使用這個結果:

<h:panelGroup layout="block" styleClass="selection"> 
    <p:selectManyCheckbox layout="pageDirection" value="#{selection.selection}"> 
</h:panelGroup> 

,並設置每個<tr>

.selection tr { 
    float: left; 
    width: 33%; 
} 

在你的情況下,它設置爲10%,外容器width: 100%

它看起來像這樣:

enter image description here

+0

你好,謝謝你的幫助,但我是4.0 primefaces,你的標籤 Sars

+0

您使用PrimeFaces的事實並不意味着您不能使用普通的JSF標籤。我也使用PF4.0,但是.. – Kuba

+0

剛剛切換到'',結果是一樣的! – Kuba

6

根據此example,您應該將layout="grid"添加到您的p:selectManyCheckbox。就像這樣:

<p:selectManyCheckbox id="grid" layout="grid" columns="5" value="#{statisticsBeanMTBF.selectedReference}"> 
    <f:selectItems value="#{statisticsBeanMTBF.listReference}" /> 
</p:selectManyCheckbox> 

編輯:

快速搜索在PrimeFaces單證顯示,columns是在4.0版中加入。如果你沒有這個版本或者不能升級,你需要用一些CSS來做舊的方法。

+0

您好,感謝您的幫助,但它不工作 – Sars

+1

應該是的。提及PF版本並詳細闡述「不起作用」會很有幫助。 – BalusC

+0

您好BalusC,我使用primefaces 4.0。 – Sars