For each Struts input form (which uses an HTTP Post) that your web pages
contain, you create a JavaBean class that helps to preserve the state of
the data-entry form. The bean must extend either
org.apache.struts.action.ActionForm
or
org.apache.struts.action.DynaActionForm
, which supports dynamic
form beans. After you add a form bean to your project, you customize the
class file to define the bean's setter and getter methods.
You must configure the form bean in the Struts configuration file before you can run the Struts-based web application. At runtime, the form bean will be created either by the Struts controller servlet or the JSP form.
This topic covers:
Adding a form-bean element from the Struts Page Flow Diagram
Adding a form-bean element from the Struts Configuration Editor
To add a form-bean element from the Struts Page Flow Diagram:
Add the action to the page flow for which you want to create a form bean.
Right-click the action and choose Go to F orm Bean.
In the Create Struts Form Bean dialog, define the new form-bean.
The form bean is added to the Struts configuration file, and the form bean opens ready for you to define it.
To add a form-bean element from the Structure window:
In the Application Navigator, expand the Web Content folder then the WEB-INF folder to find the Struts configuration file to which you want to add a form bean and select it.
If the Structure window and the Property Inspector are not displayed, open them from the View menu.
In the Structure window, expand the Struts Config node to see the list of currently defined Struts elements.
If you the action to which the form bean relates already exists:
Right-click the action and choose Go to F orm Bean.
In the Create Struts Form Bean dialog, define the new form-bean.
The form bean is added to the Struts configuration file, and the form bean opens ready for you to define it.
Otherwise, carry out the following steps.
Right-click the Struts Config node and
from the menu choose Insert inside
struts-config
form-beans.
A folder for Form Bean definitions is created in the Structure window.
In the Structure window, right-click the form-beans folder and choose I nsert inside form-beans, then in the Insert form-bean dialog, define the attributes of the new form bean.
OR
In the Struture window, right-click the form-beans folder and choose Edit . The Struts Configuration Editor opens and you can add a form bean, specifying its attributes. See adding a form-bean element to a Struts configutation file from the Struts Configuration Editor
To add a form-bean element from the Struts Configuration Editor:
Open the Struts Configuration Editor for the Struts configuration file to which you want to add a form-bean element.
In the Struts Configuration editor dialog, choose Form Beans then Add.
Use the Create New Form Bean dialog to specify details of the new form bean.
If necessary, edit the properties of the new form bean. See Editing the attributes of a form-bean element
To edit the attributes of a form bean:
Do one of the following:
In the Structure window, select the new element name from the Form Beans folder and view the list of attributes of the currently selected form bean element in the Property Inspector. (If the attributes appear as a flat list, click the Categories icon in the Property Inspector to see the attributes by group.)
OR
In the Struture window, right-click the form-beans folder and choose Edit . The Struts Configuration Editor opens and you can edit the attributes of the form bean.
To view the code for a form bean:
For example, if your web page contains the input field loginId
, you customize the form bean to add the field as follows:
public class MyLoginActionForm extends ActionForm {
protected String loginId;
protected FormFile myLoginJSPFile;
public void setLoginId(String text) {
loginId = text;
}
public String getLoginId() {
return loginId;
}
public void setMyLoginJSPFile(FormFile file) {
myJSPFile = file;
}
public FormFile getMyLoginJSPFile() {
return myLoginJSPFile;
}
}
To validate the data in your form in a bean
validate()
method:
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
return super.validate(mapping, request);
}
About Struts Support in
JDeveloper
Working
with the Struts Controller
Copyright © 1997, 2004, Oracle. All rights reserved.