[
https://issues.apache.org/jira/browse/CLK-94?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Malcolm Edgar closed CLK-94.
----------------------------
Resolution: Won't Fix
This code would be better in Click Examples as an example rather than in
ClickUtils.
> Add a Map transpose method to net.sf.click.util
> -----------------------------------------------
>
> Key: CLK-94
> URL: https://issues.apache.org/jira/browse/CLK-94
> Project: Click
> Issue Type: Improvement
> Components: core
> Environment: net.sf.click.util
> Reporter: J.F. Zarama
> Assignee: Malcolm Edgar
> Priority: Minor
>
> I find a List of Map objects a generic way to navigate through database
> tables and to present data for dynamic SQL using the modified Table and
> Column classes which will be included in Click 0.20.
> The Columns are generated dinamically and, in my case, using the order
> implied in the SQL Select statement, I use iBatis O/R/DAO, 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 );
> }
> addControl(table);
> }
> The Dao uses LinkedHashMap to reflect the order of coliumns as included in
> the SQL Select statement.
> Once a row object, a Map, is selected, it can be displayed using the Table
> control. I use the transpose method shown below to use Table to present two
> columns, name and value pairs, for each entry in the Map object.
> This transpose method I use in an onViewClick() method, as shown below.
> Request: consider adding a Table transpose( Map M,String tn,String ts )
> utility method to net.sf.click.util.
> public boolean onViewClick() {
> String no = getContext().getRequest().getParameter("value");
> Map recipe = getRecipe(no);
> addControl( transpose( recipe,"detail","simple" ) );
> return true;
> }
> private static Table transpose( Map M,String tn,String ts ) {
> Table t1 = new Table( tn );
> t1.setAttribute("class", ts);
> t1.setShowBanner(false);
> Column col = new Column( "name" );
> col.setHeaderTitle("<br/>");
> //col.setAttribute("style", "{font-weight:bolder;}");
> col.setDecorator(new Decorator() {
> public String render(Object row, Context context) {
> java.util.Map C = (java.util.Map) row;
> String name = String.valueOf( C.get("name") );
> name = capitalize(name);
> return "<b>" + name + "</b>";
> }
> });
> t1.addColumn( col );
> col = new Column( "value" );
> col.setHeaderTitle("<br/>");
> t1.addColumn( col );
> java.util.List Y = new java.util.ArrayList();
> for(Iterator c = M.keySet().iterator();c.hasNext();) {
> String key = c.next().toString();
> Object value = (Object) M.get( key );
> Map D = new LinkedHashMap();
> D.put("name",key.toLowerCase());
> D.put("value",value);
> Y.add( D );
> }
> t1.setRowList( Y );
> return t1;
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.