M Sach
M Sach

Reputation: 34424

Can Javascript on client side access Struts form?

In Struts say we define some form with the name TaskForm in struts-config.xml.

In one of the javascript function, I can see the statement:

document.TaskForm(some form name in struts-config.xml).action = action

My question here is how come we are able to execute document.taskform at client side?

I mean statements like document.getElementByid("") are defined in browser side but not sure about document.taskform?

Upvotes: 0

Views: 1640

Answers (1)

user159088
user159088

Reputation:

You can't access Struts ActionForms using JavaScript!

What you are seeing is JavaScript interaction with the HTML client side <form> tag (something like this tutorial presents)

The HTML <form> tag happens to have the same attribute name and action value as the ones from the <form-bean> and <action> tags of struts-config.xml. This is no coincidence!

ActionForms are the server side object representation of a client side HTML <form> tag and Struts server tags generate HTML which is then sent to the client.

The HTML <form> tag usually contains the name of the bean specified in <form-bean> of struts-config.xml tag, while the action attribute of the <form> is the one specified in the corresponding <action> of struts-config.xml.

Some names and values are preserved to maintain clarity of the code. This makes things homogeneous. But we are NOT talking about the same thing!

Upvotes: 1

Related Questions