aspose file tools*
The moose likes Struts and the fly likes [+] Button to add newly line of information on the jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[+] Button to add newly line of information on the jsp page" Watch "[+] Button to add newly line of information on the jsp page" New topic
Author

[+] Button to add newly line of information on the jsp page

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
hi there,

my familyForm has the following properties:
String fname;
String lname;
String dob;

since every family has different size I thought of having a [+] button where the end-user can click and have a newly line of info.

example

fname [............] lname [...............] dob [...............]
[+]


assuming the end-user provided some info and clicked the [+] button, the 'newly' page would look like this:

fname [Warren .....] lname [Buffet .......] dob [8/30/1930 .....]
fname [............] lname [...............] dob [...............]
[+]


Question:
1. What should be in the action of the [+] button?
2. How would the jsp 'create' a new line and place in the right spot?

thanks for any thoughts
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
I'd choose either one of these ways to accomplish what you want:

1) Use javascript to create a new line each time the [+] is pressed. You can use indexed properties on the back end to save everything when the form is submitted.

2) You can do a submittal each time the [+] is pressed and forward to the same jsp each time with 1 data entry row on it.

3) When they hit the [+] button, just forward to a new screen where they can enter the data, and when they submit return to the original page.

There are pros and cons of each one, but I like #3 the best because it doesn't require javascript and is easiest to set up/maintain (for me at least). It might not be fancy but it is easy and probably what the user expects.

Another option is AJAX which I try to avoid completely.
[ October 30, 2006: Message edited by: Dom Lassy ]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
ok, so first thing is done.
I manged to create an input text (javaScript) with the [+] button and it looks like this:



the call is made with:


BUT:
1. how can I insert a bean property to jscript??? I tried:

nothing

2. what if I have an array (arrayList) of travelers, how do I call them in the property, I mean traveler is only for ONE traveler (and I need travelerS)? traveler.fname[x]???

thanks for any suggestions.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will need to use indexed properties for this. I'd suggest you carefully read the following 2 articles on indexed properties:

http://struts.apache.org/1.2.9/faqs/indexedprops.html
http://wiki.apache.org/struts/StrutsCatalogLazyList

Let us know if you have trouble applying these principles to your specific situation.


Merrill
Consultant, Sima Solutions
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
First, they have an error in all of the examples.
As you can see, the constructor's name is not the same as the class's name.



Second, being less pedantic , I realize I need to create a collection of objects (in my case userList) so when the submit button is pressed, I can retrieve the userList and iterate each user.

But I'm not sure how to increase the size of the userList every time the [+] button is pressed. I'm still struggling what goes in the javascript in terms of struts tags and how to read it in the
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
One thing to keep in mind is that your JavaScript function is run on the client side inside the browser. JSP code and Struts tags are processed on the server side. Your JavaScript should not render html:text tags. Instead it should create standard HTML input tags of type "text". Look at the source of the html generated for an example. If you get the indexed properties part working you will need to create input tags that look something like:

input type="text" name="traveler[1].fname"

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [+] Button to add newly line of information on the jsp page