| Method from org.apache.struts.taglib.html.FormTag Detail: |
public int doEndTag() throws JspException {
// Remove the page scope attributes we created
pageContext.removeAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE);
pageContext.removeAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE);
// Render a tag representing the end of our current form
StringBuffer results = new StringBuffer("< /form >");
// Render JavaScript to set the input focus if required
if (this.focus != null) {
results.append(this.renderFocusJavascript());
}
// Print this value to our output writer
JspWriter writer = pageContext.getOut();
try {
writer.print(results.toString());
} catch (IOException e) {
throw new JspException(messages.getMessage("common.io", e.toString()));
}
// Continue processing this page
return (EVAL_PAGE);
}
Render the end of this form. |
public int doStartTag() throws JspException {
// Look up the form bean name, scope, and type if necessary
this.lookup();
// Create an appropriate "form" element based on our parameters
StringBuffer results = new StringBuffer();
results.append(this.renderFormStartElement());
results.append(this.renderToken());
TagUtils.getInstance().write(pageContext, results.toString());
// Store this tag itself as a page attribute
pageContext.setAttribute(Constants.FORM_KEY, this, PageContext.REQUEST_SCOPE);
this.initFormBean();
return (EVAL_BODY_INCLUDE);
}
Render the beginning of this form. |
public String getAcceptCharset() {
return acceptCharset;
}
Return the list of character encodings accepted. |
public String getAction() {
return (this.action);
}
Return the action URL to which this form should be submitted. |
public String getBeanName() {
// ------------------------------------------------------------- Properties
return beanName;
}
Return the name of the form bean corresponding to this tag. There is
no corresponding setter method; this method exists so that the nested
tag classes can obtain the actual bean name derived from other
attributes of the tag. |
public String getEnctype() {
return (this.enctype);
}
Return the content encoding used when submitting this form. |
public String getFocus() {
return (this.focus);
}
Return the focus field name for this form. |
public String getFocusIndex() {
return focusIndex;
}
|
public String getMethod() {
return (this.method);
}
Return the request method used when submitting this form. |
public String getOnreset() {
return (this.onreset);
}
Return the onReset event script. |
public String getOnsubmit() {
return (this.onsubmit);
}
Return the onSubmit event script. |
public boolean getScriptLanguage() {
return this.scriptLanguage;
}
Gets whether or not the focus script's <script> element will include the
language attribute. |
public String getStyle() {
return (this.style);
}
Return the style attribute for this tag. |
public String getStyleClass() {
return (this.styleClass);
}
Return the style class for this tag. |
public String getStyleId() {
return (this.styleId);
}
Return the style identifier for this tag. |
public String getTarget() {
return (this.target);
}
Return the window target. |
protected void initFormBean() throws JspException {
int scope = PageContext.SESSION_SCOPE;
if ("request".equalsIgnoreCase(beanScope)) {
scope = PageContext.REQUEST_SCOPE;
}
Object bean = pageContext.getAttribute(beanName, scope);
if (bean == null) {
// New and improved - use the values from the action mapping
bean =
RequestUtils.createActionForm(
(HttpServletRequest) pageContext.getRequest(),
mapping,
moduleConfig,
servlet);
if (bean instanceof ActionForm) {
((ActionForm) bean).reset(mapping, (HttpServletRequest) pageContext.getRequest());
}
if (bean == null) {
throw new JspException(messages.getMessage("formTag.create", beanType));
}
pageContext.setAttribute(beanName, bean, scope);
}
pageContext.setAttribute(Constants.BEAN_KEY, bean, PageContext.REQUEST_SCOPE);
}
Locate or create the bean associated with our form. |
public boolean isDisabled() {
return disabled;
}
Returns the disabled event handler. |
public boolean isReadonly() {
return readonly;
}
Returns the readonly event handler. |
protected void lookup() throws JspException {
// Look up the module configuration information we need
moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext);
if (moduleConfig == null) {
JspException e = new JspException(messages.getMessage("formTag.collections"));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
servlet =
(ActionServlet) pageContext.getServletContext().getAttribute(
Globals.ACTION_SERVLET_KEY);
// Look up the action mapping we will be submitting to
String mappingName = TagUtils.getInstance().getActionMappingName(action);
mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
if (mapping == null) {
JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Look up the form bean definition
FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(mapping.getName());
if (formBeanConfig == null) {
JspException e =
new JspException(messages.getMessage("formTag.formBean", mapping.getName(), action));
pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
throw e;
}
// Calculate the required values
beanName = mapping.getAttribute();
beanScope = mapping.getScope();
beanType = formBeanConfig.getType();
}
Look up values for the name, scope, and
type properties if necessary. |
public void release() {
super.release();
action = null;
moduleConfig = null;
enctype = null;
disabled = false;
focus = null;
focusIndex = null;
mapping = null;
method = null;
onreset = null;
onsubmit = null;
readonly = false;
servlet = null;
style = null;
styleClass = null;
styleId = null;
target = null;
acceptCharset = null;
}
Release any acquired resources. |
protected void renderAction(StringBuffer results) {
HttpServletResponse response =
(HttpServletResponse) this.pageContext.getResponse();
results.append(" action=\"");
results.append(
response.encodeURL(
TagUtils.getInstance().getActionMappingURL(
this.action,
this.pageContext)));
results.append("\"");
}
Renders the action attribute |
protected void renderAttribute(StringBuffer results,
String attribute,
String value) {
if (value != null) {
results.append(" ");
results.append(attribute);
results.append("=\"");
results.append(value);
results.append("\"");
}
}
Renders attribute="value" if not null |
protected String renderFocusJavascript() {
StringBuffer results = new StringBuffer();
results.append(lineEnd);
results.append("< script type=\"text/javascript\"");
if (!this.isXhtml() && this.scriptLanguage) {
results.append(" language=\"JavaScript\"");
}
results.append(" >");
results.append(lineEnd);
// xhtml script content shouldn't use the browser hiding trick
if (!this.isXhtml()) {
results.append(" < !--");
results.append(lineEnd);
}
// Construct the control name that will receive focus.
// This does not include any index.
StringBuffer focusControl = new StringBuffer("document.forms[\"");
focusControl.append(beanName);
focusControl.append("\"].elements[\"");
focusControl.append(this.focus);
focusControl.append("\"]");
results.append(" var focusControl = ");
results.append(focusControl.toString());
results.append(";");
results.append(lineEnd);
results.append(lineEnd);
results.append(" if (focusControl.type != \"hidden\" && !focusControl.disabled) {");
results.append(lineEnd);
// Construct the index if needed and insert into focus statement
String index = "";
if (this.focusIndex != null) {
StringBuffer sb = new StringBuffer("[");
sb.append(this.focusIndex);
sb.append("]");
index = sb.toString();
}
results.append(" focusControl");
results.append(index);
results.append(".focus();");
results.append(lineEnd);
results.append(" }");
results.append(lineEnd);
if (!this.isXhtml()) {
results.append(" // -- >");
results.append(lineEnd);
}
results.append("< /script >");
results.append(lineEnd);
return results.toString();
}
Generates javascript to set the initial focus to the form element given in the
tag's "focus" attribute. |
protected String renderFormStartElement() {
StringBuffer results = new StringBuffer("< form");
// render attributes
renderName(results);
renderAttribute(results, "method", getMethod() == null ? "post" : getMethod());
renderAction(results);
renderAttribute(results, "accept-charset", getAcceptCharset());
renderAttribute(results, "class", getStyleClass());
renderAttribute(results, "enctype", getEnctype());
renderAttribute(results, "onreset", getOnreset());
renderAttribute(results, "onsubmit", getOnsubmit());
renderAttribute(results, "style", getStyle());
renderAttribute(results, "target", getTarget());
// Hook for additional attributes
renderOtherAttributes(results);
results.append(" >");
return results.toString();
}
Generates the opening <form> element with appropriate
attributes. |
protected void renderName(StringBuffer results) {
if (this.isXhtml()) {
if (getStyleId() == null) {
renderAttribute(results, "id", beanName);
} else {
renderAttribute(results, "id", getStyleId());
}
} else {
renderAttribute(results, "name", beanName);
renderAttribute(results, "id", getStyleId());
}
}
Renders the name of the form. If XHTML is set to true, the name will
be rendered as an 'id' attribute, otherwise as a 'name' attribute. |
protected void renderOtherAttributes(StringBuffer results) {
}
'Hook' to enable this tag to be extended and
additional attributes added. |
protected String renderToken() {
StringBuffer results = new StringBuffer();
HttpSession session = pageContext.getSession();
if (session != null) {
String token =
(String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
if (token != null) {
results.append("< div >< input type=\"hidden\" name=\"");
results.append(Constants.TOKEN_KEY);
results.append("\" value=\"");
results.append(token);
if (this.isXhtml()) {
results.append("\" / >");
} else {
results.append("\" >");
}
results.append("< /div >");
}
}
return results.toString();
}
Generates a hidden input field with token information, if any. The
field is added within a div element for HTML 4.01 Strict compliance. |
public void setAcceptCharset(String acceptCharset) {
this.acceptCharset= acceptCharset;
}
Set the list of character encodings accepted. |
public void setAction(String action) {
this.action = action;
}
Set the action URL to which this form should be submitted. |
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
Sets the disabled event handler. |
public void setEnctype(String enctype) {
this.enctype = enctype;
}
Set the content encoding used when submitting this form. |
public void setFocus(String focus) {
this.focus = focus;
}
Set the focus field name for this form. |
public void setFocusIndex(String focusIndex) {
this.focusIndex = focusIndex;
}
|
public void setMethod(String method) {
this.method = method;
}
Set the request method used when submitting this form. |
public void setOnreset(String onReset) {
this.onreset = onReset;
}
Set the onReset event script. |
public void setOnsubmit(String onSubmit) {
this.onsubmit = onSubmit;
}
Set the onSubmit event script. |
public void setReadonly(boolean readonly) {
this.readonly = readonly;
}
Sets the readonly event handler. |
public void setScriptLanguage(boolean scriptLanguage) {
this.scriptLanguage = scriptLanguage;
}
Sets whether or not the focus script's <script> element will include the
language attribute. |
public void setStyle(String style) {
this.style = style;
}
Set the style attribute for this tag. |
public void setStyleClass(String styleClass) {
this.styleClass = styleClass;
}
Set the style class for this tag. |
public void setStyleId(String styleId) {
this.styleId = styleId;
}
Set the style identifier for this tag. |
public void setTarget(String target) {
this.target = target;
}
|