• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database grid tag  RSS feed

Don Horrell
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;

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

// 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);

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

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!