You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel Jue <te...@gmail.com> on 2006/10/19 00:50:45 UTC

Complex Bindings with Contrib Table

I have a POJO that has a Map object in it.  Inside the map are a bunch
of properties I'd like to display, which are strings and ints.

What I am trying to get around is having to construct getters and
setters for all the properties, but I still want to use the Contrib
Table.  (the quantity and names of the properties in the Map are
dynamic, loaded from a DB.)

Usually, it's accessed like this:
mypojo.mymap.get("SomePropertyX");

So a getter in my POJO would look like:

String getSomepropertyX()
{
   //type safety ftw!
   return (String) mypojo.mymap.get("SomePropertyX");
}

The table would have columns of "Property Name" and "Property Value"


So how would this be completed in my page spec? :

    <component id="table" type="Contrib:Table">
        <binding name="source" value="mypojo"/>
        <binding name="columns" value="?????????1, ????????2"/>
        <binding name="columnsClass" value="literal:title"/>
        <binding name="pageSize" value="10"/>
    </component>
    <component id="?????????????" type="Block"/>
    <component id="?????????" type="Insert">
         <binding name="value" value="components.table.tableRow.????????2"/>
    </component>


Thanks for any help,
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Complex Bindings with Contrib Table

Posted by Daniel Jue <te...@gmail.com>.
Dom,

This is working great!  Following your example helped me to better
understand the table component too.

Specifically, it never occurred to me that I could generate the string
for the table columns in the class file like this:

public String getTableColumns()
{	//Column id:Column Title:ognl expression
	//value="literal:id, firstName:First
name:name.firstName,lastName:name.lastName, telNo"/>
return "data0:ID:getUserDetails('USERGUID'),data1:Email:getUserDetails('EMAIL'),data2:First
Name:getUserDetails('FIRSTNAME'),data3:Last
Name:getUserDetails('LASTNAME')";
}

Here is my page spec:

    <component id="table" type="Contrib:Table">
        <binding name="source" value="users"/>
        <binding name="columns" value="tableColumns"/>
        <binding name="columnsClass" value="literal:title"/>
        <binding name="pageSize" value="10"/>
    </component>

    <component id="data1ColumnValue" type="Block"/>

	<component id="emailLink" type="DirectLink">
	<binding name="listener" value="listener:onShowDetails"/>
	<binding name="parameters"
value="components.table.tableRow.getUserDetails('EMAIL')"/>
	</component>

    <component id="emailLinkDisplay" type="Insert">
	<binding name="value"
value="components.table.tableRow.getUserDetails('EMAIL')"/>
	</component>

and my html:

<table border="1" jwcid="table">
<tr>
<th>id</th><th>email</th>
</tr>
<tr>
<td>1</td>
<td jwcid="data1ColumnValue">
<a href="" jwcid="emailLink">
<span jwcid="emailLinkDisplay">email@address.com</span>
</a></td></tr></table>

I am really liking the results, but I feel like I am violating the MVC
separation.  I think that is because my keys (like "LASTNAME") are the
column names I read from a db table's metadata (part of the model).

I guess I am wanting the best of both: MVC separation and not having
to write redundant code to access all the parts of the model.  At the
moment I am not using an ORM to create accessor methods for me, so
that's why I am using a map with db columns (grabbed via metadata
commands) as the keys.

This is kinda OT for Tapestry, but do you think this is violating MVC?

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Complex Bindings with Contrib Table

Posted by Dom Couldwell <do...@db.com>.
I did something recently that might be of use, it was not pretty though...

Basically the underlying page returned a list of MarketData objects (POJOs) that each have a method called getMarketData(String key) on them that pulled data from a map
i.e. each Market Data object held a number of pieces of data keyed by Strings.

For the Contrib table definition the definition was:

  <component id="resultsTable" type="Contrib:TableView">
    <binding name="source"   value="ognl:results"/>
    <binding name="columns"  value="ognl:tableColumns"/>
    <binding name="pageSize" value="ognl:pageSize"/>
  </component>

Where the getTableColumns() method on the underlying page returned something like:

data0:displayName1:getMarketDate('key1'),data1:displayName2:getMarketDate('key2'),data2:displayName3:getMarketDate('key3')

e.g.

data0:Mid Price:getMarketDate('Mid_Price'),data1:Mid Yield:getMarketDate('Mid_Yield'),data2:Ask Price:getMarketDate('Ask Price')

And the getResults() method returned a list of the MarketData objects

in the .html I then had something like:

        <td jwcid="data0ColumnValue@Block">
          <span jwcid="@Insert" value="ognl:components.rows.tableRow.getMarketData(keys[0])"></span>
        </td>
        <td jwcid="data1ColumnValue@Block">
          <span jwcid="@Insert" value="ognl:components.rows.tableRow.getMarketData(keys[1])"></span>
        </td>
        <td jwcid="data2ColumnValue@Block">
          <span jwcid="@Insert" value="ognl:components.rows.tableRow.getMarketData(keys[2])"></span>
        </td>

This is a simplified version as the original had a lot more junk...

the getKeys method returns a list of Strings that corresponds to the keys used to build up the original tableColumns list

You can have as many of the above Block definitions as you like to cater for up to the maximum number of columns of data you want to show but they will only be rendered for the number of columns that you declare in your table columns.

As I said it's not pretty but it did work... I did try to get it to render the above blocks in a For loop but could not work out how to generate them dynamically.

I should also point out that I'm relatively new to Tapestry so there may be others with far better solutions. In the end I also binned the Contrib table and did it myself which made for much neater code.

Dom



                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
             "Daniel Jue" <te...@gmail.com>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
             10/18/2006 06:50 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           To 
                                                                                                                                                                                                                                                                                                                                                                                                                        "Tapestry users" <us...@tapestry.apache.org>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           cc 
                                                                                                                                                                                                     Please respond to                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                        "Tapestry users" <us...@tapestry.apache.org>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Subject 
                                                                                                                                                                                                                                                                                                                                                                                                                        Complex Bindings with Contrib Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              




I have a POJO that has a Map object in it.  Inside the map are a bunch
of properties I'd like to display, which are strings and ints.

What I am trying to get around is having to construct getters and
setters for all the properties, but I still want to use the Contrib
Table.  (the quantity and names of the properties in the Map are
dynamic, loaded from a DB.)

Usually, it's accessed like this:
mypojo.mymap.get("SomePropertyX");

So a getter in my POJO would look like:

String getSomepropertyX()
{
   //type safety ftw!
   return (String) mypojo.mymap.get("SomePropertyX");
}

The table would have columns of "Property Name" and "Property Value"


So how would this be completed in my page spec? :

    <component id="table" type="Contrib:Table">
        <binding name="source" value="mypojo"/>
        <binding name="columns" value="?????????1, ????????2"/>
        <binding name="columnsClass" value="literal:title"/>
        <binding name="pageSize" value="10"/>
    </component>
    <component id="?????????????" type="Block"/>
    <component id="?????????" type="Insert">
         <binding name="value" value="components.table.tableRow.????????2"/>
    </component>


Thanks for any help,
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org




--
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org