001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: ActionFormTag.java 6400 2007-12-06 14:41:00Z docentt $
004: */
005: package org.gridsphere.provider.portletui.tags;
006:
007: import org.gridsphere.portlet.impl.RenderResponseImpl;
008: import org.gridsphere.portlet.impl.SportletProperties;
009:
010: import javax.portlet.RenderResponse;
011: import javax.servlet.jsp.JspException;
012: import javax.servlet.jsp.JspTagException;
013: import javax.servlet.jsp.JspWriter;
014: import javax.servlet.jsp.PageContext;
015: import java.util.ArrayList;
016:
017: /**
018: * The <code>ActionFormTag</code> provides a UI form tag that can also include <code>ActionParam</code> tags
019: * nested within it.
020: */
021: public class ActionFormTag extends ActionTag {
022:
023: protected boolean isMultipart = false;
024: // 'POST' replaced by 'post' for XHTML 1.0 Strict compliance
025: protected String method = "post";
026:
027: /**
028: * Sets the form method attribute e.g. POST
029: *
030: * @param method the form method
031: */
032: public void setMethod(String method) {
033: this .method = method;
034: }
035:
036: /**
037: * Returns the form method attribute e.g. POST
038: *
039: * @return the form method
040: */
041: public String getMethod() {
042: return method;
043: }
044:
045: /**
046: * Sets whether this form supports multi-part form data as in the case of file uploading
047: *
048: * @param isMultipart is true if this form supports multi-part form data, false otherwise
049: */
050: public void setMultiPartFormData(boolean isMultipart) {
051: this .isMultipart = isMultipart;
052: }
053:
054: /**
055: * Returns whether this form supports multi-part form data as in the case of file uploading
056: *
057: * @return true if this form supports multi-part form data, false otherwise
058: */
059: public boolean getMultiPartFormData() {
060: return isMultipart;
061: }
062:
063: public int doStartTag() throws JspException {
064: paramBeans = new ArrayList();
065: return EVAL_BODY_BUFFERED;
066: }
067:
068: public int doEndTag() throws JspException {
069: try {
070: JspWriter out = pageContext.getOut();
071:
072: out.print("<form ");
073: //if (onSubmit != null) out.print(" onsubmit=\"" + onSubmit + "\" ");
074:
075: out.print("action=\"");
076:
077: String actionStr = createActionURI();
078:
079: out.print(actionStr);
080:
081: out.print("\" method=\"");
082: out.print(method);
083: out.print("\"");
084: if (isMultipart) {
085: out.print(" enctype=\"multipart/form-data\"");
086: }
087: if (name == null) {
088: name = "form" + this .getUniqueId("gs_formNumber");
089: }
090:
091: if (this .cssStyle != null) {
092: out.print(" style=\"" + this .cssStyle + "\"");
093: }
094: if (this .cssClass != null) {
095: out.print(" class=\"" + this .cssClass + "\"");
096: }
097:
098: out.print(" id=\"" + name + "\"");
099: out.print(" name=\"" + name + "\"");
100: if (onSubmit == null) {
101: out.print(" onsubmit=\"return validate( " + name
102: + " );\" ");
103: } else {
104: out.print(" onsubmit=\"" + onSubmit + "\" ");
105: }
106: if (onReset != null)
107: out.print(" onreset=\"" + onReset + "\" ");
108: out.println(">");
109:
110: // write out rest of body
111: bodyContent.writeOut(getPreviousOut());
112: // end form
113: out.print("</form>");
114: } catch (Exception e) {
115: throw new JspTagException(e.getMessage());
116: }
117: // nulling these out is ABSOLUTELY NECESSARY or weird
118: // interactins happen with actionsubmit nested inside actionform!
119: name = null;
120: action = null;
121: return EVAL_PAGE;
122: }
123:
124: public void release() {
125: super.release();
126: }
127:
128: }
|