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

http://struts2yuiplugin.googlecode.com/ · Java · 152 lines · 115 code · 28 blank · 9 comment · 5 complexity · 34a7c33a5d9f3a7ccf57371d706c3507 MD5 · raw file

  1. package com.googlecode.struts2yuiplugin.components;
  2. import com.googlecode.struts2yuiplugin.tools.YUITools;
  3. import com.opensymphony.xwork2.util.ValueStack;
  4. import org.apache.struts2.components.UIBean;
  5. import org.apache.struts2.views.annotations.StrutsTagAttribute;
  6. import javax.servlet.http.HttpServletRequest;
  7. import javax.servlet.http.HttpServletResponse;
  8. /**
  9. * YUIBean is a standard base-class for the YUI components.
  10. * The main purpose is to remove the attributes inherited from UIBean and to support the 'noscript' feature
  11. *
  12. */
  13. public abstract class YUIBean extends UIBean {
  14. private String widget;
  15. private String noscript;
  16. protected YUIBean(ValueStack valueStack, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
  17. super(valueStack, httpServletRequest, httpServletResponse);
  18. }
  19. @Override
  20. public void evaluateParams() {
  21. super.evaluateParams();
  22. populateWidgetName();
  23. if (noscript != null) {
  24. this.addParameter("noscript", findValue(noscript, Boolean.class));
  25. }
  26. this.addParameter("defaultHandler", true);
  27. }
  28. /**
  29. * Generate the javascript name for this widget if not explictly specified.
  30. * The name is generated from the escaped Id generated by UIBean
  31. */
  32. private void populateWidgetName() {
  33. String widgetName;
  34. if (widget != null) {
  35. widgetName = widget;
  36. } else {
  37. widgetName = YUITools.sanitizeForJavascript(getId()+"Widget");
  38. }
  39. addParameter("widget", widgetName);
  40. }
  41. @Override
  42. @StrutsTagAttribute(description = "HTML id attribute", rtexprvalue = true)
  43. public void setId(String id) {
  44. super.setId(id);
  45. }
  46. @StrutsTagAttribute(description = "A unique javascript name to assign to this widget. Use to specify a namespace.", required = false)
  47. public void setWidget(String widget) {
  48. this.widget = widget;
  49. }
  50. @StrutsTagAttribute(description = "If true the tag will not include any associated javascript", required = false, defaultValue = "false")
  51. public void setNoscript(String noscript) {
  52. this.noscript = noscript;
  53. }
  54. @Override
  55. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  56. public void setOnclick(String string) {
  57. super.setOnclick(string);
  58. }
  59. @Override
  60. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  61. public void setOndblclick(String string) {
  62. super.setOndblclick(string);
  63. }
  64. @Override
  65. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  66. public void setOnmousedown(String string) {
  67. super.setOnmousedown(string);
  68. }
  69. @Override
  70. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  71. public void setOnmouseup(String string) {
  72. super.setOnmouseup(string);
  73. }
  74. @Override
  75. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  76. public void setOnmouseover(String string) {
  77. super.setOnmouseover(string);
  78. }
  79. @Override
  80. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  81. public void setOnmousemove(String string) {
  82. super.setOnmousemove(string);
  83. }
  84. @Override
  85. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  86. public void setOnmouseout(String string) {
  87. super.setOnmouseout(string);
  88. }
  89. @Override
  90. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  91. public void setOnfocus(String string) {
  92. super.setOnfocus(string);
  93. }
  94. @Override
  95. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  96. public void setOnblur(String string) {
  97. super.setOnblur(string);
  98. }
  99. @Override
  100. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  101. public void setOnkeypress(String string) {
  102. super.setOnkeypress(string);
  103. }
  104. @Override
  105. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  106. public void setOnkeydown(String string) {
  107. super.setOnkeydown(string);
  108. }
  109. @Override
  110. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  111. public void setOnkeyup(String string) {
  112. super.setOnkeyup(string);
  113. }
  114. @Override
  115. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  116. public void setOnselect(String string) {
  117. super.setOnselect(string);
  118. }
  119. @Override
  120. @StrutsTagAttribute(description = "Not supported - use the YUI event utility")
  121. public void setOnchange(String string) {
  122. super.setOnchange(string);
  123. }
  124. }