Hi
Lets see in example
you declare an action in struts-config like this:

<action name="registrationForm" path="/registration" scope="request" type="com.example.struts.action.RegistrationAction" validate="false">
      <forward name="toForm" path="registerForm.jsp" />
 </action>

Now when you access "/registration" url Your Action's class "execute" method will be called. Inside this method you get instance of "registrationForm" ActionForm. Copy needed properties from DB object to this registration form:
Here is code example

public ActionForward execute(ActionMapping actionMapping,
                               ActionForm actionForm,
                               HttpServletRequest request,
                               HttpServletResponse servletResponse) throws
      Exception {
    RegistrationForm registrationForm = (RegistrationForm) actionForm;
BeanUtils.copyProperties(registrationForm , objectFromDB);

// ANd forward to your jsp page
return actionMapping.findForward(toForm);
}

Now if jsp is well formed using Struts tags like <html:text> your form will be populated.

To submit info you can do again actionMapping like "/updateRegistration" and inside execute method copy properties FROM actionForm instance to DB object

This example is just one of many ways to accomplish that

I suggest you to look at this tutorial http://www.learntechnology.net/struts-lesson-1.do
It is very clean and easy to understand tutorial
Cheers.

Andy.de wrote:
Hi Ilja,
i'm using DAO patterns but the question was: how can i init a form inside an
action. I Didn't
find any method to do this and also no example. All struts samples are with
forms to create
new objects and not to edit existing objects.
regards, Andy

Ilja S. wrote:
Hi
Action class is right place.
Common way is to have some layer working with DB like DAO pattern. Then You can have some service layer between DAO and Action which you call from Action class. Call it, get data transfer object from DB, copy its properties to ActionForm instance and forward request to your jsp page with form. Struts will do the rest. That is all.

Andy.de wrote:
Hi folks,
i init my form beans at reset(...) of ActionForm from database but i
think
this is not correct because
if an error occurs i have no chance to forward to an error page or to
save
ActionErrors. I think the
controller must read objects from database and init the form.
All samples are very simple and only with forms for new objects (name="";
street=""; at reset()).
Where is te correct place to init forms from database if i want edit an
existing object and which method must i call????
I'm using Struts 1.2.9

Regads, Andy

--
*************************************
Best Regards
Ilja


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
*************************************
Best Regards
Ilja


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to