1

I do have a page, where I have a list of rich:collapsiblePanel that hold input elements. These collapsiblePanels themselves store their expanded/collapsed state within a backing bean.

Now I have the use case to Open/Close all of these collapsiblePanels at once, with one mouse click. So I have tried to achieve this with the two commandButtons over the list. These use the attached actionListener to iterate over all backing beans of the collapsiblePanels and set the expanded flag to true/false.

This seems to work, unless you Open or Close one of the collapsiblePanels on their own. As soon as that happens clicking the buttons does not do anything anymore.

<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>

I have published a project on github so that you can try around with the code.

For completeness here are the two backing beans

@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;
    }

}
4

1 回答 1

2

This may be related to this RichFaces bug?!: https://issues.jboss.org/browse/RF-11546

于 2013-08-16T13:44:03.250 回答