|
From: spivee on 31 Mar 2005 21:49 I'm looking for a solution to this problem I've been having. I have a multi page form. Basically, the first form, you pick an identifying object. The Action for that form generates an object based on the identifying object and displays the data into a form on the second page, to allow for edits. Basically, I need to be able to populate the text fields with some of the data from the object in the session. I'm basically trying to do this... <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ page language="java" import="com.spivee.www.MyObject" %> <% MyObject object = (MyObject) session.getAttribute("MyObject"); %> <html:html locale="true"> <body> <p>Please confirm the information.</p> <html:form action="/configureControlTool"> My Object Name: <html:text property="objectname" size="18" value="<%= object.getName() %>" /> <html:submit /> <html:reset /> </html:form> </body> </html:html> I know I can do this by using a standard html input tag, but I'd like to know how it's supposed to be done with taglibs. I found one article but all it really said was to 'use JSTL expression language' and I'm not sure what that is :-P
From: Wendy S on 31 Mar 2005 22:13 <spivee(a)excite.com> wrote: > I'm looking for a solution to this problem I've been having. I have a > multi page form. Basically, the first form, you pick an identifying > object. The Action for that form generates an object based on the > identifying object and displays the data into a form on the second > page, to allow for edits. Basically, I need to be able to populate the > text fields with some of the data from the object in the session. I'm > basically trying to do this... If you rearrange it so you can populate the form bean for the second form before you forward to that JSP, the Struts tags will automatically render values for the form elements based on the contents of the form bean. You should almost never use the 'value' attribute of the tags, it defeats the purpose of the framework. (You'd never be able to re-display the user's input if it fails validation, the form would keep reverting to the 'default' value from the object in the session.) I have a single Action -- EditWhateverAction that has methods for select, update, create, etc. (It's one of the DispatchActions, so there is logic to select the correct method based on values in the request.) That keeps it all together, one form, one Action. With separate Actions, I don't see how to get around Action chaining, which is generally frowned upon, but sometimes necessary. Here's the way I see yours working: selectThing.do -> SelectThingAction -> selectThing.jsp (first time) (form is submitted to) selectThing.do -> SelectThingAction (places object in session) -> editThing.do -> EditThingAction (pre-populates form from the object in the session) -> editThing.jsp For the 'pre-populate form' part, see: BeanUtils.copyProperties(...). Perhaps someone more familiar with having a bunch of separate Actions can rework it to get rid of the chaining. -- Wendy
|
Pages: 1 Prev: Error loading log4j properties file Next: Strange null-pointer |