tags:

views:

443

answers:

1

Calling All DWR Gurus!

I am currently using reverse Ajax to add data to a table in a web page dynamically.

When I run the following method:

public static void addRows(String tableBdId, String[][] data) {
 Util dwrUtil = new Util(getSessionForPage()); // Get all page sessions
 dwrUtil.addRows(tableBdId, data);
}

The new row gets created in my web page as required.

However, in order to update these newly created values later on the tags need to have an element ID for me to access.

I have had a look at the DWR javadoc and you can specify some additional options see http://directwebremoting.org/dwr/browser/addRows , but this makes little sense to me, the documentation is very sparse.

If anyone could give me a clue as to how I could specify the element id's for the created td elements I would be most grateful. Alternatively if anyone knows of an alternative approach I would be keen to know.

Kind Regards

Karl

A: 

The closest I could get was to pass in some arguments to give the element an id. See below:

    public static void addRows(String tableBdId, String[] data, String rowId) {

 Util dwrUtil = new Util(getSessionForPage()); // Get all page sessions

 // Create the options, which is needed to add a row ID
 String options = "{" +
   "  rowCreator:function(options) {" +
   "    var row = document.createElement(\"tr\");" +
   "     row.setAttribute('id','" + rowId + "'); " +
     "    return row;" +
       "  }," +
   "  cellCreator:function(options) {" +
   "    var td = document.createElement(\"td\");" +
   "    return td;" +
     "  }," +
   "  escapeHtml:true\"}";


 // Wrap the supplied row into an array to match the API
 String[][] args1 = new String[][] { data };
 dwrUtil.addRows(tableBdId, args1, options);
Karl