|
BEA NetUI tags and APIs are included for backward compatibility only. For new applications, use the Beehive tags and APIs. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.jsp.tagext.TagSupport javax.servlet.jsp.tagext.BodyTagSupport com.bea.wlw.netui.tags.AbstractBaseTag com.bea.wlw.netui.tags.html.Form
public class Form
This tag represents an input form, associated with a bean whose properties correspond to the various fields of the form.
Attribute Descriptions | |||
---|---|---|---|
Attribute | Required | Runtime Expression Evaluation | Data Bindable |
action | Yes | No | No |
Required. The action invoked by submitting the Form. | |||
encType | No | No | No |
The content encoding to be used on a post submit. | |||
focus | No | No | No |
The tagID of a nested Netui tag which should receive the focus. | |||
location | No | No | No |
The location hash to append to the url. | |||
method | No | No | No |
The request method used when submitting this form. | |||
name | No | No | No |
The attribute key under which the associated ActionForm bean used to populate
the input form is stored. This ActionForm is found in the scope defined by the scope
attribute. | |||
scope | No | No | No |
The scope ('request' or 'session') under which the associated ActionForm
bean used to populate the form input fields is stored. Using the name , type
and scope attributes defines an the ActionForm object used. | |||
tagId | No | No | No |
The ID of this button used by the enclosing html tag to get the tag's real ID attribute for javascript and focus purposes. The real ID attribute id is generated based upon this name. | |||
target | No | No | No |
The window target | |||
type | No | No | No |
The Java class name of the ActionForm bean to be created, if necessary.
This bean will be created if the name and scope attributes are set.
The bean is then used to populate the form input fields. |
processData
action method in the Controller file when the form is submitted.
<netui:form action="processData"> Name: <netui:textBox dataSource="{actionForm.name}"/> Age: <netui:textBox dataSource="{actionForm.age}"/> <netui:button value="Submit" type="submit"/> </netui:form>
Notice that the processData action method takes a parameter of
type ProcessDataForm
.
/** * @jpf:action * @jpf:forward name="success" path="showData.jsp" */ protected Forward processData(ProcessDataForm form) { // // Process the submitted data here. // return new Forward("success"); }
This means that the submitted data is loaded into an instance of ProcessDataForm before it is passed to the action method.
In this next sample, the form fields are pre-populated based upon default values stored in the Session object.
<netui:form action="Action" type="corp.Controller$NameBean" scope="session" name="nameBean"> Name: <netui:textBox dataSource="{actionForm.name}" /> <netui:button value="Submit"/> </netui:form>
Submitting Data
When a <netui:form> is submitted, the form data is passed to a method for processessing. The data is passed as a Form Bean instance. The <netui:form>'s input fields correspond to the properties of the Form Bean. When the form is submitted the following sequence of events occurs: (1) a new Form Bean instance is created, (2) the form data is loaded into the corresponding Form Bean properties, and (3) the Form Bean instance is passed to the method where the data is processed.
The action
attribute determines the target method of the submission.
The parameter of the target method determines the Form Bean instance
that carries the submitted data.
For example, if a <netui:form>'s target method is someAction
...
<netui:form action="someAction"> // // input fields go here // <netui:button value="Submit" type="submit"/> </netui:form>
...and the someAction
method takes a Form Bean parameter of
type SomeFormBean
...
/** * @jpf:action * @jpf:forward name="success" path="showData.jsp" */ protected Forward someAction(SomeFormBean form)
...then an instance of SomeFormBean
will carry the submitted data.
Pre-populating Form Fields with the Session Object
The name
, type
, and scope
attributes can
be used together to pre-populate
the form fields with default values when they are first rendered in the browser.
In the Controller file, instantiate the appropriate Form Bean, set default values, and store the Form Bean instance in the Session object.
protected void onCreate() { // Create a new Form Bean instance ProcessDataForm formInstance = new ProcessDataForm(); // Set default values. formInstance.setAge(32); formInstance.setName("John"); // Store the instance in the Session object. getSession().setAttribute("defaultValues", formInstance); }
Then, use the name
, type
, and scope
attributes to pre-populate the
form fields.
<netui:form action="processData" name="defaultValues" type="tagSamples.netui.form.FormController$ProcessDataForm" scope="session">
Note: when the data is submitted, the data is passed as a Request-scoped Form
Bean, *not* as the Session-scoped Form Bean used to pre-populate the fields. However, you
may pass the data as a Page Flow-scoped Form Bean, if the annotation
@jpf:action form="somePageFlowScopedBean"
is set on the receiving method.
For detailed information on Form Bean scopings see
Form Bean Scopings
Pre-populating Form Fields By Passing a Form Bean Instance to the JSP Page
As an alternative to the pre-population technique above, you can set the pre-population values in a Form Bean instance and then pass that instance to the JSP page. For example, assume that index.jsp contains the <netui:form> and input elements. The following action method sets the pre-population values in a Form Bean instance and passes that instance to the <netui:form> and its input elements. Note that the Forward object returned by the method has two parameters, the String "success" and the pre-populated form.
/** * @jpf:action * @jpf:forward name="success" path="index.jsp" */ protected Forward begin(ProcessDataForm form) { form.setAge(44); form.setName("Mark"); return new Forward("success", form); }
Field Summary | |
---|---|
protected org.apache.struts.config.ModuleConfig |
appConfig
The application configuration for our module. |
protected String |
beanName
The name of the form bean to (create and) use. |
protected String |
beanScope
The scope of the form bean to (create and) use. |
protected String |
beanType
The type of the form bean to (create and) use. |
protected String |
enctype
The content encoding to be used on a post submit. |
protected String |
focus
The name of the field to receive focus, if any. |
protected String |
location
The location hash to append to the url. |
protected org.apache.struts.action.ActionMapping |
mapping
The ActionMapping defining where we will be submitting this form |
protected String |
method
The request method used when submitting this form. |
protected String |
name
The attribute key under which our associated bean is stored. |
protected String |
scope
The scope (request or session) under which our associated bean is stored. |
protected org.apache.struts.action.ActionServlet |
servlet
The ActionServlet instance we are associated with (so that we can initialize the servlet property on any form bean that
we create). |
protected String |
target
The window target. |
protected String |
text
The body content of this tag (if any). |
protected String |
type
The Java class name of the bean to be created, if necessary. |
Fields inherited from class com.bea.wlw.netui.tags.AbstractBaseTag |
---|
ATTR_GENERAL, ATTR_GENERAL_EXPRESSION, ATTR_JAVASCRIPT, ATTR_STYLE, JAVASCRIPT_STATUS, NETUI_UNIQUE_CNT |
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport |
---|
bodyContent |
Fields inherited from class javax.servlet.jsp.tagext.TagSupport |
---|
id, pageContext |
Fields inherited from interface com.bea.wlw.netui.tags.html.HtmlConstants |
---|
ACCEPT, ACCESSKEY, ACTION, ALIGN, ALINK, ALT, ANCHOR, BACKGROUND, BASE, BGCOLOR, BODY, BORDER, BR, CAPTION, CELLPADDING, CELLSPACING, CHAR, CHAROFF, CHARSET, CHECKED, CLASS, COLS, COORDS, DIR, DISABLED, DIV, ENCTYPE, FOR, FORM, FORM_GET, FORM_POST, FRAME, HEIGHT, HREF, HREFLANG, HSPACE, HTML, ID, IMAGE, INPUT, INPUT_BUTTON, INPUT_CHECKBOX, INPUT_FILE, INPUT_HIDDEN, INPUT_IMAGE, INPUT_PASSWORD, INPUT_RADIO, INPUT_RESET, INPUT_SUBMIT, INPUT_TEXT, ISMAP, LABEL, LANG, LINK, LONGDESC, MAXLENGTH, METHOD, NAME, ONBLUR, ONCHANGE, ONCLICK, ONDBLCLICK, ONFOCUS, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONLOAD, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, ONRESET, ONSELECT, ONSUBMIT, ONUNLOAD, OPTION, READONLY, REL, REV, ROWS, RULES, SELECT, SHAPE, SIZE, SPAN, SRC, STYLE, SUMMARY, TABINDEX, TABLE, TARGET, TD, TEXT, TEXTAREA, TITLE, TR, TYPE, USEMAP, VALIGN, VALUE, VLINK, VSPACE, WIDTH |
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag |
---|
EVAL_BODY_BUFFERED, EVAL_BODY_TAG |
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag |
---|
EVAL_BODY_AGAIN |
Fields inherited from interface javax.servlet.jsp.tagext.Tag |
---|
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE |
Constructor Summary | |
---|---|
Form()
|
Method Summary | |
---|---|
void |
addParameter(String name,
Object value)
Adds a URL parameter to the generated hyperlink. |
void |
addTagID(String tagID,
String name)
Adds a tagId and name to the Form's focusMap. |
int |
doAfterBody()
Save the body content of the Form. |
int |
doEndTag()
Render the end of this form. |
int |
doStartTag()
Render the beginning of this form. |
void |
generateRealName()
|
String |
getAction()
Return the action of the Form. |
String |
getBeanName()
Return the name of the form bean corresponding to this tag. |
String |
getEnctype()
Return the content encoding to be used on a post submit. |
String |
getFocus()
Return the name of the field to receive focus. |
String |
getLocation()
Return the location hash to append to the url. |
String |
getMethod()
Return request method used when submitting this form. |
String |
getName()
Return the attribute key under which our associated bean is stored. |
String |
getOnClick()
Gets the onClick javascript event. |
String |
getOnDblClick()
Gets the onDblClick javascript event. |
String |
getOnKeyDown()
Gets the onKeyDown javascript event. |
String |
getOnKeyPress()
Gets the onKeyPress javascript event. |
String |
getOnKeyUp()
Gets the onKeyUp javascript event. |
String |
getOnMouseDown()
Gets the onMouseDown javascript event. |
String |
getOnMouseMove()
Gets the onMouseMove javascript event. |
String |
getOnMouseOut()
Gets the onMouseOut javascript event. |
String |
getOnMouseOver()
Gets the onMouseOver javascript event. |
String |
getOnMouseUp()
Gets the onMouseUp javascript event. |
String |
getOnReset()
Gets the onReset javascript event. |
String |
getOnSubmit()
Gets the onSubmit javascript event. |
String |
getRealName()
this is used to |
String |
getScope()
Gets the scope (request or session) under which the associated bean is stored. |
String |
getStyle()
Gets the style of the rendered html tag. |
String |
getStyleClass()
Gets the style class of the rendered html tag. |
String |
getTabindex()
Gets the tabIndex of the rendered html tag. |
String |
getTagId()
Return the ID of the form. |
String |
getTagName()
Return the name of the Tag. |
String |
getTarget()
Gets the window target. |
String |
getType()
Gets the Java class name of the bean to be created, if necessary. |
protected void |
localRelease()
Release any acquired resources. |
protected void |
lookup()
Look up values for the name , scope , and
type properties if necessary. |
void |
setAction(String action)
Set the name of the action for the Form. |
void |
setAttribute(String name,
String value)
Set an attribute value. |
void |
setEnctype(String enctype)
Set the content encoding to be used on a post submit. |
void |
setFocus(String focus)
Set the name of the field to receive focus. |
void |
setLocation(String location)
Set the location hash to append to the url. |
void |
setMethod(String method)
Set the request method used when submitting this form. |
void |
setName(String name)
Set the attribute key under which our associated bean is stored. |
void |
setOnClick(String onclick)
Sets the onClick javascript event. |
void |
setOnDblClick(String ondblclick)
Sets the onDblClick javascript event. |
void |
setOnKeyDown(String onkeydown)
Sets the onKeyDown javascript event. |
void |
setOnKeyPress(String onkeypress)
Sets the onKeyPress javascript event. |
void |
setOnKeyUp(String onkeyup)
Sets the onKeyUp javascript event. |
void |
setOnMouseDown(String onmousedown)
Sets the onMouseDown javascript event. |
void |
setOnMouseMove(String onmousemove)
Sets the onMouseMove javascript event. |
void |
setOnMouseOut(String onmouseout)
Sets the onMouseOut javascript event. |
void |
setOnMouseOver(String onmouseover)
Sets the onMouseOver javascript event. |
void |
setOnMouseUp(String onmouseup)
Sets the onMouseUp javascript event. |
void |
setOnReset(String onReset)
Sets the onReset javascript event. |
void |
setOnSubmit(String onSubmit)
Sets the onSubmit javascript event. |
void |
setScope(String scope)
Sets the scope (request or session) under which the associated bean is stored. |
void |
setStyle(String style)
Sets the style of the rendered html tag. |
void |
setStyleClass(String styleClass)
Sets the style class of the rendered html tag. |
void |
setTabindex(String tabindex)
Sets the tabIndex of the rendered html tag. |
void |
setTagId(String tagID)
Set the ID of the form. |
void |
setTarget(String target)
Sets the window target. |
void |
setType(String type)
Sets the Java class name of the bean to be created, if necessary. |
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport |
---|
doInitBody, getBodyContent, getPreviousOut, setBodyContent |
Methods inherited from class javax.servlet.jsp.tagext.TagSupport |
---|
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setParent, setValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.servlet.jsp.tagext.Tag |
---|
getParent, setParent |
Field Detail |
---|
protected org.apache.struts.config.ModuleConfig appConfig
protected String enctype
protected String focus
protected String location
protected org.apache.struts.action.ActionMapping mapping
protected String method
protected String name
protected String scope
protected org.apache.struts.action.ActionServlet servlet
servlet
property on any form bean that
we create).
protected String target
protected String text
protected String beanName
ActionMapping
otherwise.
protected String beanType
ActionMapping
otherwise.
protected String beanScope
ActionMapping
otherwise.
protected String type
Constructor Detail |
---|
public Form()
Method Detail |
---|
public String getTagName()
getTagName
in class AbstractBaseTag
public void setAttribute(String name, String value) throws javax.servlet.jsp.JspException
name
represents
the name of the attribute.
The value
represents the value and may contain
a netui expression. This method may result in errors being generated.
This requires that the tag buffer its body and
write attributes in the end tag. For the form tag it is not legal to set
the id
, name
, action
, or method
attributes with this method.
setAttribute
in interface IAttributeConsumer
name
- The name of the attribute. This value may not be null or the empty string.value
- The value of the attribute. This may contain a netui expression.
javax.servlet.jsp.JspException
- A JspException may be thrown if there is an error setting the attribute.public String getAction()
public void setAction(String action)
action
- - the name of the action to set for the Form.public String getEnctype()
public void setEnctype(String enctype)
enctype
- - the content encoding type.public String getRealName()
public void generateRealName()
public String getFocus()
public void setFocus(String focus)
focus
- - the focus field name.tagID
of an input field which should receive initial focus.public String getLocation()
public void setLocation(String location)
location
- - the location hashpublic String getMethod()
public void setMethod(String method)
method
- - the request methodpublic String getName()
public void setName(String name)
name
- - the attribute key namescope
attribute.public String getOnReset()
public void setOnReset(String onReset)
onReset
- - the onReset event.public String getOnSubmit()
public void setOnSubmit(String onSubmit)
onSubmit
- - the onReset event.public String getScope()
public void setScope(String scope)
scope
- - the scope.request
or session
) under which the associated Form Bean
used to populate the form input fields is stored.
Using the name
, type
and scope
attributes defines
the Form Bean used.public String getTagId()
public void setTagId(String tagID)
tagID
- - the ID.String value. Sets the id
(or name
) attribute of the rendered HTML tag.
Note that the real id attribute rendered in the browser may be
changed by the application container (for example, Portal containers may change
the rendered id value to ensure the uniqueness of
id's on the page). In this case, the real id rendered
in the browser may be looked up
through the JavaScript function getNetuiTagName( tagId, tag ).
For example, assume that some tag's tagId
attribute is set to foo
.
<netui:textBox tagId="foo" />
Then the following JavaScript function will return the real id attribute rendered in the browser:
getNetuiTagName( "foo", this )
To get a <netui:form> element and all of its children elements in JavaScript, use
the same JavaScript function getNetuiTagName( tagId, tag )
. For example,
assume that there is a <netui:form> whose
tagId attribute is set to bar
.
<netui:form tagId="bar" >
Then the following JavaScript function will return the <netui:form> element and its children (packaged as an array).
document[getNetuiTagName( "bar", this )]
To retreive the value entered into a <netui:textBox> within the <netui:form> tag, use the following JavaScript expression.
document[getNetuiTagName("bar", this)][getNetuiTagName("foo", this)].value
The second parameter ensures that the JavaScript function
begins its search within the correct Portlet scope. Pass the
JavaScript keyword this
as the second parameter.
For detailed information on using the function
getNetuiTagName( tagId, tag )
see
Using JavaScript in Page Flow and Portal Applications.
public String getTarget()
public void setTarget(String target)
target
- - the window target.public String getType()
public void setType(String type)
type
- - the class namename
and scope
attributes are set.
The Form Bean is then used to populate the form input fields.public void addParameter(String name, Object value) throws javax.servlet.jsp.JspException
addParameter
in interface URLParams
name
- - the name of the parameter to be added.value
- - the value of the parameter to be added (a String or String[]).
javax.servlet.jsp.JspException
public void addTagID(String tagID, String name)
tagID
- - the tagID of a child tag.name
- - the name of a child tag.public String getBeanName()
public int doStartTag() throws javax.servlet.jsp.JspException
doStartTag
in interface javax.servlet.jsp.tagext.Tag
doStartTag
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspException
- if a JSP exception has occurredpublic int doAfterBody() throws javax.servlet.jsp.JspException
doAfterBody
in interface javax.servlet.jsp.tagext.IterationTag
doAfterBody
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspException
- if a JSP exception has occurredpublic int doEndTag() throws javax.servlet.jsp.JspException
doEndTag
in interface javax.servlet.jsp.tagext.Tag
doEndTag
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspException
- if a JSP exception has occurredprotected void localRelease()
localRelease
in class AbstractBaseTag
protected void lookup() throws javax.servlet.jsp.JspException
name
, scope
, and
type
properties if necessary.
javax.servlet.jsp.JspException
- if a required value cannot be looked uppublic void setTabindex(String tabindex)
tabindex
- - the tab index.public String getTabindex()
public void setStyle(String style)
style
- - the html style.public String getStyle()
public void setStyleClass(String styleClass)
styleClass
- - the html style class.public String getStyleClass()
public String getOnClick()
public void setOnClick(String onclick)
onclick
- - the onClick event.public String getOnDblClick()
public void setOnDblClick(String ondblclick)
ondblclick
- - the onDblClick event.public String getOnKeyDown()
public void setOnKeyDown(String onkeydown)
onkeydown
- - the onKeyDown event.public String getOnKeyPress()
public void setOnKeyPress(String onkeypress)
onkeypress
- - the onKeyPress event.public String getOnKeyUp()
public void setOnKeyUp(String onkeyup)
onkeyup
- - the onKeyUp event.public String getOnMouseDown()
public void setOnMouseDown(String onmousedown)
onmousedown
- - the onMouseDown event.public String getOnMouseMove()
public void setOnMouseMove(String onmousemove)
onmousemove
- - the onMouseMove event.public String getOnMouseOut()
public void setOnMouseOut(String onmouseout)
onmouseout
- - the onMouseOut event.public String getOnMouseOver()
public void setOnMouseOver(String onmouseover)
onmouseover
- - the onMouseOver event.public String getOnMouseUp()
public void setOnMouseUp(String onmouseup)
onmouseup
- - the onMouseUp event.
|
BEA NetUI tags and APIs are included for backward compatibility only. For new applications, use the Beehive tags and APIs. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |