PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/googlecode/struts2yuiplugin/views/jsp/ui/SubmitTag.java

http://struts2yuiplugin.googlecode.com/
Java | 83 lines | 63 code | 16 blank | 4 comment | 7 complexity | 1abc64d465d0bcdeedcfa834f3f537e2 MD5 | raw file
 1package com.googlecode.struts2yuiplugin.views.jsp.ui;
 2
 3import com.googlecode.struts2yuiplugin.components.Submit;
 4import com.googlecode.struts2yuiplugin.components.XHRComponent;
 5import com.opensymphony.xwork2.util.ValueStack;
 6import org.apache.struts2.components.Component;
 7import org.apache.struts2.views.jsp.ui.FormTag;
 8
 9import javax.servlet.http.HttpServletRequest;
10import javax.servlet.http.HttpServletResponse;
11import javax.servlet.jsp.tagext.Tag;
12
13/**
14 * Tag for a YUI button widget of type Submit
15 */
16public class SubmitTag extends AbstractYUITag implements XHRComponent {
17
18    private String formId;
19    private String href;
20    private String method;
21    private String target;
22    private String callback;
23    private String clickListener;
24
25    @Override
26    protected void populateParams() {
27        super.populateParams();
28
29        Submit button = (Submit) this.component;
30        if (formId == null) {
31            formId = findParentFormId();
32        }
33        button.setFormId(formId);
34        button.setHref(href);
35        button.setMethod(method);
36        button.setTarget(target);
37        button.setCallback(callback);
38        button.setClickListener(clickListener);
39    }
40
41    @Override
42    public Component getBean(ValueStack valueStack, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
43        return new Submit(valueStack, httpServletRequest, httpServletResponse);
44    }
45
46
47    /** Lookup the form that contains this submit button. It will only be found it it's a JSP tag */
48    private String findParentFormId() {
49        String formId = null;
50        Tag parent = this;
51        while (((parent = parent.getParent()) != null) && (formId == null)) {
52            if (FormTag.class.isAssignableFrom(parent.getClass())) {
53                formId = ((FormTag) parent).getId();
54            }
55        }
56        return formId;
57    }
58
59    public void setFormId(String formId) {
60        this.formId = formId;
61    }
62
63    public void setHref(String href) {
64        this.href = href;
65    }
66
67    public void setMethod(String method) {
68        this.method = method;
69    }
70
71    public void setTarget(String target) {
72        this.target = target;
73    }
74
75    public void setCallback(String callback) {
76        this.callback = callback;
77    }
78
79    public void setClickListener(String clickListener) {
80        this.clickListener = clickListener;
81    }
82
83}