Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tag library

 
Faris Syed
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Simple question, I want to assign a current year value in a text field when form is displayed but instead of assigning a value it is showing this literal string like this <%=s_year%>

thanks for help.

<html:text property="year" style="width:40px" value="<%=s_year%>" />
 
Jakob Jenkov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this <%=s_year%> is shown as the value it could be because that tag doesn
t allow you to use runtime expressions (<%=...%> as values for that attribute. Then whatever text you enter will be used as it is.

I can see that you are using Struts for the form, right? Struts is really helpful in many cases, but once in a while you run into requirements that are easier to implement using ordinary JSP/HTML. You can achieve what you want like this:

<input type="text" name="year" style="width:40px" value="<%=s_year%>" />

somewhat easier than trying to tweak the other stuff into the Struts tags. Those who say scriptlets are forbidden, bad stuff, are only right 95% of the time I think. The last 5% of the times scriptlets are exactly the easiest and most elegant way to achieve what you need.

Don't worry that Struts won't be able to work with that form value. Struts can't see the difference when the data reaches the server anyways. It will populate your form bean just fine no matter if you use the Struts tag libs to generate the form, or ordinary HTML.
 
Faris Syed
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jakob for your reply. You are right I was trying to be more sophisticated by using tag library. My goal is to populate all date/time values using collection and then pre-select current values. But I guess I have go back to good old days and use for loops to populate <select>

<html:select property="month" value="<%=s_month%>">
<html ptions name="months" />
</html:select>

 - 

<html:select property="day" value="<%=s_day%>">
<html ptions name="days" />
</html:select>

 - 

<html:text property="year" style="width:40px" value="<%=s_year%>" />
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the tag library in question is part of Struts, I'm moving this off to the Web App Frameworks forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic