• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form-bean with DynaValidatorForm

 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

in the struts-config.xml file the tage <form-bean> is used
for eg

<form-bean name="testTableForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="addButton" type="java.lang.String"/>
<form-property name="saveButton" type="java.lang.String"/>
<form-property name="deleteButton" type="java.lang.String"/>
</form-bean>

here form-bean definition which i got is....
When a user clicks the Submit button on an HTML form built with Struts, the data from that form is populated into a Java bean called a form bean

so in form-bean(<form-bean name="testTableForm") are we giving the name
"testTableForm" name as javabean name or its just a from name defined in a JSP?

And is it mandatory to define a formbean in struts where we need to do get and set(or its ok if i don't define a FormBean)?

I may be wrong here while asking this question so anyone can just explain the use of <form-bean>

thanks in Advance
Anurag
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

so in form-bean(<form-bean name="testTableForm") are we giving the name
"testTableForm" name as javabean name or its just a from name defined in a JSP?

In your struts-config.xml, you have define the a dyna form named testTableForm. But you also need to specify, which ACTION you want the form to be served, so, you need:




And is it mandatory to define a formbean in struts where we need to do get and set(or its ok if i don't define a FormBean)?

For DynaForm, if you dont have your own FormBean class, you can use:

to set values into the DynaForm, and you can use:

to get values from the DynaForm.

Thus, without getters and setters, and the *real* Form object, you can still do the get/set.

Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot edit the topmost part, so I post it here:

In your struts-config.xml, you have defined the a dyna form named testTableForm. But you also need to specify, which ACTION you want the form to be served, so, you need:


In this case, when your JSP, say testTableForm0.jsp, contains an action that named "testTableAction", the data inside the JSP (if specified correctly using Struts Tags) will be copied into the DynaForm, and the corresponding method() will be called to process this request with the dyna form.

Nick
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicholas ,

Thanks a lot for your reply it cleared a lot for me,

I have a question what we get when we set JSP form properties
in Dyna form, how does this validate the form fields?

pls reply.

thanks
Anurag
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a question what we get when we set JSP form properties
in Dyna form,

The Struts engine will put the corresponding value of the variables into the Sturts by the DynaForm's getter and setter method:

You need not to do anything, all these actions are performed by the Struts engine.


how does this validate the form fields?

As you can see the <action> tag, the value of the attribute validate must be set to true!


By doing so, the validate(ActionMapping mapping, HttpServletRequest request) method will be called automatically by the Struts engine.

And, all checking logics are located inside this method.



In such case, if the errors contains elements, the Struts engine will redirect the request back to the caller page, and you can see the errors inside ActionErrors.

Nick
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic