001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: ActionSubmitTag.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005: package org.gridsphere.provider.portletui.tags;
006:
007: import org.gridsphere.portlet.impl.SportletProperties;
008: import org.gridsphere.provider.portletui.beans.ActionSubmitBean;
009: import org.gridsphere.provider.portletui.beans.ParamBean;
010:
011: import javax.servlet.jsp.JspException;
012: import javax.servlet.jsp.JspWriter;
013:
014: /**
015: * An <code>ActionSubmitTag</code> provides a button element that includes a <code>DefaultPortletAction</code> and may
016: * also include nested <code>ParamTag</code>s
017: */
018: public class ActionSubmitTag extends ActionTag {
019:
020: protected ActionSubmitBean actionSubmitBean = null;
021: protected String imageSrc = null;
022:
023: public String getImageSrc() {
024: return imageSrc;
025: }
026:
027: public void setImageSrc(String imageSrc) {
028: this .imageSrc = imageSrc;
029: }
030:
031: public int doStartTag() throws JspException {
032: if (!beanId.equals("")) {
033: actionSubmitBean = (ActionSubmitBean) getTagBean();
034: if (actionSubmitBean == null) {
035: actionSubmitBean = new ActionSubmitBean(beanId);
036: } else {
037: if (actionSubmitBean.getAction() != null) {
038: action = actionSubmitBean.getAction();
039: }
040: if (actionSubmitBean.getValue() != null) {
041: value = actionSubmitBean.getValue();
042: }
043: if (actionSubmitBean.getKey() != null) {
044: key = actionSubmitBean.getKey();
045: }
046: if (actionSubmitBean.getParamBeanList() != null) {
047: paramBeans = actionSubmitBean.getParamBeanList();
048: }
049: if (actionSubmitBean.getOnClick() != null) {
050: onClick = actionSubmitBean.getOnClick();
051: }
052: }
053: } else {
054: actionSubmitBean = new ActionSubmitBean();
055: }
056:
057: if (onClick != null)
058: actionSubmitBean.setOnClick(onClick);
059:
060: actionSubmitBean.setName(createActionURI());
061: actionSubmitBean.setUseAjax(useAjax);
062:
063: if (anchor != null)
064: actionSubmitBean.setAnchor(anchor);
065: if (imageSrc != null)
066: actionSubmitBean.setImageSrc(imageSrc);
067:
068: if (key != null) {
069: value = getLocalizedText(key);
070: actionSubmitBean.setKey(key);
071: }
072:
073: if (!beanId.equals("")) {
074: this .updateBaseComponentBean(actionSubmitBean);
075: } else {
076: this .setBaseComponentBean(actionSubmitBean);
077: }
078:
079: if (action != null)
080: actionSubmitBean.setAction(action);
081:
082: if (cssStyle != null) {
083: actionSubmitBean.setCssStyle(cssStyle);
084: }
085: if (cssClass != null) {
086: actionSubmitBean.setCssClass(cssClass);
087: }
088:
089: Object parentTag = getParent();
090: if (parentTag instanceof ContainerTag) {
091: ContainerTag containerTag = (ContainerTag) parentTag;
092: containerTag.addTagBean(actionSubmitBean);
093: }
094: return EVAL_BODY_INCLUDE;
095: }
096:
097: public int doEndTag() throws JspException {
098:
099: for (ParamBean paramBean : paramBeans) {
100: ParamBean pbean = (ParamBean) paramBean;
101: portletPhase
102: .addParameter(pbean.getName(), pbean.getValue());
103: }
104:
105: String actionURI = createActionURI().toString();
106: actionSubmitBean.setName(actionURI);
107:
108: if (portletPhase != null)
109: actionSubmitBean.setAction(portletPhase.toString());
110:
111: if (pageContext.getRequest().getAttribute(
112: SportletProperties.USE_AJAX) != null) {
113: String paction = ((!action.equals("")) ? "&"
114: + portletPhase.toString() : "");
115: String portlet = (String) pageContext.getRequest()
116: .getAttribute(SportletProperties.PORTLET_NAME);
117: String compname = (String) pageContext.getRequest()
118: .getAttribute(SportletProperties.COMPONENT_NAME);
119: actionSubmitBean.setUseAjax(true);
120: actionSubmitBean
121: .setOnClick("GridSphereAjaxHandler2.startRequest('"
122: + portlet + "', '" + compname + "', '"
123: + paction + "');");
124: }
125:
126: if (useAjax) {
127: String cid = (String) pageContext.getRequest()
128: .getAttribute(SportletProperties.COMPONENT_ID);
129: String paction = ((!action.equals("")) ? "&"
130: + portletPhase.toString() : "");
131: actionSubmitBean
132: .setOnClick("GridSphereAjaxHandler.startRequest('"
133: + cid + "', '" + paction + "');");
134: }
135:
136: if ((bodyContent != null) && (value == null)) {
137: actionSubmitBean.setValue(bodyContent.getString());
138: }
139:
140: try {
141: JspWriter out = pageContext.getOut();
142: out.print(actionSubmitBean.toEndString());
143: } catch (Exception e) {
144: throw new JspException(e);
145: }
146:
147: return EVAL_PAGE;
148: }
149:
150: public void release() {
151: super.release();
152: actionSubmitBean = null;
153: }
154:
155: }
|