Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database grid tag

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

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.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic