| Author |
How to set maxlength property dynamically in Struts html:text tag?
|
Kate Xu
Greenhorn
Joined: Jul 28, 2003
Posts: 11
|
|
Hello all, I have a problem using Struts <html:text> tag. How do I set maxlength property dynamically? For example: <html:text name="myForm" property="firstName" size="25" maxlength="30" /> I tried the following three ways: (1) use <%= %>, it won't work. import MyClass; .... <html:text name="myForm" property="firstName" size="25" maxlength="<%=MyClass.FIRSTNAME_MAX_LENGTH%>" /> (2) Use <bean:message> tags, it won't work. <html:text name="myForm" property="firstName" size="25" maxlength="<bean:message key="myPage.maxlength.firstnameMaxlength"/>" /> (3) Use <bean:write> tag, it also won't work. <html:text name="myForm" property="firstName" size="25" maxlength="<bean:write name=\"myForm\" property="firstnameMaxLength"/>"/> Any ideas? Thank you! Kate
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4115
|
|
The Struts documentation shows that the maxlength attribute can be a runtime expression so the first method should work. Try using the fully qualified name of MyClass: maxlength=<%=com.foo.MyClass.MAXLENGTH %>
|
Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
Yup. First method should work. I use it all the time. I can't think of what might have gone wrong (other than the already stated). Maybe the constant is an int and it doesn't like it? If so, change it to a String or do the following: <html:text name="myForm" property="firstName" size="25" maxlength='<%= MyClass.FIRSTNAME_MAX_LENGTH + "" %>' />
|
A good workman is known by his tools.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: How to set maxlength property dynamically in Struts html:text tag?
|
|
|