You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pv...@denodo.com on 2008/01/28 22:27:06 UTC

AJAX approach

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 postmaster@denodo.com.
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 postmaster@denodo.com.
Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: AJAX approach

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
>
> I would like to ask you if you know wheter YUI table lets me filter, 
> order by column and paginate the table using AJAX (without refreshing 
> the page) or doing it client-side. I couldn´t take a look to it yet. 
> Sorry.

Yes, all that's possible on the client side with the YUI datatable. I 
use all the above features. 

They have some examples for client-side sorting, pagination and XHR.  
Filtering is performed by via the DataTable's RecordSet API
http://developer.yahoo.com/yui/examples/datatable/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: AJAX approach

Posted by Pablo Vázquez Blázquez <pv...@denodo.com>.
Hi Jeromy,

Thank you very much for your explanation. I know it was a big question.

Well, I liked your suggestion of having a function with 2 timestamps 
(that´s what I had thougth about), but, for "external" reasons, it won´t 
be so.

Now, I will have a controller action that will keep at session scope the 
actual state (the whole collection) and, from client, periodically will 
ask the model for the actual state and match previous state with the new 
one. Then, I will get only the differences between them and convert them 
to a json string, which will be returned by the action. In this json 
string I will have the rows that have changed, including those that have 
been deleted or created, so that I can update the table in the document.

I would like to ask you if you know wheter YUI table lets me filter, 
order by column and paginate the table using AJAX (without refreshing 
the page) or doing it client-side. I couldn´t take a look to it yet. Sorry.

Thanks.


Jeromy Evans escribió:
> 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
>
> pvazquez@denodo.com 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 postmaster@denodo.com.
>> 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 postmaster@denodo.com.
>> Thank you.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: AJAX approach

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
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

pvazquez@denodo.com 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 postmaster@denodo.com.
> 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 postmaster@denodo.com.
> Thank you.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org