File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Map-backed ActionForm Key value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Map-backed ActionForm Key value" Watch "Map-backed ActionForm Key value" New topic

Map-backed ActionForm Key value

Brian Boyle

Joined: Nov 17, 2003
Posts: 13
I am using a map-backed ActionForm and so in my JSP code I have a <html:text> tag that looks like this:
<html:text property="value(<%=value.getUserId()%> " readonly="true" size="2" />
The reason I have a scriplet in there is because I have a dynamic form and the value of the key changes all the time. I want the value of the key to be the "id" of the user logged in.
However, this is giving me problems because the value of the key is being taken literally as <%=value.getUserId()%> rather than the value of the userId. The scriplet <%= value.getUserId %> is correct because I have tested it with System.out.println(value.getUserId). So it looks like I cannot put my scriplet in there. Has anyone experienced this before? Or does anyone know why it won't et me do this? Any way to get around this?
I'd appreciate any help. I've been stuck on it for two days now.
[ March 07, 2004: Message edited by: Brian Boyle ]
Srikanth Shenoy
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
You must be using Tomcat.
Tomcat and many other JSP parsers cannot interpret what you are trying to do !!!
This should work:
<html:text property='<%= "value(" + value.userId + ")" %>' readonly="true" size="2" />
Srikanth Shenoy
Author: Struts Survival Guide - Basics to Best Practices

Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Brian Boyle

Joined: Nov 17, 2003
Posts: 13
Hi thanks for your reply. I am using Tomcat! I had already tried thee method you suggested but that didn't work either . However I got an answer from the Struts mailing list.This is what I did and it worked!
<% String propertyName = "value(" + myId + ")"; %>
<html:text title="myinput" property="<%=propertyName%>" readonly="true" size="2" />
I agree. Here's the link:
subject: Map-backed ActionForm Key value
jQuery in Action, 3rd edition