Hi,
You're asking a big question. What follows is the approach I would
take. There's many other approaches you could also try and my solution
may be too javascript-centric for you.
First, the interface is stateless, so I'd probably have my action always
accept two timestamp parameters and always output the changes that
occurred between the start timestamp and end timestamp. If the start
timestamp is null you want all data. If the end timestamp is null you
want most recent.
This would simplify the action down to the single responsibility of
providing the difference in the data between the start and end timestamp.
If your data changes against something other than time, such as revision
number, then use that as the arguments.
The table data will need to be decorated with information about the
timestamp/revision.
I would output the data as JSON or XML, not HTML.
The client (javascript) maintains the state for your user. It knows
whether its loaded data yet, the timestamp/revision of the current data
and controls when to get an update (periodically or triggered). I would
use a javascript library that includes an ajax datagrid. That's a fancy
name for a table that can update its data asynchronously. My favourite
is YUI (http://developer.yahoo.com/yui/datatable/) but there are plenty
available.
Whatever the implementation, the datagrid will include a data model that
contains the table data (eg. a RecordSet in YUI) and includes methods
for updating the table model dynamically. If you ever used Swing, they
generally work like Swing's TableModel.
Your responsibility will be to map the changed data into the datagrid's
model. As the current state and data is in memory (eg. in the RecordSet)
and the changed data is available from your action's result (eg. in XML
or a JSON structure) you can iterate through the changes and apply each
them to the model. As the model is changed, the library will update the UI.
Hope that gives you some direction.
regards,
Jeromy Evans
[EMAIL PROTECTED] wrote:
Hi!
I would like to comment you a problem I have now when developing a web
application using Struts 2.
I have a collection of items, which I want to show in a table. Those
items have some attributes that change with the time and I would like
to show the updated state in the view layer. I don´t know very well
how to achieve this. I suppose I must be polling the web server and
getting the whole collection each time, but this collection may be
huge, so I don´t think it would be a nice approach. What I would like
most would be changing only those attributes that changed from the
last polling.
Supposing that I have an action at the model layer that returns me a
collection with only those item that have changed (the first time it
must return me the whole items), (or maybe, I could have 2 actions:
one for ask if sth has changed and another one to retrieve the whole
collection -if sth has changed-), how can I modify the HTML to update
the shown content? Could I convert the item's collection in the
controller action to JSON and retrieve it in the jspx? It is, call
this controller action directly from javascript? Is there an easier
way to do this using Struts2 or do I have to use "AJAX raw"?
To sum up:
controller action -> model action -> returns collection<Item> ->
controller action returns jspx where I draw the table. Now how do I
update this table? The easy way would be using an s:div tag with
href="action" and a timer to update it, but it would involve update
the whole table.
Any help would be grateful.
Thanks.
----------------------------------------------------------------
http://www.denodo.com
Aviso Legal
Este mensaje es solamente para la persona a la que va dirigido.
Sus contenidos y cualquier archivo adjunto son confidenciales.
Si usted lo ha recibido por error, le rogamos que lo borre y
lo notifique a [EMAIL PROTECTED]
Gracias.
Legal Notice
This message is intended for the addressee only and its contents
and any attached files are strictly confidential.
If you have received it in error, please remove this mail and
contact [EMAIL PROTECTED]
Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]