This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts: access ActionForm bean from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts: access ActionForm bean from JSP" Watch "Struts: access ActionForm bean from JSP" New topic
Author

Struts: access ActionForm bean from JSP

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
How do I get access to the ActionForm bean from a JSP page?
For example, I've a formbean named "loginForm" and resides in session scope.
How do I access it from JSP?
I've tried <jsp:useBean id="loginForm" scope="session"/> but it is not getting it.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Well, if you are using struts tags within an HTML form, by default they will look for the instance of ActionForm that is specified in the struts config. If you are not using this inside an <html:form>, you could always use the <bean> tags, such as <bean:write>.
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
I need the reference to the Session ActionForm object, so that I can initialize the attributes of another form on the same page.
How to initialize ActionForm? If through the constructor, I'll have no access to the struts/servlet environment.
Is it that I've to create my own beans to coordinate? Since ActionForms cannot be referenced as an object from anywhere else?
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
You are confusing me.
1. Do have a form be specified in your struts-config.xml? For example:

2. In your action-mappings section of struts-config, is your action set up to use that form-bean in the proper scope. For example:

Assuming you have done this, an ActionForm will be instntiated for you for access in the Action and by the JSP.
In your jsp there should be a couple ways you could get access to this form-bean.
This will associate a text field in the form with the username attribute of your logonForm bean.

Also, you could get access to it using <bean> tags like this.
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
Originally posted by Jason Menard:
You are confusing me.
Also, you could get access to it using <bean> tags like this.

I am thinking about obtaining the FormAction Object reference, so that I can do some processing with the values.
However, I've worked around it by creating a reguar jsp:bean and put it in the session scope during execution of Action class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts: access ActionForm bean from JSP
 
Similar Threads
Problem with indexed property !
Passing a Parameter via Ajax
access to attributes
Difference between Page Bean and Form Bean??
Setting up form data