PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/googlecode/struts2yuiplugin/components/Div.java

http://struts2yuiplugin.googlecode.com/
Java | 168 lines | 113 code | 30 blank | 25 comment | 0 complexity | fd9e5e52ac0a06b6b3a19a485e7f879c MD5 | raw file
  1package com.googlecode.struts2yuiplugin.components;
  2
  3import com.opensymphony.xwork2.util.ValueStack;
  4import com.googlecode.struts2yuiplugin.tools.YUITools;
  5
  6import javax.servlet.http.HttpServletRequest;
  7import javax.servlet.http.HttpServletResponse;
  8
  9import org.apache.struts2.views.annotations.StrutsTagAttribute;
 10import org.apache.struts2.views.annotations.StrutsTag;
 11
 12/**
 13 * A div that can load its own HTML content via XHR
 14 */
 15@StrutsTag(name = "div", tldTagClass = "com.googlecode.struts2yuiplugin.views.jsp.ui.DivTag", description = "Renders a div with content loaded via XHR")
 16public class Div extends ClosingYUIBean implements XHRComponent, OGNLEvaluator {
 17
 18    public static final String OPEN_TEMPLATE = "yuidiv";
 19    public static final String TEMPLATE = OPEN_TEMPLATE +"-close";
 20
 21    private XHRSupport xhrSupport;
 22
 23    public Div(ValueStack valueStack, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
 24        super(valueStack, httpServletRequest, httpServletResponse);
 25        xhrSupport = new XHRSupport(this);
 26    }
 27
 28    @Override
 29    public void evaluateParams() {
 30        super.evaluateParams();
 31        xhrSupport.evaluateParams(this);
 32
 33        populateOnLoadListenerName();
 34        addParameter("target", getId()); // target is self
 35    }
 36
 37    /**
 38      * Generate the javascript onload listener name if not explictly specified
 39      * The name is generated from the id but sanitized for javascript
 40      */
 41    private void populateOnLoadListenerName() {
 42        String onLoadListener = YUITools.sanitizeForJavascript(getId()+"OnLoad");
 43        addParameter("onLoadListener", onLoadListener);
 44    }
 45
 46    public String getDefaultOpenTemplate() {
 47        return OPEN_TEMPLATE;
 48    }
 49
 50    protected String getDefaultTemplate() {
 51        return TEMPLATE;
 52    }
 53
 54    @Override
 55    @StrutsTagAttribute(description = "Mandatory id attribute", required = true, rtexprvalue = true)
 56    public void setId(String id) {
 57        super.setId(id);
 58    }
 59
 60    /**
 61     * The optional ID of the form to include in the request
 62     */
 63    @StrutsTagAttribute(description = "The ID of the form to include in the request", required = false)
 64    public void setFormId(String formId) {
 65        xhrSupport.setFormId(formId);
 66    }
 67
 68    /**
 69     * Optional href to send the request to.  If not provided, the form's action will used
 70     */
 71    @StrutsTagAttribute(description = "The URL to make the request to if other than the form's action", required = false, rtexprvalue = true)
 72    public void setHref(String href) {
 73        xhrSupport.setHref(href);
 74    }
 75
 76    /**
 77     * HTTP method to use when HREF is specified. Default is GET
 78     */
 79    @StrutsTagAttribute(description = "The HTTP method to use", required = false, defaultValue = "GET")
 80    public void setMethod(String method) {
 81        xhrSupport.setMethod(method);
 82    }
 83
 84     /**
 85     * The name of an alternative javascript callback for the YUI Connection Manager's response
 86     */
 87    @StrutsTagAttribute(description = "An alternative javascript callback for the YUI Connection Manager's response", required = false)
 88    public void setCallback(String callback) {
 89        xhrSupport.setCallback(callback);
 90    }
 91
 92    @Override
 93    @StrutsTagAttribute(description = "Not supported")
 94    public void setTitle(String title) {
 95        super.setTitle(title);
 96    }
 97
 98    @Override
 99    @StrutsTagAttribute(description = "Not supported")
100    public void setDisabled(String disabled) {
101        super.setDisabled(disabled);
102    }
103
104    @Override
105    @StrutsTagAttribute(description = "Not supported")
106    public void setLabel(String label) {
107        super.setLabel(label);
108    }
109
110    @Override
111    @StrutsTagAttribute(description = "Not supported")
112    public void setLabelSeparator(String labelseparator) {
113        super.setLabelSeparator(labelseparator);
114    }
115
116    @Override
117    @StrutsTagAttribute(description = "Not supported")
118    public void setLabelposition(String labelPosition) {
119        super.setLabelposition(labelPosition);
120    }
121
122    @Override
123    @StrutsTagAttribute(description = "Not supported")
124    public void setRequiredposition(String requiredposition) {
125        super.setRequiredposition(requiredposition);    
126    }
127
128    @Override
129    @StrutsTagAttribute(description = "Not supported")
130    public void setRequired(String required) {
131        super.setRequired(required);
132    }
133
134    @Override
135    @StrutsTagAttribute(description = "Not supported")
136    public void setName(String name) {
137        super.setName(name);
138    }
139
140    @Override
141    @StrutsTagAttribute(description = "Not supported")
142    public void setValue(String value) {
143        super.setValue(value);
144    }
145
146    @Override
147    @StrutsTagAttribute(description = "Not supported")
148    public void setTabindex(String tabindex) {
149        super.setTabindex(tabindex);
150    }
151
152    @Override
153    @StrutsTagAttribute(description = "Not supported")
154    public void setAccesskey(String accesskey) {
155        super.setAccesskey(accesskey);
156    }
157
158    /**
159     * Evaluates the OGNL expression
160     *
161     * @param expr OGNL expression.
162     * @return the String value found.
163     */
164    public String evaluateExpression(String expr) {
165        return super.findString(expr);
166    }
167
168}