You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Coble <Ji...@duke.edu> on 2005/05/27 18:18:53 UTC
How to use bean property as value for html hidden field
In my JSP html:form, I want to have the value of a hidden field set to the
(String) value of a property of a request-scoped attribute. I tried using
a "bean:write" as the argument to the "value=" property of the
"html:hidden" tag, like this ...
<html:hidden property="resource" value="<bean:write name=\"resource\"
property=\"code\" scope=\"request\"/>" />
but, on the resulting page, the value of the hidden field was set to the
string ...
<bean:write name="resource" property="code"
scope="request"/>
not the value of the "code" property of the request-scoped "resource"
attribute.
I presume I could set the value of the html:hidden field using JSP <%= %>
syntax but I was trying to see if I could do it using the Struts taglibs.
Any ideas?
Thanks.
--Jim
==================================
Jim Coble
Senior Technology Specialist
Center for Instructional Technology
Email: jim.coble@duke.edu
Voice: 919-660-5974 Fax: 919-660-5923
Box 90198, Duke University
Durham, NC 27708-0198
==================================
Re: How to use bean property as value for html hidden field
Posted by Jim Coble <Ji...@duke.edu>.
Michael--
Thanks for the suggestion. I tried it but it doesn't work for the
html:hidden tag ... generated error message is "According to TLD, tag
html:hidden must be empty, but is not".
I think my best bet is follow the suggestion Wendy made in an
earlier post and set the value in the form in the preceding Action class.
--Jim
==================================
Jim Coble
Senior Technology Specialist
Center for Instructional Technology
Email: jim.coble@duke.edu
Voice: 919-660-5974 Fax: 919-660-5923
Box 90198, Duke University
Durham, NC 27708-0198
==================================
Michael Jouravlev <jm...@gmail.com>
05/27/2005 01:30 PM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
Struts Users Mailing List <us...@struts.apache.org>
cc
Subject
Re: How to use bean property as value for html hidden field
Though it does not seem to be documented well, but some (many, all?)
tags support textual content, like a regular XML element. This would
look kind of like this:
<html:hidden property="resource">
<bean:write name="resource" property="code" scope="request"/>
</html:hidden>
I haven't tried it, but this might work.
Michael.
On 5/27/05, Jim Coble <Ji...@duke.edu> wrote:
> In my JSP html:form, I want to have the value of a hidden field set to
the
> (String) value of a property of a request-scoped attribute. I tried
using
> a "bean:write" as the argument to the "value=" property of the
> "html:hidden" tag, like this ...
>
> <html:hidden property="resource" value="<bean:write name=\"resource\"
> property=\"code\" scope=\"request\"/>" />
>
> but, on the resulting page, the value of the hidden field was set to the
> string ...
>
> <bean:write name="resource" property="code"
> scope="request"/>
>
> not the value of the "code" property of the request-scoped "resource"
> attribute.
>
> I presume I could set the value of the html:hidden field using JSP <%=
%>
> syntax but I was trying to see if I could do it using the Struts
taglibs.
>
> Any ideas?
>
> Thanks.
> --Jim
>
> ==================================
> Jim Coble
> Senior Technology Specialist
> Center for Instructional Technology
> Email: jim.coble@duke.edu
> Voice: 919-660-5974 Fax: 919-660-5923
> Box 90198, Duke University
> Durham, NC 27708-0198
> ==================================
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to use bean property as value for html hidden field
Posted by Michael Jouravlev <jm...@gmail.com>.
Though it does not seem to be documented well, but some (many, all?)
tags support textual content, like a regular XML element. This would
look kind of like this:
<html:hidden property="resource">
<bean:write name="resource" property="code" scope="request"/>
</html:hidden>
I haven't tried it, but this might work.
Michael.
On 5/27/05, Jim Coble <Ji...@duke.edu> wrote:
> In my JSP html:form, I want to have the value of a hidden field set to the
> (String) value of a property of a request-scoped attribute. I tried using
> a "bean:write" as the argument to the "value=" property of the
> "html:hidden" tag, like this ...
>
> <html:hidden property="resource" value="<bean:write name=\"resource\"
> property=\"code\" scope=\"request\"/>" />
>
> but, on the resulting page, the value of the hidden field was set to the
> string ...
>
> <bean:write name="resource" property="code"
> scope="request"/>
>
> not the value of the "code" property of the request-scoped "resource"
> attribute.
>
> I presume I could set the value of the html:hidden field using JSP <%= %>
> syntax but I was trying to see if I could do it using the Struts taglibs.
>
> Any ideas?
>
> Thanks.
> --Jim
>
> ==================================
> Jim Coble
> Senior Technology Specialist
> Center for Instructional Technology
> Email: jim.coble@duke.edu
> Voice: 919-660-5974 Fax: 919-660-5923
> Box 90198, Duke University
> Durham, NC 27708-0198
> ==================================
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to use bean property as value for html hidden field
Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Jim Coble" <Ji...@duke.edu>
> In my JSP html:form, I want to have the value of a hidden field set to the
> (String) value of a property of a request-scoped attribute. I tried using
> a "bean:write" as the argument to the "value=" property of the
> "html:hidden" tag, like this ...
>
> <html:hidden property="resource" value="<bean:write name=\"resource\"
> property=\"code\" scope=\"request\"/>" />
You cannot nest JSP tags. Set the value of the form property 'resource' to
the correct value in the Action, before forwarding to the JSP, and the
framework will render the hidden field with the value set. What's placing
the 'resource' bean in the request? Instead of/in addition to that, do
form.setResource( resource.getCode() );
If for some reason that's unacceptable, you could always use a plain old
HTML <input> tag and nest the <bean:write> in that.
Or you could use Struts-EL and JSTL, but that's overkill for this problem.
I assume you aren't on a JSP 2.0 container so that the expression
${resource.code} would work.
--
Wendy Smoak
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org