2013-08-16 30 views
1

我確實有一個頁面,其中有一個rich:collapsiblePanel列表,用於保存輸入元素。這些collapsiblePanels自己將展開/摺疊狀態存儲在輔助bean中。a4j中的collapsiblePanel的批量打開/關閉:重複

現在我有用例來一次打開/關閉所有這些collapsiblePanel,只需點擊一下鼠標。所以我試圖用列表中的兩個命令按鈕來實現這一點。這些使用附加的actionListener迭代collapsiblePanels的所有支持bean,並將擴展標誌設置爲true/false。

這似乎工作,除非你打開或關閉其中一個collapsiblePanels自己。一旦發生這種情況,單擊按鈕不會再做任何事情。

<h:form prependId="false"> 

    <a4j:commandButton value="Open All" actionListener="#{viewBean.doOpenAll}" render="c" /> 
    <a4j:commandButton value="Close All" actionListener="#{viewBean.doCloseAll}" render="c" style="margin-left: 10px;" /> 

    <a4j:outputPanel id="c"> 
    <a4j:repeat id="repeat" value="#{viewBean.items}" var="item"> 
     <rich:collapsiblePanel id="panel" expanded="#{item.expanded}"> 
      <h:outputLabel id="text_lbl" value="text" /> 
     <h:inputText id="text" value="#{item.text}" /> 
     </rich:collapsiblePanel> 
    </a4j:repeat> 
    </a4j:outputPanel> 

</h:form> 

我已經發布了a project on github,以便您可以嘗試使用代碼。

爲了完整這裏有兩個支持豆

@ViewScoped 
@ManagedBean 
public class ViewBean implements Serializable { 
    static final Logger LOG = LoggerFactory.getLogger(ViewBean.class); 

    private static final long serialVersionUID = -6239437588285327644L; 
    private List<ListItem> items; 

    public ViewBean() { 
     items = new ArrayList<ListItem>(10); 
     for (int i = 0; i < 10; i++) { 
      items.add(new ListItem("item " + i)); 
     } 
    } 

    public void doOpenAll() { 
     LOG.debug("open all"); 
     for (ListItem item : items) { 
      item.setExpanded(true); 
     } 
    } 

    public void doCloseAll() { 
     LOG.debug("close all"); 
     for (ListItem item : items) { 
      item.setExpanded(false); 
     } 
    } 

    public List<ListItem> getItems() { 
     return items; 
    } 

} 
public class ListItem { 

    private boolean expanded; 
    private String text; 

    public ListItem(String text) { 
     super(); 
     this.text = text; 
    } 

    public boolean isExpanded() { 
     return expanded; 
    } 

    public void setExpanded(boolean expanded) { 
     this.expanded = expanded; 
    } 

    public String getText() { 
     return text; 
    } 

    public void setText(String text) { 
     this.text = text; 
    } 

} 

回答

2

這可能與此有關RichFaces的錯誤:?!https://issues.jboss.org/browse/RF-11546

+0

感謝您的答覆,我想中驗證這一點jboss論壇。不幸的是,自從週五(2013年8月16日)以來已經下降。 – cheffe

+1

這是一個有關richfaces 4.3.3的問題,並已使用4.3.4解決 – cheffe