• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Handle Exceptions errors in Struts Form

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having to get database information to initialize the Form values in the loadForm method. One such method throws an exception. How do I handle errors to be displayed when the form is being initialized?

[I recognize that having the Form throw an exception for the calling action class to catch is ONE answer, is there another way?]

Struts provides the ActionErrors/ActionMessages for the Action class, but what structure exists for the Form class of Struts?

Below is a VERY skeletal representation of what I am facing:

public class TestForm extends ActionForm
{
ArrayList states;

public TestForm loadForm()
{
states=new ArrayList();
states=someDBmethodCall();
}
}
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead You could try keeping the Actionform 'dumb' and using a setup Action instead. You can have an ActionForm associated with multiple Actions, so basically, you create an action whose job is to populate the Form with the data you require.

By calling database code from your Actionforms, you're coupling your View very tightly to the data access code, which (in my opinion) is detail it needn't know about.

Does that help at all?
 
JD Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,

Thanks tons for your input!! That is a great suggestion and I will pass it on to the rest of the project team.

Merry Christmas!!!

JD
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Daniel's suggestion. Your Action should be the bridge between your form and your data or business tier. I would not make database calls directly in a form.

- Brent
reply
    Bookmark Topic Watch Topic
  • New Topic