Struts taglib html:text and dynamic values problem

S

spivee

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
 
W

Wendy S

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.
 
Joined
Feb 11, 2008
Messages
1
Reaction score
0
Did you get resolved your issue

I also have similar requirement and I came across your post, did you get resolved your issue, If Yes, could you please let me know what exactly you did.

Thx
Kishor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top