This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic values inside html:text value property

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what i would like to do... I want a text box whose value property will be loaded with a String that is available as an attribute in session scope.

When defining a text box using html:text why cant i write scriplets inside the value property ?



If instead i say value = "blah" it works fine. Is it possible to define values inside this property that do not start with a double qoute ?

Thanks.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <html:text> tag requires quotes around the value property you specify regardless of whether it's a scriptlet or not. It does accept scriptlets, but requires "all or nothing", meaning the entire value must be a scriptlet, or none of it must be a scriptlet. So, the following should work:

value="<% request.getSession().getAttribute("attribute_name") %>"

One additional note: The only reason for using the <htm:text> tag as opposed to an <input type="text"> tag is that it already populates the value for you based on the property of the ActionForm bean you specify. If you're overriding this value anyway, there's no real reason to use the <html:text> tag. The following will work just as well.

<input type="text" name="fun" size="10" value="<% request.getSession().getAttribute("attribute_name") %>" >
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello John,
i have done what u r talking about.


request.getSession().getAttribute("attribute_name")
you take this value in scriplet
and then use that value just like.
<% String a = request.getSession().getAttribute("attribute_name"); %>


<html:text property="fun"
size="10"
value="<%=a%>" />


hope this will work
Nishita
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jain is right. I had missed the fact that your code is missing the equal sign.

The following should also work:

value="<%= request.getSession().getAttribute("attribute_name") %>"
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahhh yes ! it worked. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic