Strange problem with subTable and AJAX refreshes
alibsd Mar 16, 2009 5:14 AMHi
I'm working on creating some kind of grouping by use of rich:subTable.
The sample code is:
xhtml file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"> <body> <f:view> <h:form> <rich:dataTable id="lettersGrid" value="#{lettersBean.lettersGroup}" var="letterGroup"> <f:facet name="header"> <rich:columnGroup> <rich:column> <h:outputText value="subject" /> </rich:column> <rich:column> <h:outputText value="sender" /> </rich:column> <rich:column> <h:outputText value="receiver" /> </rich:column> <rich:column> <h:outputText value="type" /> </rich:column> </rich:columnGroup> </f:facet> <rich:column colspan="4"> <h:commandButton action="#{letterGroup.toggleShow}" value="#{letterGroup.name}" /> </rich:column> <rich:subTable id="subTable" value="#{letterGroup.letters}" var="letter"> <rich:column> <h:outputText value="#{letter.subject}" /> </rich:column> <rich:column> <h:outputText value="#{letter.sender}" /> </rich:column> <rich:column> <h:outputText value="#{letter.receiver}" /> </rich:column> <rich:column> <h:outputText value="#{letter.type}" /> </rich:column> </rich:subTable> </rich:dataTable> </h:form> </f:view> </body> </html>
and the managed beans are:
package com.salimi; import java.util.ArrayList; import java.util.List; public class LettersBean { private String groupCol = "type"; private List<LetterGroup> letterGroups; public LettersBean() { letterGroups = new ArrayList<LetterGroup>(3); for (int i = 0; i < 3; i++) { String typeName = "type " + i; List<Letter> groupLetters = new ArrayList<Letter>(); LetterGroup grp = new LetterGroup((i % 2 == 0), typeName, groupLetters); letterGroups.add(grp); for (int j = 0; j < 10; j++) { groupLetters.add(new Letter("subject " + i + "_" + j, typeName, "sender " + i + "_" + j, "receiver " + i + "_" + j)); } } } public List<LetterGroup> getLettersGroup() { return letterGroups; } public void setLettersGroup(List<LetterGroup> group) { } public String getGroupCol() { return groupCol; } public void setGroupCol(String groupCol) { this.groupCol = groupCol; } }
package com.salimi; import java.util.ArrayList; import java.util.List; public class LetterGroup { private String name; private List<Letter> letters; private boolean mustShow; public LetterGroup(boolean mustShow, String name, List<Letter> letters) { super(); this.name = name; this.letters = letters; this.mustShow = mustShow; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Letter> getLetters() { if (mustShow) { System.err.println(name + " returning list with size = " + letters.size()); return letters; } else { System.err.println(name + " returning EMPTY list"); return new ArrayList<Letter>(); } } public void setLetters(List<Letter> letters) { this.letters = letters; } public boolean isMustShow() { System.err.println(name + " must " + (mustShow ? "" : "not") + " be shown"); return mustShow; } public void setMustShow(boolean mustShow) { this.mustShow = mustShow; } public void toggleShow() { mustShow = !mustShow; } }
Managed beans are Session Scoped. Everything is fine when h:commandButton
is used. But when it is replaced by a4j:commandButton, the data of subTable is
not shown. I can't understand the reason for this strange behavior. Any ideas why
AJAX updates do not work, while normal postbacks work correctly.
BTW, first I wanted to use rendered attribute of the subTable, but since it was
not work either, I had to handle show/hide subtable in LetterGroup.getLetters() method.
Regards