Nesting table rowgroups

Hi,

Is there a way to nest tablerowgroups in a table? I saw a tutorial has two table row groups but there display one after other. Say, I have a person list, l'd like to group the person based on the last name, and the table will look like this:

Last name First NameAddresssome other stuff

grp One:Doe

grp Two Joe123 main st.

grp Two Smith 1234 main st.

grp One:XXXX

grp Two Joe 2

grp Two Smith2.

Thanks

Jimmy

[478 byte] By [Jimmy200012a] at [2007-11-26 21:07:11]
# 1
Hi!You can group and order your entities in SQL query with command "GROUP BY" and "ORDER BY".Thanks,Roman.
-Grif-a at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 2
Yes. You can use group by in the query, but in the output table, those the group will be repeated. Don't know if there's a visual way, or you just need to dynamically to create it not using data table.
Jimmy200012a at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 3

I did this by designing two tables on the same page then go to the JSP view and move the code of the second table into one tableColumn of the first table.

The second thing is I have to set the parameters of the second table's sql command to values of the coressponding currentRow when each row of the first table is displaying.

Vu

vuqphama at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 4

Vu,

Thank you so much for replying. I have no trouble putting the second table inside the first one's column. But I have no idea where to change the sql command or set the rowsetObject. Would you please post some examples?Let's say the first table is a person table, and the second one is the trip table. where should I put the first table's personid as the query paramter for the trip table?which method should I modify?

Thanks

Jimmy

Jimmy200012a at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 5

Jimmy,

I post below the code that I am using which is for listing the pair of projects/department ( the outside table ) and their corresponding update status ( inside table ). One pair of project/dep may have multiple lines of status.

The main idea is to hook the code to get currentRow values to update the '? paramters' of the 2nd sql. To do so, I extends the classes CachedRowSetXImpl and CachedRowSetDataProvider to be able to put my code in.

Because of using the extended classes, I have to modify the class types of the rowSet variables in Session1.java also.

Sorry for my ugly code. If I have time, I will create a sample project with clearer code/comments tonight.

Vu

-- class WrappedCachedRowSetDataProvider -

package webcontractor.bean;

import com.sun.data.provider.impl.CachedRowSetDataProvider;

import com.sun.data.provider.RowKey;

import javax.sql.rowset.CachedRowSet;

import com.sun.data.provider.FieldKey;

public class WrappedCachedRowSetDataProvider extends CachedRowSetDataProvider{

/** Creates a new instance of WrappedCachedRowSetDataProvider */

private String cachedName;

private int hooked = 0;

public WrappedCachedRowSetDataProvider() {

}

public CachedRowSet getCachedRowSet() {

//System.out.println("*** getCachedRowSet" + ": " + getCachedName());

CachedRowSet crs = super.getCachedRowSet();

if( crs instanceof WrappedCachedRowSetXImpl )

((WrappedCachedRowSetXImpl)crs).setHooked(hooked);

return super.getCachedRowSet();

}

public String getCachedName() {

return cachedName;

}

public void setCachedName(String cachedName) {

this.cachedName = cachedName;

}

public int getHooked() {

return hooked;

}

public void setHooked(int hooked) {

this.hooked = hooked;

}

}

- class WrappedCachedRowSetXimpl.java

package webcontractor.bean;

import java.sql.SQLException;

import javax.sql.rowset.CachedRowSet;

import com.sun.sql.rowset.CachedRowSetXImpl;

import oracle.net.ano.SupervisorService;

import com.sun.rowset.internal.BaseRow;

import com.sun.data.provider.impl.CachedRowSetDataProvider;

public class WrappedCachedRowSetXImpl extends CachedRowSetXImpl{

private int wrapped = 0;

private int hooked = 0;

private CachedRowSet crs;

private CachedRowSetDataProvider crsdp;

/** Creates a new instance of WrappedRowSet */

public WrappedCachedRowSetXImpl() {

}

public BaseRow getCurrentRow() throws SQLException {

if( getHooked() == 1 ) { // using the hooked version to update the 2nd sql command with currentRow values of the first sql

if( wrapped == 0) { // to prevent stack overlofwed

wrapped = 1;

String command = super.getCommand();

//String projkey = super.getString(1);

String projectkey = super.getString("PRJ_PROJKEY");

String deppk = super.getString("DEP_PK");

System.out.println("\r\n- -\r\ngetCurrentRow cmd=" + command +", projectkey=" + projectkey + ", deppk = "+ deppk);

if( getCrs() != null) {

command = crs.getCommand();

getCrs().setObject(1, projectkey);

getCrs().setObject(2, deppk);

System.out.println("The hooked crs is for " + command);

crsdp.refresh();

}

wrapped = 0;

}

}

return super.getCurrentRow();

}

public int getHooked() {

return hooked;

}

public void setHooked(int hooked) {

this.hooked = hooked;

}

public CachedRowSet getCrs() {

return crs;

}

public void setCrs(CachedRowSet crs) {

this.crs = crs;

}

public CachedRowSetDataProvider getCrsdp() {

return crsdp;

}

public void setCrsdp(CachedRowSetDataProvider crsdp) {

this.crsdp = crsdp;

}

}

-- code that are used in SessionBean1.java

private void _init() throws Exception {

...

notifiedprojectRowSet.setCrs(projectupdateRowSet);

notifiedprojectRowSet.setHooked(1);

}

private WrappedCachedRowSetXImpl projectupdateRowSet = new WrappedCachedRowSetXImpl();

public CachedRowSetXImpl getProjectupdateRowSet() {

return projectupdateRowSet;

}

public void setProjectupdateRowSet(WrappedCachedRowSetXImpl crsxi) {

this.projectupdateRowSet = crsxi;

}

private WrappedCachedRowSetXImpl notifiedprojectRowSet = new WrappedCachedRowSetXImpl();

public CachedRowSetXImpl getNotifiedprojectRowSet() {

return notifiedprojectRowSet;

}

public void setNotifiedprojectRowSet(WrappedCachedRowSetXImpl crsxi) {

this.notifiedprojectRowSet = crsxi;

}

notifiedprojectRowSet is the rowSet for the outer table

and projectupdateRowSet is for the innter table

vuqphama at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 6
Vu,This is exactly what I need. But I just having trouble to get the code working. Thanks. Jimmy
Jimmy200012a at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...
# 7

Jimmy,

Oopd, I forgor one code line that sets the provider.

((WrappedCachedRowSetXImpl)getValue("#{SessionBean1.notifiedprojectRowSet}")).s etCrsdp(projectupdateDataProvider);

Anyway, I just made a sample which is clearer with only one wrapped class of CachedRowSet and all the debug codes are got rid of.

This sample uses the two tables Departments and Employees of the HR schema of Oracle database. The outside table is the department name, and the inside table is the first name/last name of the people of a given department.

You can download the sample here

http://pluto.sivell.com/~vu/netbeans/nestedtables.tar.gz

There is a very short readme.txt which explains which code you may need to look at.

HTH,

Vu

vuqphama at 2007-7-10 2:41:48 > top of Java-index,Development Tools,Java Tools...