aspose file tools*
The moose likes JSF and the fly likes Database grid tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Database grid tag" Watch "Database grid tag" New topic
Author

Database grid tag

Don Horrell
Greenhorn

Joined: Oct 29, 2004
Posts: 4
I'm trying to write a custom JSF tag that takes a database table name as a parameter.
The tag needs to work out the structure of the database table and display the data in the table as a set of rows containing the fields in the database.

So, I've crated DatabaseGridTag, which extends UIComponentELTag and is configured to create a UIInputDatabaseGrid (which extends UIData).
DatabaseGridTag dynamically works out the structure of the database table and creates UIOuput objects for each column of the table.
The DatabaseGridTag works fine at displaying all the rows and columns, but when I try to add a UICommand to display an "Update" button, the button is displayed, but the command does not call the handler. There's no error, but it does not call my CompanyGroupHandler.update().


protected void addFields(UIInputDatabaseGrid grid, CompanyGroupHandler handler)
{
FacesContext context = getFacesContext();
boolean updateable = true;

try
{
// Setup the columns etc.
List cmds = new JdbcHelper().getMetaData(tableName);
Iterator it = cmds.iterator();
while(it.hasNext())
{
// Create a column & add to the grid.
ColumnMetaData cmd = (ColumnMetaData)(it.next());
UIColumn column = new UIColumn();
UIOutput header1 = new UIOutput();
String columnLabel = getColumnLabel(cmd);
header1.setValue(columnLabel);
column.setHeader(header1);
grid.getChildren().add(column);

// Create an input & add to the column. Value binding gets the value from the map - key is columnLabel.
UIInput input = new UIInput();
ValueBinding vb = context.getApplication().createValueBinding("#{" + var + "." + columnLabel + "}");
input.setValueBinding("value", vb);
column.getChildren().add(input);
}

// Add update button, if req.
if(updateable)
{
// ??? This bit displays the button, but clicking it does not work!!!
UIColumn column = new UIColumn();
grid.getChildren().add(column);
UICommand command = (UICommand)(context.getApplication().createComponent("javax.faces.Command"));
column.getChildren().add(command);
command.setRendererType("javax.faces.Button");
MethodBinding mb = context.getApplication().createMethodBinding("#{companyGroupHandler.update}", null);
if(mb == null)
{
LOGGER.error("DatabaseGridTag.addFields() : Null methodBinding.");
}
command.setAction(mb);
command.setValue("Update");
}


}
catch(DAOException e)
{
LOGGER.error("DatabaseGridTag.addFields() : DAOE " + e);
}
}



So, how do I dynamically create the "Update" button and bind it to the CompanyGroupsHandler.update() method?
Where should I call my addFields() method from - the Tag's setProperties() method, doStartTag()...?


I've tried lots of different ways of creating the MethodBinding, but noneof them work.


Any help appreciated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database grid tag