• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

can't get indexed form property to work.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I've looked at the FAQ and it seems like I should be able to solve this from there, but I'm still struggling to get it to work.

I can't get my input fields to show when first loading my submit page.

I have the following form:
Main Form: SubmitForm, it's a large form with an indexed property in it that I can't get to work:



(it has the appropriate getter/setters)



(with appropriate getters/setters
struts-config.xml:



JSP: - as you can see, i've tried both forEach and iterate.



Neither seems to populate the initial table in the jsp to 5 rows. The iterate doesn't find anything to iterate over.

Any suggestions?
Thanks
[ December 31, 2008: Message edited by: Brian Harper ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Twivel", please check your private messages for an important administrative matter.
 
Brian Harper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be a bit clearer on my problem: The jsp compiles fine, the page displays, no errors show up in the log, it just doesn't populate the empty text fields in the jsp.

I suspect this is because there is no data in SubmitForm.ingredients because it hasn't been filled out yet, but I expected having size="5" in the <form-bean> tag would cause it to show 5 empty rows.

Clearly, I don't have something configured right.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code looks good to me, Just some changes/doubts,

1. Change JSP code name attribute , like


I changed the name attribute, because the the mapping of name in form-bean tag is


2. Are you using DynaActionForm ? Because you declared form-property element in your form-bean tag

 
Brian Harper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I changed the name and am still having the same issue... the iterator does nothing. I think your second comment is the cause. I guess I was just confused about when to use the form-property tag, I don't use DynaActionForm.

My flow is as follows:

1. Action /submit.do is a forward to submit.jsp without an action type.
2. Clicking submit does onsubmit validation and calls a different action: /submitAction.do to do server side validation and processing - and this does have an action type.

I have two actions because I don't want validation (and the associated errors) with showing the form the first time. Perhaps there is a better approach to this?

So without using a DynaActionForm, I guess I need to have a different action associated with 1 that pre-populates the form so the rows show up.... off to try it now.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Harper:
I guess I was just confused about when to use the form-property tag, I don't use DynaActionForm.



This is what struts-config_1_2.dtd says about "form-property" element:

The "form-property" element describes a JavaBean property that can be used to configure an instance of a DynaActionForm or a subclass thereof. This element is only utilized when the "type" attribute of the enclosing form-bean" element is [org.apache.struts.action.DynaActionForm] or a subclass of DynaActionForm. If a custom DynaActionForm subclass is used, then the "dynamic" attribute of the enclosing <form-bean> element must be set to "true". Since Struts 1.1.



So If you are not using DynaActionForm, then remove that element.

1. Action /submit.do is a forward to submit.jsp without an action type.



Now, While forwarding to JSP page on which you are iterating , then simply add the name of "bean" in action mapping tag..
like

<action .. name="submitForm"/>

A question : Any special reason to use array of size 5(You can show 5 empty rows by iterating 5 times), If no, then have look at this FAQ, It might help !!
 
Brian Harper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got it working now, I stopped using the array example and followed the FAQ exactly. I had looked at it before, but I was still working off of a different example that used an array.

And I guess you're right, it makes more sense to just iterate in the JSP if the List is empty than to add empty elements to the list.

I'd also like to expand the list dynamically without submitting.... (e.g. add another row by clicking a button). this seems to help with that, I just need to figure out how to get the last index so I can increment it. Any tips on that?

Thanks for the help.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Harper:
I just need to figure out how to get the last index so I can increment it. Any tips on that?



Why you required last index position ?

Still, <logic:iterate has "indexId" attribute which holds the current index of the collection on each iteration.

Look here.
 
Brian Harper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sagar Rohankar:

Why you required last index position ?


My current thoughts are:

On the server side, I will iterate over the collection and create the initial table and one empty row.

Then, on the client side I want to provide a button that allows them to
add more rows after they fill in the empty one. I can use javascript but take a look at the following example:



In the above code, javascript innerHTML will have to know the last X used so it can increment it.

Thanks for your help!
 
Brian Harper
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've figured out how to answer the number of rows in the table question.

 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm happy to help you
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic