Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<html:text property?> Question!

Status
Not open for further replies.

croniccoder

Programmer
Jul 28, 2006
1
US
I am new to struts. I am trying to create a conditional statement within a jsp page.

<html:text maxlength="128" property="streetName">

streetName is a string that is being displayed in the text box. I want to create a conditional that if the streetName length is greater than 4, then display the background in #FFCCFF, else display the backgroun in #FFFFFF.

I've tried this many ways, but can't figure it out. Any help would be greatly appreciated.
 
Cronic, (hehe)

This is not part of struts. This is a javascript call.
This is how it's done.

You're struts code:
Code:
[blue]
<html:text maxlength="128" property="streetName" onKeyPress="changeColor(this.form.streetName)">
[/blue]

In between the <head></head> tags, insert this script.
Code:
[blue]
[red]<SCRIPT LANGUAGE=[blue]"javascript"[/blue]>[/red]
[b]function[/b] changeColor(textObject)
{
	if (textObject.value.length>=3) textObject.style.background='#FFCCFF';
	else textObject.style.background='#FFFFFF';
}


[red]</script>[/red]
[/blue]


I just tried this via basic html in firefox/ie and I know struts supports the onMethods() so it should work.

Hope that helps.
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
If you want to do it in struts you could create a property in you actionform for the length of the streetName:

Code:
private int streetNameLength = 0;
public int getstreetNameLength {
    return this.streetName.length();
}

and then use the <logic:greaterThan> tag:

Code:
<logic:greaterThan name="formBeanName" property="streetNameLength" value="4">
...set your background...
</logic:greaterThan>
<logic:lessEqual name="formBeanName" property="streetNameLength" value="4">
...set your background...
</logic:lessEqual>
 
bluecrush,

That will only work if he submits the form. I suppose since he never specified he can use either way.

-Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
I don't believe that's accurate...

My understanding is that when the form is initially created, so is the form bean with the default values (in this case,
Code:
 streetNameLength = 0;
). So, as long as the form exists in the jsp that he uses the logic tags in, the property is available without submitting the form.
 
blue,

That is correct. Those attribues are avaiable in the form at the time of processing. So he can use all the struts logic he wants, but what I was point out is that maybe he wants to change the background color as the user is typing, rather than do a submission to submission change of color.


-Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top