aspose file tools*
The moose likes Struts and the fly likes How to set maxlength property dynamically in Struts html:text tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to set maxlength property dynamically in Struts html:text tag?" Watch "How to set maxlength property dynamically in Struts html:text tag?" New topic
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: 4419
    
    5

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]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

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: http://aspose.com/file-tools
 
subject: How to set maxlength property dynamically in Struts html:text tag?
 
Similar Threads
how to nest Struts tags?
regarding <html:text> tag
Struts Validator-Validating an Integer Form Field
Managing dynamic form elements in Struts
How to set value in html:text using bean:write