This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

A solution to DynaActionForm arrays

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
Derek Clarkson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!