| Author |
Dynamic values inside html:text value property
|
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
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.
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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") %>" >
|
Merrill
Consultant, Sima Solutions
|
 |
Nishita Jain
Ranch Hand
Joined: Mar 30, 2006
Posts: 97
|
|
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
|
Nishita
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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
Joined: Feb 24, 2006
Posts: 6588
|
|
|
ahhh yes ! it worked. Thanks.
|
 |
 |
|
|
subject: Dynamic values inside html:text value property
|
|
|