my dog learned polymorphism*
The moose likes Struts and the fly likes tag library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "tag library" Watch "tag library" New topic
Author

tag library

Faris Syed
Greenhorn

Joined: Jun 25, 2004
Posts: 8
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

Joined: Jun 22, 2004
Posts: 8
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.


Jakob Jenkov<br />Softare Architect<br /><a href="http://www.jenkov.com" target="_blank" rel="nofollow">www.jenkov.com</a>
Faris Syed
Greenhorn

Joined: Jun 25, 2004
Posts: 8
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

As the tag library in question is part of Struts, I'm moving this off to the Web App Frameworks forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tag library