File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes setting values from action class into table UI... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "setting values from action class into table UI..." Watch "setting values from action class into table UI..." New topic
Author

setting values from action class into table UI...

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I have an object containing values to be persisted in table UI...

The table contains only header as it is dynamic,The row count depends on the DB...

The values in action class are obtained from the DB and I need to get the row values into table and this is to be done in Javascript call made onLoad...

How to achieve this? Or is there any other way?
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
You could have an action that outputs only the table data in whatever format is convenient for you (json, xml, etc.) and send an AJAX request to it from JS.


OCJP 6 (93%)
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Lorand can you elaborate... I din't absorb that completely. You meant (<body onLoad =callAjax()) Ajax call that gets values from action class and set them in your Javascript generated table???

Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
I asumed that by a javascript call you meant an AJAX request...

You could give us a bit more information on this "javascript call" and the need for it!
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I mean I have a JSP with a table containing only a header


The rest of the rows are to be obtained from from the action class and set them in the table...

There are two things to be done here in same jsp...

1) If data is present in DB then I already have an object containing values for table...I just need to put them onto UI but it's linked with 2

2) if there are no data on DB i need to add rows here...so I used a JS to add rows dynamically to UI and DB(this is done)

My problem is with 1 here .I already have a JS to add rows to table... Now am confused how to put the data obtained from DB to table without disturbing the flow!
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
You can add the rows with the data from the DB on the server side, no need for JS, just put the row data in a Collection, add a getter for it in your action class, iterate over it in the JSP and output the rows! Which version of Struts are you using?
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
am using Struts-2... s:iterator would do rite?

Do you think i need a session?
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Pradeep Adibatla wrote:s:iterator would do rite?


Rite.

Pradeep Adibatla wrote:
Do you think i need a session?


No, s:iterator can access the action class through the value stack, just add a getter that returns the Collection with the row data!
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Thanks... I would get back to even greater detail if it doesn't work... struggling with struts and JS and their combo
 
 
subject: setting values from action class into table UI...
 
Similar Threads
how to pass cell values(td) as hidden things to Action class(struts-2)?
struts.xml doubt (Action classes,struts-2)
Action class doubt(submit,button type)
using OGNL
Problem with selected checkbox value in struts 1.2