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

styleID attribute

Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
Hello everyone,
I know the purpose of styleID attribute(Ex:in html:text). It's basically to give the element an ID attribute since the name attribute is overloaded.

But I am having problem in assigning id attribute for a element which has indexed/nested property.

<html:text indexed="true" name="riskResults" property="riskFromDate" size="10" maxlength="10" styleClass="AdmTextBox" />

I have to specify name attribute because "rishResults" is a innerbean for the outerone, like this

public class LymeSupplementForm extends ValidatorActionForm {
private String firstName;
private List riskList = new ArrayList()
public RiskResults getRiskResults(int index)
while(index >= riskList.size()){
riskList.add(new RiskResults());
return (RiskResults)riskList.get(index);

public void setRiskResults(int index,RiskResults risk)

in my javascript, I do something like this
var inDate = trim(document.getElementById('riskResults['+ 0+ '].riskFromDate').value);

this is where I get the problem. It works fine in IE but not in Mozilla. IE automatically treates the name attribute as ID but for Mozilla, I had to explicilty specify ID attribute.
I tried adding styleID attribute but still no,luck

Can someone please help me?
[ March 27, 2007: Message edited by: Vani D Bandargal ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Please be sure to ask questions on the Struts tags in the Struts forum. This post has been moved there for you.

[Asking smart questions] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The indexed attribute of the <html:text> tag causes the name attribute of the rendered HTML page to be indexed. However, it does nothing with the styleId attribute except pass it through as-is to create the id attribute in the rendered HTML. If you want an indexed value for the id, you will have to build it yourself using a scriptlet.

There is another way to do it, though. I'd suggest using the JavaScript getElementsByName function. This function always returns an array, even if there is only one element with the specified name. Something like the following would work:

[ March 27, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: styleID attribute
It's not a secret anymore!