views:

164

answers:

2

I have two questions :

1) Where do we call a bean in struts (what is the exact line through which we call the bean and from which file) and how the getter and setter methods are called?

2) Also we are fixing the scope as request or session or something else, I can understand that the values will be stored in the request object or session object but my question is in what form the values will be stored?

A: 

2) the values will be stored as objects. The request and session attributes are Maps containing key and the object you stored.

Kees de Kooter
+2  A: 

1) If you're talking about struts form beans, they are populated automatically through the struts's ActionServlet and the various tags you used.

2) This is determined by your struts-config.xml configuration and your <html:form action="/myAction"> tag :

<form-beans>
    <form-bean name="myForm" type="com.example.struts.form.MyForm" />
<form-beans>
<action-mappings>
    <action path="/myAction"
            type="com.example.struts.action.MyAction"
            name="myForm"
            scope="request">
  <forward name="success" path="myjsp.jsp" />
  <forward name="failure" path="named.error.tiles.definition" />
    </action>
</action-mappings>

In this example, your html form containing the html:form tags will populate your myForm struts form bean with a request scope visibility when you submit your formular.

You will then retrieve it in your MyAction class with :

public ActionForward execute(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) {

        if(isCancelled(request))
            form.reset(mapping, request);

        if(form != null)
            MyForm myForm = (MyForm)form;
}
WiseTechi