Click
  1. Click
  2. CLK-91

Table to support java,util.Map

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      Table/Column control

      Description

      Often a domain object is unnecessary and java.util.Map is a generalized way to describe Table columns and rows.

      So a List of java.util.Map objects is a convenient generalized model resulting from a List Dao.getAll() type of methods.

      Currently one needs code like the one below for each Colum object of a Table control to us a List of Map objects.

      col = new Column("NAME");
      col.setHeaderTitle("name");
      table.addColumn(col);
      col.setDecorator(new Decorator() {
      public String render(Object row, Context context)

      { java.util.Map M = (java.util.Map) row; return M.get("NAME").toString(); }

      });

      Request. Provide support for a List of java.util.Map objects as a data source for the Table control.

        Activity

        Hide
        Malcolm Edgar added a comment -

        Changes checked into SVN, will be available in release 0.20

        Show
        Malcolm Edgar added a comment - Changes checked into SVN, will be available in release 0.20
        Hide
        J.F. Zarama added a comment -

        I tried the new Column.java class.

        It does require a change to Table.java at 758 from

        column.renderTableData( row, buffer, context ); to
        column.renderTableData ( j, row, buffer, context );

        Once this is done, the Data source for a Table, in the form of a List of Map objects, each Map representing a row with variables (columns) as Map keys works very well.

        In my case I use iBatis for DAO/O/R and it is configured to return a List of LikedHasMap rows with keys respecting the order of the Select statement.

        Therefore the rendered table will have 3-columns, No, Name, Description, and in the same order as in the Select statement:

        Select No, Name, Description From Products Where ...

        With this approach I am able to have a generic Table rendering as follows:

        public void onGet() {
        List R = this.dao.getAll();
        java.util.Map C = (java.util.Map) R.get(0);
        for(Iterator c = C.keySet().iterator();c.hasNext()

        { String key = c.next().toString().toLowerCase(); Column col = new Column( key ); this.table.addColumn( col ); }

        this.table.setRowList(R);
        GenHtml gh = new GenHtml();
        gh.addLink("/zMenu/click/table.css","text/css", "stylesheet" );
        gh.add( table.toString() );
        addModel("zMain", gh.getHtml() );
        }

        I think this functionality may be of interest to Click users.

        I look forward to have the updated Column.java and Table.java in the next release of Click; thanks;

        Show
        J.F. Zarama added a comment - I tried the new Column.java class. It does require a change to Table.java at 758 from column.renderTableData( row, buffer, context ); to column.renderTableData ( j, row, buffer, context ); Once this is done, the Data source for a Table, in the form of a List of Map objects, each Map representing a row with variables (columns) as Map keys works very well. In my case I use iBatis for DAO/O/R and it is configured to return a List of LikedHasMap rows with keys respecting the order of the Select statement. Therefore the rendered table will have 3-columns, No, Name, Description, and in the same order as in the Select statement: Select No, Name, Description From Products Where ... With this approach I am able to have a generic Table rendering as follows: public void onGet() { List R = this.dao.getAll(); java.util.Map C = (java.util.Map) R.get(0); for(Iterator c = C.keySet().iterator();c.hasNext() { String key = c.next().toString().toLowerCase(); Column col = new Column( key ); this.table.addColumn( col ); } this.table.setRowList(R); GenHtml gh = new GenHtml(); gh.addLink("/zMenu/click/table.css","text/css", "stylesheet" ); gh.add( table.toString() ); addModel("zMain", gh.getHtml() ); } I think this functionality may be of interest to Click users. I look forward to have the updated Column.java and Table.java in the next release of Click; thanks;
        Hide
        Malcolm Edgar added a comment -

        This request sounds pretty useful.

        The attached Column class extends the getProperty() method to support Map row objects, could you please test this class to see if it meets your needs.

        regards Malcolm Edgar

        Show
        Malcolm Edgar added a comment - This request sounds pretty useful. The attached Column class extends the getProperty() method to support Map row objects, could you please test this class to see if it meets your needs. regards Malcolm Edgar

          People

          • Assignee:
            Malcolm Edgar
            Reporter:
            J.F. Zarama
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development