• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nesting the bean:write tag

 
mark anthony
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33691
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
I thought you couldn't nest tags. The tags get evaluated in a single pass.
 
mark anthony
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternately:



should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic