Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Transferring table data using struts

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a form bean EmployeeFormBean which contains the information for a particular employee .

In my JSP there is a table with variable no of rows each row representing one employee details

Using an "Add Row " button users can add a new row in the table and fill in the details of the employee.

After entring data for n no of employees in the table the form is submitted

My question , how do i transfer this information of a collection of employee
form beans.

I cant use nested beans since the no of rows in the table can be known only at run time and I need to create a new row each time the user presses "Add Row"

Currently I have only figured out how to dynamically create the table (using regular html elements not struts elements using functions like document.createElement ).
But even then how do i transfer this info to action class

Will be really grateful for any sort of hints/tips/solutions

Thanks
Shiva
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done something like this before...

I used an IFRAME, when someone changed something I would change the src of the IFRAME to point to a new page, the same page actually, just with a query string appended with all the input variables. The browser will not refresh or jump to the top of the page. All the user will see is the load animation (which will not last long since the requested page will contain nothing)
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another possible solution:
  • The first time the table is displayed, retrieve the information from the datbase, put it in the form bean, and forward to the jsp.
  • use indexed properties to display the table in the jsp.
  • have your "add row" button change the action of the form to an AddRowAction and submit the form
  • The AddRowAction will add a new blank employee object to the list of objects in the form bean and redisplay the jsp.
  • When the user presses the submit button, Struts will be able to process the changes in the List of Employees in the form bean.

  •  
    shiva viswanathan
    Ranch Hand
    Posts: 152
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HI Kerry / Merrill,

    Thanks you very much for giving me some possible solutions

    However , i want a solution which can be done without going back to the server

    I want something if possible using javascript itself but to create struts elements dynamically .

    Basically i dont want to go to server since the user has not committed the data until he creates all the table data and submits the form

    Thanks
    Shiva
     
    Kerry Wilson
    Ranch Hand
    Posts: 254
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Perhaps you could somehow encrypt the information into a single field using javascript, then decrypt when it reaches the server. Other than that you could probably create hidden fields on the fly (name1,name2,value1,value2).

    If I weren't going to use the IFRAME solution I would probably figure out a way to encrypt the data in a single field. As I think the hidden fields would probably be a lot messier.

    You could use a common encryption algorithm like md5, though I don't know if that is available in javascript. What type of data are you capturing?
     
    shiva viswanathan
    Ranch Hand
    Posts: 152
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Kerry

    I have found a much better approach using indexed properties of javabeans
    in struts.

    Using this property it is possible to submit multiple instances of the same
    actionform (ie multiple rows of data )in a single submit.

    Will you know once I get the right procedure

    Thanks
    Shiva
     
    Kerry Wilson
    Ranch Hand
    Posts: 254
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I do not doubt that it is possible to accomplish this on the server side, what I am wondering is how it will work in the browser and be presented to the user. IMO, that is the most difficult part of the problem.
     
    shiva viswanathan
    Ranch Hand
    Posts: 152
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HI Kerry

    No it will not be on the server side . It will be on the client side itself

    There will be a button on the page something like "Add Row" which the user can press to add another row of details .


    Thus in my page i will dynamially create a new row which is possible using
    javascript .

    Only thing i have to make sure is that the new text boxes created have the correct name corresponding to the indexed property of the java bean so that the data can be transferred once the submit button is pressed

    Hey , and good news .
    Its working
    I need some time to consolidate the complete code
    I will then post it .

    Thanks
    Shiva
     
    reply
      Bookmark Topic Watch Topic
    • New Topic