<h:dataTable value="#{locale$select.classes}" var="class">
<h:column>
<f:facet name="header">
<f:verbatim>Students</f:verbatim>
</f:facet>
<h:dataTable value="#{class.students}" var="s">
<h:column>
<h:commandLink action="" value="#{s}" immediate="true">
&n bsp;&n bsp; <f:param name="name" value="#{s}"/>
</h:commandLink>
</h:column>
</h:dataTable>
</h:column>
<h:column>
<f:facet name="header">
<f:verbatim>Class Id</f:verbatim>
</f:facet>
<h:outputText value="#{class.id}"/>
</h:column>
<h :column>
<f:facet name="header">
<f:verbatim>Description</f:verbatim>
</f:facet>
<h:outputText value="#{class.description}"/>
</h:column>
</h:dataTable>
</h:form>
Managed Bean:
ClassInfo[] classes = new ClassInfo[3];
classes[0] = new ClassInfo(new Integer(100), "Basket Weaving");
classes[1] = new ClassInfo(new Integer(200), "Industrial arts");
classes[2] = new ClassInfo(new Integer(300), "Computer Science");
return classes;
}
public String selectStudent() {
FacesContext facesContext = FacesContext.getCurrentInstance();
String name = (String) facesContext.getExternalContext().getRequestParameterMap().get("name");
&nbs p;&nbs p; System.out.println(name);
return null;
}
ClassInfo Class:
private Integer id = null;
private String description = null;
public ClassInfo(Integer id, String description) {
this.id = id;
this.description = description;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String[] getStudents() {
//FacesContext facesContext = FacesContext.getCurrentInstance();
// simulate a db call
if (id.equals(100)) {
return new String[] {
"Bob", "Sally", "Fred"
};
} else if (id.equals(200)) {
return new String[] {"Joe", "Ben"};
} else
return new String[] {"Gary", "Zane", "Seth"};
}
}
-------------- Original message --------------
From: "Romanowski, Tim" <[EMAIL PROTECTED]>
Gary, thanks for the suggestion, but I'm not sure I understand how this will help me:Are you suggesting to use the datalist within my datatable? In such a case, the value returned by "#{countryList.countries}" is dependent upon the row id of my datatable. So I would have several columns in my datatable, of which one of those columns can have multiple 'sub-rows' per datatable row. When I render my datatable, how would I access the current row id in a bean so that I can do a calculation for displaying more data in _another_ column for the _same_ row? Emphasis added since the wording can get tricky.I could solve this by having two Lists, one which is used for the datatable, and another used by the particular column. I could then synchronize those lists myself, and write some spaghetti to increment a counter every time I grab the data for the particular multi-row column. However, that is a pretty ugly way of handling this, and I'm hoping there is an elegant (or at least less ugly) solution. Thoughts?
From: Gary VanMatre [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 19, 2006 4:16 PM
To: MyFaces Discussion
Subject: RE: Constructing Datatable with Columns Having Foreign Key referencesYou might give the dataList component a look. The rowIndexVar will give you the current row (http://myfaces.apache.org/tomahawk/dataList.html).<t:dataList id="data1"
styleClass="standardList"
var="country"
value="#{countryList.countries}"
layout="simple"
rowCountVar="rowCount"
rowIndexVar="rowIndex">
<h:outputText value="#{country.name}" />
<h:outputText value=", " rendered="#{rowIndex + 1 < rowCount}" />
</t:dataList>Gary-------------- Original message --------------
From: "Romanowski, Tim" <[EMAIL PROTECTED]>
Perhaps to point this in a useful direction: is it possible to get a value of the current row (such as "row.id") from the FacesContext in a bean? For example:<t:column><f:facet name="header"><f:verbatim>MyValues</f:verbatim></f:facet><h:outputText value="${currentRow.currentRowValues}" /></t:column>Is it possible to access another value for the currentRow object, such as currentRow.ID, by calling the FacesContext in a backing bean? If so, what is the proper way to do this?
From: Romanowski, Tim
Sent: Wednesday, April 19, 2006 9:57 AM
To: [email protected]
Subject: Constructing Datatable with Columns Having Foreign Key referencesWhen constructing a myfaces (tomahawk) datatable, I have a couple columns that each contain foreign key references. How do you guys handle the situation where a given row in a datable might have a column that itself has multiple rows? In other words, row 1 of my datable has a column which itself contains several rows. It doesn't seem like placing a child datatable within a parent datatable will necessarily solve anything, since I don't know what data goes in the current row until I know the value of a column in the current row.
From reading looking through the archives and some other sites, it looks (is this true?) that there is no clean way to pass a parameter of the current row id back to a backing bean to do some processing for dynamically constructing the current row. I've seen some suggestions on setting f:param and using that value, but setting an f:param to equal the current rowid in a datatable doesn't seem to work. I've also seen another kludge that used a 'disabled' property to set a map value, but that was, well, a kludge (but perhaps the best way?).
Again, how are you guys constructing complex tables? Any help would be greatly appreciated!
_____________________________________
TR

