aspose file tools*
The moose likes Struts and the fly likes Is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is "action" a reserved word?" Watch "Is "action" a reserved word?" New topic
Author

Is "action" a reserved word?

Chris Skinner
Greenhorn

Joined: Jan 23, 2002
Posts: 23
Hi,
I just had a strange problem with a struts app I'm working on. I have a field in my form bean :

private String action;

with the appropriate getters and setters.

In my .jsp I am using it like such :

<html:select property="action">
<option></option>
<option>Changed</option>
<option>Closed</option>
<option>Filed</option>
<option>Transfered</option>
</html:select>

Anyway, when I submit the form I get an internet explorer script error saying the object does not support this property or method.

I changed the name of the variable to action1 and I no longer get the error. So I'm curious is "action" actually a reserved word in struts that I'm unaware of? Anybody else ever seen this ?

Thanks
Chris


Christopher Skinner<br />SCJP2 1.4<br />SCWCD (in training)
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Its not a reserved word in struts.
It IS an attribute of an html form.

A lot of time in HTML you will see:


The problem comes in javascript.
myForm.action normally refers to the attribute "action" on the form tag.
Sometimes you want to change this with javascript: eg myForm.action="/otherSave.do"

myForm.userName refers to the textfield on the form.
eg myForm.userName.value = 'John Doe'

But what happens if you put a control called "action" in your form?
Does myForm.action refer to the attribute "action" in the form tag, or the control embedded in the form?
You see how the confusion arises?

Suggested solution: don't use action as the name of a control on a form. I would also avoid "name", "id", "method" or any other attributes of the form tag that you might want to access in javascript.

Cheers,
evnafets
Chris Skinner
Greenhorn

Joined: Jan 23, 2002
Posts: 23
Ah-Haa.....thanks that makes sense.
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is "action" a reserved word?