• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Database grid tag

Posts: 12
  • 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.
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic