All, I am new to Struts and trying to use same jsp/action/action form for both insert as well as update. I am not sure what I am doing wrong. I am also using Tiles framework in the application if it makes any difference. Any help is appreciated. TIA Srinivas My Struts Config
Hi Srinivas, Would you be so kind as to change the "Gxxx" in your publicly displayed name to comply with the JavaRanch Naming Policy? We prefer that you use a real name but if you don't want to do that, just use one that isn't obviously fictitious. Thanks for your cooperation! --- What exactly is not working right for you? Are you getting errors? We could sift through the code but it would help the diagnosis along if we knew what some of the symptoms were.
Thanks for the response. Well I don't see any errors and the jsp loads fine with no data in form fields. Let me give more details on the functionality of the form. The form is part of a wizard flow and has "Add another event", "Next" buttons. If the user click on "Add another event", details given are validated and stored in a session bean and sent back to the same form with empty form data. This works fine. JSP displays edit links to previously added events on top of the jsp by reading the session bean. User can switch to one of the previously entered events by clicking on those links. I want to read the data back from session and put it back on the form. I have followed the struts-registration example and do not see what I am missing. But when I click on those links I am getting empty form rather than filled form. When I put in some system.out.println in the above Action class execute method, I do find that the execute is using "Edit" mode as per my hidden field on form and I do see it reads event bean data from session bean and sets this bean on form. Looks like as if a new form object is being created after I have set data read from my session on the form object. But not sure where it is happening and how to fix it. Should my success forward to my tile definition or the struts definition of the url? Right now it forwards to tile definition. Let me know if you need more code than what I have already posted. Again thanks for your time [ August 21, 2003: Message edited by: Srinivas Gupta ]
Srinivas, You're doing a lot of things in execute() that you really shouldn't--things that the Struts framework does for you automatically. I suggest that you go through this excellent tutorial to get a good idea of how you should structure your Struts application and how to separate responsibilities properly. I'm sure you'll soon realize what you're doing wrong once you get a good idea of how your objects should work with the framework.
Joined: Aug 20, 2003
Thanks for the tutorial link. I will cleanup my execute method. However, The problem still exists. Why is my form data from session is not displaying when page is used in edit mode?
Try this simple test: 1. remove or comment out everything you have in execute(). 2. Add code that does the following: 2.1. create a new EventDetailBean 2.2. set properties of the EventDetailBean 2.3. put the EventDetailBean in your form bean 2.4. return the SUCCESS forward 3. In you JSP, just add simple html:text tags for each property of your EventDetailBean You should see the values populated in the form. If you still have a problem, post your execute code again along with the relevant portions of the JSP.