Hi Frederic,

thanks for sharing this!

Some people might rip you apart when you call this a component since it doesn't handle any encapsulation of state (which is what happened to me last time on JavaLobby), but anyway.

It's a nice example of the flexibility of RIFE's template engine though.

The main criticism of this approach is that when your table needs to become interactive (like sorting the columns and such), you have to reimplement your 'component'. When using embedded elements, you can just continue to extend the capabilities of it.

Best regards,

Geert

On 07 Jun 2006, at 17:12, [EMAIL PROTECTED] wrote:

Hi dear RIFErs,

I've managed to implement a simple component which I call a "view
component", in the sense that it's not really an Element, just a
reusable unit that renders a view from some data. In this case, it's
an HTML table. My goal was to encapsulate how I display a table of
data in my application, so that it is consistent throughout.

My question to you is, what do you think of this approach? Am I
missing some important issues? Is there a better way of achieving
this? I think this way seems fine but I'm interested in your thoughts
or suggestions.

Say I want to display two tables of data. Ideally, in my template,
I'd want something like:

<p>
Here is a table:
</p>
<r:v name="table1"/>

<p>
Here is another table:
</p>
<r:v name="table2"/>

And, in my Element.processElement():

Table table1 = ...; // create a Table component from some data
Table table2 = ...; // ditto

template.setValue("table1", table1);
template.setValue("table2", table2);

So it is the Table class that is the view component. It has a
Template that could be set by injection (in my example, it is
hardcoded..) This class/template combination takes care of rendering
the HTML table from the supplied data, with any niceties that I
want (even/odd rows, CSS classes..)

So now any time I want to display a table of data, I create an
instance of Table, feed it the data, and place it in my template. The
Table.toString() method returns its template.getContent(), so that it
renders itself.

I didn't see a need to involve Element here, since the Table has no
behavior, data links, exits, etc. It is just a view component.

What you do think? Is this approach good for creating reusable
"view components" in a RIFE application?

Thanks in advance for your thoughts!

Note: if you want to try out the attached sample code, just add
the RIFE jar in the lib/ directory, then run "ant build" from the
root directory. This will build the WAR file in the "dist/"
directory.

Best regards,
Frederic Daoud
--

  [EMAIL PROTECTED]

<rife-view-component-example.zip>
_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users

--
Geert Bevin
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com


_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to