Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionForm

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class RegisterForm extends ActionForm

{

}

I have this in my execute method of the Action class :

Registerform rf = (RegisterForm) form; // what exactly is happening here ?

RegisterForm is not an abstract class then , why can we not create an instance of Registerform ? Also I read "The base ActionForm class cannot be instantiated". Is it because the ActionForm class is mentioned as abstract in the api docs :
public abstract class ActionForm extends Object implements Serializable

Is the ActionForm a javabean ?? If yes what are the rules/specifcation for a javabean ? Are there any datatype an ActionForm can/cannot take. Few rules for a class to be a java bean are :

1. must have getters and setters
2. must implement Serializable.
3.... ?
4.... ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Registerform rf = (RegisterForm) form; // what exactly is happening here ?

What do you mean? The form is being cast to an instance of RegisterForm.

> why can we not create an instance of Registerform

What makes you think you can't?

> Is the ActionForm a javabean

It *could* be, but doesn't have to be:

http://en.wikipedia.org/wiki/JavaBean
http://struts.apache.org/1.2.7/api/org/apache/struts/action/ActionForm.html

I don't understand the rest of your JavaBean questions.
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know why is the ActionForm(org.apache.struts.action.ActionForm) class created as an abstract class , whereas the action(org.apache.struts.action) is not abstract ?

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
H David Newton,

public class RegisterForm extends ActionForm

{

}

Registerform rf = (RegisterForm) form;

I read this in "Struts in Action", so not sure why we are not creating an instance of the Registerform like :
Registerform rf = new Registerform();

Thanks for the two links that you provided.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the form already exists and is populated with form data. If you created a new one you'd have an empty form.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic