wood burning stoves 2.0*
The moose likes Struts and the fly likes nesting the bean:write tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "nesting the bean:write tag" Watch "nesting the bean:write tag" New topic
Author

nesting the bean:write tag

mark anthony
Greenhorn

Joined: Mar 14, 2005
Posts: 13
hi I want to nest the <bean:write tag into any other html tag

i.e.

<html:hidden property="color" value="<bean:write name="colorSet" property="colorValue" />"/>


Could you tell me if I am missing any quotes or something ?

Thanks
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Mark,
I thought you couldn't nest tags. The tags get evaluated in a single pass.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
mark anthony
Greenhorn

Joined: Mar 14, 2005
Posts: 13
so ,
what if I need to write a value that comes from a bean into a html tag?
Do I need to use scriplets?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In the standard struts tags, your only option is to use scriptlets instead of nesting tags.


However, in cases like this, I prefer to use the struts-el version of the tags. They allow you to embed EL expressions in the tags.

Using your example, the code would be:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" prefix="html-el" %>

<html-el:hidden property="color" value="${colorSet.colorValue}"/>

Just remember to include the struts-el.jar file in your classpath.
[ December 18, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One other fact about html:xxx tags that's not very well documented is that if you supply a body for the tag, it is used as if you had coded a value attribute for that tag.

So, in the example you gave, the following would work:

<html:hidden property="color"><bean:write name="colorSet" property="colorValue" /></html:hidden>
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
>One other fact about html:xxx tags that's not very well documented is that
>if you supply a body for the tag, it is used as if you had coded a value
>attribute for that tag.
Unfortunately it doesn't work for the html:hidden tag.
The tld specifies that it can't have a body.


I would say the best approach here is to populate your ActionForm in the Action used to load the page.
ie in java code:

form.setColor(colorSet.getColorValue());

Then when you forward to your jsp page with just

<html:hidden property="color">
It is automagically populated for you.
Elie Hirschman
Ranch Hand

Joined: Dec 15, 2005
Posts: 37
Alternately:



should work.
 
GeeCON Prague 2014
 
subject: nesting the bean:write tag