• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A solution to DynaActionForm arrays

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I've been researching how to handle arrays in DynaActionForms. In other words, situations where you need an array or list to represent rows of data on the screen and most especially when you don't know how any entries will be on the page. I looked around the web and found all sorts of hacks to get around the problem that struts does not initialise the arrays. Some people advocated inserting extra actions, loading stuff into session and all sorts of things. All of which sounded problematic, labour intensive and not really addressing the problem (No insults intended).

So I had a look at the struts code and came up with the following extension to the DynaActionForm. So far I've tested it using definitions of both a String array and LinkedList in my struts-config.xml and they have worked perfectly without requiring any extra actions or code to set them up. This version of the form basically extends arrays and lists on demand as the framework loads the data. Missing entries such as indexes 4 and 5 in my sample jsp are left as nulls.

Any comments welcome. I don't think I've doubled on anyones work, but let me know as I searched for solutions like this but didn't find any.



Sample struts-config.xml:



And a sample Jsp page:



And finally a sample action:


[ August 29, 2005: Message edited by: Derek Clarkson ]
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this link.

http://wiki.apache.org/struts/StrutsCatalogLazyList?highlight=%28lazy%29
 
Derek Clarkson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhh, the LazyDynaBean looks exactly like what I was looking for. But I cannote get it to work. I replaced my custom DynaForm with the LazyDynaBean but it keeps throwing errors at me I cannot figure out. The latest I got was after including the commons validator jar which it seemed to be looking for. Now I just get


Which means nothing to me. It's obviously something to do with the setup of the validator. But I'm not using it so I cannot see what it is looking for.

Any ideas ?

ciao
Derek

[ August 29, 2005: Message edited by: Derek Clarkson ]
[ August 29, 2005: Message edited by: Derek Clarkson ]
 
Derek Clarkson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok got it working. I had to figure out the validator first which I had not used before or included in any projects. What a pain. It's real good and throwing out all sorts of vague messages that make no sense at all. But to summarise, the LazyDynaBean solution in the document looks good and as stated is a drop in replacement for the standard DynaActionForm Providing you have Validator Active !. However what it doesn't state is that in order to use this solution you also have to now amend the validation.xml every time you want to create a form that can handle arrays and lists.

Personally I'm wondering if this is over kill. I won't know until I investigate the Validator a bit more and decide if it's worthwhile or just the made creation of some engineer with no real world experience. I say this because sometimes the effort required to maintain solutions which break things up this much can be worse that coding it directly. Especially as projects get larger.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic