Populating form bean in structs

Discussions

Web tier: servlets, JSP, Web frameworks: Populating form bean in structs

  1. Populating form bean in structs (5 messages)

    Hi, I want to make a page or editing some information. So at the first time I need to load the values from database and display it in the form. So how can I initialize that formbean. I am using these tags in structs-config.xml and Click here so on clicking this link I want to go to the page a.jsp with the values from database. ie I need to initialize the form bean of a.jsp. Thanks in advance

    Threaded Messages (5)

  2. Re: Populating form bean in struts[ Go to top ]

    The only way to do this is to create a specific Action that would get the data to populate from your service layer. This has to be done in the execute() method of your Action. public ActionForward execute(...){ (MyForm) myForm = (MyForm) form ; // some access to service layer ... myForm.setFoo(...) ; return mapping.findFroward(...); } Hope this help.
  3. Take a look into the very good book "Jakarta Struts Live", available for free as ebook here on TSS. The action should look something like this: Than "showData.do" is the URL you call, "ShowDataAction" handles the database operation, and the forward "success" will leed you to the JSP. HTH, Michael.
  4. Ok, Is there any way other than writing action class & form bean. Because I want just a link and no need of 'formBean' you specified. I am intrested using tag. Is there any method like init() or something in Action or elsewhere such that it will work on form load?
  5. Re: Populating form bean in structs[ Go to top ]

    If you want to edit data and further submit these data, you definitly need a form bean, and an Action to populate it. The creation of the form bean is done by Struts, and you just have to handle it in your action. More generally when you have to edit data , you need a first Action A to populate the form and forward to edit page and another action B to handle submit data. Both are using the same form bean. You can also merge A and B in one DispatchAction. The Action A might not be necessary if you don't need to populate the form from service layer data. In that case the form is populated from default values, and Struts will create (or reuse) an instance of the form when it encounters the tag in the page.
  6. aa[ Go to top ]

    Take a look into the very good book "Jakarta Struts Live", available for free as ebook here on TSS.

    The action should look something like this:




    Than "showData.do" is the URL you call, "ShowDataAction" handles the database operation, and the forward "success" will leed you to the JSP.

    HTH, Michael.