This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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>.
Joined: Apr 19, 2002
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?
Joined: Nov 09, 2000
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.
Joined: Apr 19, 2002
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.