• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

List Objects in Form Bean has null values...mostly

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm sure I'm missing something obvious. I've spent tons of time reading about this problem, but I'm stuck. #6 in the Struts FAQ was the most helpful thus far.

I have a form bean with a list of beans. When the save and submit actions I have are executed, the form bean values are all populated correctly except the list. The fields in the list object are all null except the ones that I've defined as textarea elements with indexed="true". I've tried changing the scope from "request" to "session", but no change. I can see this when I put a breakpoint in my validate method.

Here is the relevant code from my Struts 1.1 application. I've tried to trim out the fat. There are actually many more fields in each bean.

struts-config


form bean


list bean


JSP


When I break at my validate method, partNumber will be null and suggestion will be correctly populated. I've also tried many other ways of writing the list fields in the JSP (hidden fields, using property='<%="partNumber["+idx+"]"%>', etc) , but most of them make it so it doesn't render. Please let me know what I'm doing wrong!
Thank you,
Dan
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This chunk of code perplexes me--I'm assuming index is never >= itemList.size(), otherwise wouldn't this loop until the computer melted?

Have to you verified that the indexed textarea is rendering correctly?

Why would partNumber be anything but null? Is there a form field or initialization for partNumber you haven't shown? All I see (with an admittedly hasty overview) is a <bean:write> tag.
 
Dan Keefe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:This chunk of code perplexes me--I'm assuming index is never >= itemList.size(), otherwise wouldn't this loop until the computer melted?

Have to you verified that the indexed textarea is rendering correctly?

Why would partNumber be anything but null? Is there a form field or initialization for partNumber you haven't shown? All I see (with an admittedly hasty overview) is a <bean:write> tag.



The perplexing code is straight from the FAQ:
http://faq.javaranch.com/java/IndexedProperties
I just pasted it in without even looking at it for the sake of solving this issue. :o

The indexed textareas are rendering fine and the attributes are retaining their value. (Indexed text fields work fine too.) I just noticed now that if I add 'disabled="true"', these attributes also are null in the requests.

partNumber and suggestion are both populated via GetRfqAction. partNumber can be "" and suggestion can be null, but they are both populated in the response and visible on the page.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Disabled form fields, IIRC, aren't sent by the browser.

I don't see where the partNumber is being populated, so I won't be able to help much more: in the JSP posted there's just a <bean:write>, so I wouldn't expect that field to be populated on form submission since there's no form element.
 
Dan Keefe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's being populated via GetRfqAction:
I know it's populated via this: BeanUtils.copyProperties(rfqForm, rfqDTO); I've inspected the code with breakpoints and it's also passed correctly to my JSP and displayed.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IIRC copyProperties doesn't do a deep copy (could be wrong about that).

That aside, there's still no form elements for the partNumber, so it wouldn't be set on form submission.
 
Dan Keefe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:IIRC copyProperties doesn't do a deep copy (could be wrong about that).

That aside, there's still no form elements for the partNumber, so it wouldn't be set on form submission.



It does do a deep copy. It has the same effect as rfqForm.setItemList(rfqDTO.getItemList());

I don't know what you're saying regarding no form elements. I'm pretty new to all of this so maybe that's my problem.
If I change my JSP to have:
<html:text name="item" property="partNumber" indexed="true"/>
It is populated correctly.

So let me rephrase my question:
How do I get all of the attributes in my list in my form to be populated without putting them into editable text attributes? partNumber will not be editable on the screen to the user, but I do want the same value passed back when I save/submit. As I said before, it only comes back when I have it in a text-like box. I haven't been successful with hidden elements. Is that what I need to use?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put them in a hidden form element? <bean:write> isn't a form element, it just displays values--when a form is submitted only form elements are submitted, not random text on the page.

FYI, from http://commons.apache.org/beanutils/v1.8.0/apidocs/index.html:

Note that this method is intended to perform a "shallow copy" of the properties and so complex properties (for example, nested ones) will not be copied.

 
Dan Keefe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Put them in a hidden form element? <bean:write> isn't a form element, it just displays values--when a form is submitted only form elements are submitted, not random text on the page.

FYI, from http://commons.apache.org/beanutils/v1.8.0/apidocs/index.html:

Note that this method is intended to perform a "shallow copy" of the properties and so complex properties (for example, nested ones) will not be copied.



I guess I don't know how to put these items in a hidden form element. I've tried:
<html:hidden property="<%="partNumber["+idx+"]"%>" />
and I get:
No getter method for property partNumber[0]

Here is a slimmed down version of my JSP




I did test copyProperties, but I found that it already had copied those properties by the time it hit my rfqForm.setItemList(rfqDTO.getItemList()); statement so I removed that statement. Maybe I'll put it back in given what you've pointed out in the javadoc.

Thanks
 
Dan Keefe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I am just syntactically challenged. I add this to my iterate statement and it works just like I want it to.


Thanks for trying to help, David. :beerchug:
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IIRC the <html:hidden> tag also has an "indexed" attribute, too.
 
You get good luck from rubbing the belly of a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic