If yes, then you can simply use logic:iterate on the String emails property.
If no, (i.e there is only one text field where the user can enter multiple emails seperated by a comma or some delimiter), then why do u need an String array to store them. It can simply be a string variable. Later on you can use StringTokenizer to identify individual mails.
If you can post your JSP code that wud make the problem more clear.
Leandro, there are two possible solutions that strikes my mind straight away.
1) Scriptlet way. You should check for the length of the array in your jsp page and lay textfields accordingly. If the length is zero/ array is null (may be when the page is rendered first time), then put only one text field. Not so lucid and clean approach, though.
2) Indexed properties way. If you remember my very first post, earlier in the thread on similar topic, I had mentioned use of Indexed properties. Use indexed getter and setter for accessing individual elements and array accessors as you are having them right now. Then you can use Iterator tag for laying as many textfields as you require (refer to myformview.jsp in that thread). To make things easier, you can have your array pre-filled with atleast one element.
Try to work on these lines of thought. You should be able to strike a solid solution for this.
HTH. If you need a code on indexed property, post back. Also see Indexed Properties How-to for indexed properties in struts. It's a good reference document.
Thanks and regards, Kinjal Sonpal [ June 19, 2004: Message edited by: Kinjal Sonpal ]
2 - Yes, it's very nice to keep all control at sever side, but, as i said, i'll let the client (or user) choose how many emails he/she wants to register at one submit (so he/she doesn't get bored to have to register one email, then other email, then other email.... he/she registers all of them at once). So, i don't see how could i monitor that at server side, because i won't be able to know how many emails the user would like to register.
Well, i'd appreciate if you comment a little on the above said.
Thanks and regards, ltcmelo
Joined: Jun 06, 2003
Leandro, here's answer to your first question.
I'll try to put things step by step. Note that the following code is not tested and executed, and is based on my understanding of the current context and iterator tag. However, I've extensively used a similar code in my project with great success and consistency.
MyForm.java ----------- MyForm.jsp (The email form) --------------------------- Here, we'd lay the controls using iterator tag. This'll allow proper re-rendering the controls if the validations fail. As explained in my earlier post, when the page is rendered for the first time, this may not render any control if the array is empty. So prepopulating the array with a dummy value will allow to render only one textfield.
If you require a readonly view of the form before final submission occurs, just replace <html: text> with <bean: write>, as explained in my post on the earlier thread.
One more thing. To the best of my knowledge, to make indexed properties go smoothly, the value of the id attribute in the iterate tag should match the indexed property in the form-bean. And the value of the property attribute should match the array accessor in form-bean. I've made the text bold for your easy understanding.
I hope I've not missed out any major detail. Please post back the results.
Thanks and regards, Kinjal Sonpal [ June 21, 2004: Message edited by: Kinjal Sonpal ]
Joined: Jun 06, 2003
And here goes the second answer.
So, i don't see how could i monitor that at server side, because i won't be able to know how many emails the user would like to register.
That's true. You can't directly monitor the things at server-side, and that's what I was trying to suggest. And this where I get uncomfortable. May be I'm too conservative in my thinking about the security in the web world.
1) Ask the user in the beginning, the number of lines to add, pass it on using a form submission, and then present the user with those many lines to edit. OR 2) Provide the user with only one line at a time, giving add button to add one more line and submit the form. When the form is presented again, the previous lines are shown read-only and one more line is shown editable. This is similar to adding attachments to mail on most web based email services. OR 3) Provide the user with some pre-determined(3-4 could be okay) number of editable lines. Then follow approach 2. This could allow you to save an additonal form submission on most occassion. However you should remember that even in this case you should not hard-code your jsp page for the number of lines. You should still run the iterator code. Let the fronting action decide how many lines it should have prefilled.
Hope this answers your question. There could also be some more approaches or there could be some flaws in the above as well. May be gurus would like to comment on this.
Thanks and regards, Kinjal Sonpal
[ June 21, 2004: Message edited by: Kinjal Sonpal ] [ June 21, 2004: Message edited by: Kinjal Sonpal ]
Joined: Mar 27, 2004
Thanks for your time and attention Kinjal, I'll try those strategies in 1 or 2 days (unfortuantelly, i won't be able to try them out rigth now) and let you know the results.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Workaround for dealing with String inputs