Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handle Exceptions errors in Struts Form

 
JD Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic