/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

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