I am now using Struts 1.0 for the J2EE framework. In jsp code: I have used <html:form action="/controller.do" name="frmController" type="ControllerForm">. In the ControllerForm.java, there is a field 'target'. The request of this jsp page comes from ControllerAction. Actually, I hope that when the request comes to the jsp page, the variable 'target' has a value assigned in the ControllerAction, so I have used setTarget("value") in ControllerAction. However, it seems that in the jsp file, a new ControllerForm is instantiated. How can I instantiate the ControllerForm in the ControllerAction, so that the jsp file use the same form without instantiate a new one? Thanks! Stephen Lee
I'm having a little difficulty figuring out what you want done where there, but I can tell you what is SUPPOSED to be happening. When the initial request is being made to prepare a form for input, the form bean will be either created or located (depending on scope). It can initialize itself and acquire properties from its requester. This is done by the core dispatched automatically. The core dispatcher then uses the URL that caused the "prepare"-phase request to detemine which Action processor to invoke for secondary dispatching. One of the parameters that this Action processor will get is the Form Bean, so you can do any last-minute value tweaking there. When the dispatcher is exited, it returns the ID of the associated JSP to present. This JSP's form controls are filled in from the form bean. Additional logic for non-Stuts-managed data may be in the JSP itself, although this isn't really a good idea. The JSP is used to generate HTML (or whatever) and the page is displayed on the client machine. Once the user clicks "OK" on the form, the core dispatcher takes over again, creating/locating the indicated form bean and filling in values from the form. The validator is invoked (assuming you've done the usual configuration) and, if the data is valid, the Action processor for the form's URL is invoked.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Hi Tim, This is quite a different topic but my problem with struts is that there is no distinction in the execute (or perform) method in the Action class whether you are requested to display the ActionForm (i.e the JSP associated with the form) or to handle a submitted ActionForm. For example, if I had a JSP page that prompts for a password change with a submit button on it, how could I distinguish inside the execute method that it is called to display the page initially or to now process this page and change the password in the database etc? The way we do it at the moment is test for the existence of some parameter value in the request (e.g. the submit button) and decide what to do based on that. Is this the standard way of doing in struts or is there a feature in struts that takes care of this that we don't know? I am looking for a sort of a separate display() method in the Action class that will be called by the framework if requested to display the form rather than use the execute() method as a general handler for these two different events. I know that in some other framework such as JATO, you will explicitly know whether you are going to display or handle the form because the events that you receive from the framework are very specific. Thanks, Eric
All of life is a contant education - Eleanor Roosevelt. Tiny ad: