UIBean.java

Index Score
org.apache.struts2.components
Struts 2

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DOC_COMMENTNumber of javadoc comment lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
COMMENTSComment lines
SIZESize of the file in bytes
CYCLOMATICCyclomatic complexity
LINESNumber of lines in the source file
BLOCKSNumber of blocks
JAVA0034JAVA0034 Missing braces in if statement
FUNCTIONSNumber of function declarations
JAVA0179JAVA0179 Local variable hides visible field
COMPARISONSNumber of comparison operators
UNIQUE_OPERANDSNumber of unique operands
OPERATORSNumber of operators
PROGRAM_VOCABHalstead program vocabulary
PARAMSNumber of formal parameter declarations
PROGRAM_LENGTHHalstead program length
LINE_COMMENTNumber of line comments
LOCLines of code
ELOCEffective lines of code
INTERFACE_COMPLEXITYInterface complexity
OPERANDSNumber of operands
LOGICAL_LINESNumber of statements
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
JAVA0075JAVA0075 Method parameter hides field
WHITESPACENumber of whitespace lines
EXITSProcedure exits
JAVA0144JAVA0144 Line exceeds maximum M characters
UNIQUE_OPERATORSNumber of unique operators
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0123JAVA0123 Use all three components of for loop
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
LOOPSNumber of loops
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0145JAVA0145 Tab character used in source file
/* * $Id: UIBean.java 591174 2007-11-02 00:31:53Z husted $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.struts2.components; import java.io.Writer; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.StrutsConstants; import org.apache.struts2.components.template.Template; import org.apache.struts2.components.template.TemplateEngine; import org.apache.struts2.components.template.TemplateEngineManager; import org.apache.struts2.components.template.TemplateRenderingContext; import org.apache.struts2.views.annotations.StrutsTagAttribute; import org.apache.struts2.views.util.ContextUtil; import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; /** * UIBean is the standard superclass of all Struts UI componentns. * It defines common Struts and html properties all UI components should present for usage. * * <!-- START SNIPPET: templateRelatedAttributes --> * * <table border="1"> * <thead> * <tr> * <td>Attribute</td> * <td>Theme</td> * <td>Data Types</td> * <td>Description</td> * </tr> * </thead> * <tbody> * <tr> * <td>templateDir</td> * <td>n/a</td> * <td>String</td> * <td>define the template directory</td> * </td> * <tr> * <td>theme</td> * <td>n/a</td> * <td>String</td> * <td>define the theme name</td> * </td> * <tr> * <td>template</td> * <td>n/a</td> * <td>String</td> * <td>define the template name</td> * </td> * </tbody> * </table> * * <!-- END SNIPPET: templateRelatedAttributes --> * * <p/> * * <!-- START SNIPPET: generalAttributes --> * * <table border="1"> * <thead> * <tr> * <td>Attribute</td> * <td>Theme</td> * <td>Data Types</td> * <td>Description</td> * </tr> * </thead> * <tbody> * <tr> * <td>cssClass</td> * <td>simple</td> * <td>String</td> * <td>define html class attribute</td> * </tr> * <tr> * <td>cssStyle</td> * <td>simple</td> * <td>String</td> * <td>define html style attribute</td> * </tr> * <tr> * <td>title</td> * <td>simple</td> * <td>String</td> * <td>define html title attribute</td> * </tr> * <tr> * <td>disabled</td> * <td>simple</td> * <td>String</td> * <td>define html disabled attribute</td> * </tr> * <tr> * <td>label</td> * <td>xhtml</td> * <td>String</td> * <td>define label of form element</td> * </tr> * <tr> * <td>labelPosition</td> * <td>xhtml</td> * <td>String</td> * <td>define label position of form element (top/left), default to left</td> * </tr> * <tr> * <td>requiredposition</td> * <td>xhtml</td> * <td>String</td> * <td>define required label position of form element (left/right), default to right</td> * </tr> * <tr> * <td>name</td> * <td>simple</td> * <td>String</td> * <td>Form Element's field name mapping</td> * </tr> * <tr> * <td>required</td> * <td>xhtml</td> * <td>Boolean</td> * <td>add * to label (true to add false otherwise)</td> * </tr> * <tr> * <td>tabIndex</td> * <td>simple</td> * <td>String</td> * <td>define html tabindex attribute</td> * </tr> * <tr> * <td>value</td> * <td>simple</td> * <td>Object</td> * <td>define value of form element</td> * </tr> * </tbody> * </table> * * <!-- END SNIPPET: generalAttributes --> * * <p/> * * <!-- START SNIPPET: javascriptRelatedAttributes --> * * <table border="1"> * <thead> * <tr> * <td>Attribute</td> * <td>Theme</td> * <td>Data Types</td> * <td>Description</td> * </tr> * </thead> * <tbody> * <tr> * <td>onclick</td> * <td>simple</td> * <td>String</td> * <td>html javascript onclick attribute</td> * </tr> * <tr> * <td>ondblclick</td> * <td>simple</td> * <td>String</td> * <td>html javascript ondbclick attribute</td> * </tr> * <tr> * <td>onmousedown</td> * <td>simple</td> * <td>String</td> * <td>html javascript onmousedown attribute</td> * </tr> * <tr> * <td>onmouseup</td> * <td>simple</td> * <td>String</td> * <td>html javascript onmouseup attribute</td> * </tr> * <tr> * <td>onmouseover</td> * <td>simple</td> * <td>String</td> * <td>html javascript onmouseover attribute</td> * </tr> * <tr> * <td>onmouseout</td> * <td>simple</td> * <td>String</td> * <td>html javascript onmouseout attribute</td> * </tr> * <tr> * <td>onfocus</td> * <td>simple</td> * <td>String</td> * <td>html javascript onfocus attribute</td> * </tr> * <tr> * <td>onblur</td> * <td>simple</td> * <td>String</td> * <td>html javascript onblur attribute</td> * </tr> * <tr> * <td>onkeypress</td> * <td>simple</td> * <td>String</td> * <td>html javascript onkeypress attribute</td> * </tr> * <tr> * <td>onkeyup</td> * <td>simple</td> * <td>String</td> * <td>html javascript onkeyup attribute</td> * </tr> * <tr> * <td>onkeydown</td> * <td>simple</td> * <td>String</td> * <td>html javascript onkeydown attribute</td> * </tr> * <tr> * <td>onselect</td> * <td>simple</td> * <td>String</td> * <td>html javascript onselect attribute</td> * </tr> * <tr> * <td>onchange</td> * <td>simple</td> * <td>String</td> * <td>html javascript onchange attribute</td> * </tr> * </tbody> * </table> * * <!-- END SNIPPET: javascriptRelatedAttributes --> * * <p/> * * <!-- START SNIPPET: tooltipattributes --> * * <table border="1"> * <tr> * <td>Attribute</td> * <td>Data Type</td> * <td>Default</td> * <td>Description</td> * </tr> * <tr> * <td>tooltip</td> * <td>String</td> * <td>none</td> * <td>Set the tooltip of this particular component</td> * </tr> * <tr> * <td>jsTooltipEnabled</td> * <td>String</td> * <td>false</td> * <td>Enable js tooltip rendering</td> * </tr> * <tr> * <td>tooltipIcon</td> * <td>String</td> * <td>/struts/static/tooltip/tooltip.gif</td> * <td>The url to the tooltip icon</td> * <tr> * <td>tooltipDelay</td> * <td>String</td> * <td>500</td> * <td>Tooltip shows up after the specified timeout (miliseconds). A behavior similar to that of OS based tooltips.</td> * </tr> * <tr> * <td>key</td> * <td>simple</td> * <td>String</td> * <td>The name of the property this input field represents. This will auto populate the name, label, and value</td> * </tr> * </table> * * <!-- END SNIPPET: tooltipattributes --> * * * <!-- START SNIPPET: tooltipdescription --> * <b>tooltipConfig is deprecated, use individual tooltip configuration attributes instead </b> * * Every Form UI component (in xhtml / css_xhtml or any other that extends them) can * have tooltips assigned to them. The Form component's tooltip related attribute, once * defined, will be applied to all form UI components that are created under it unless * explicitly overriden by having the Form UI component itself defined with their own tooltip attribute. * * <p/> * * In Example 1, the textfield will inherit the tooltipDelay and tooltipIconPath attribte from * its containing form. In other words, although it doesn't define a tooltipIconPath * attribute, it will have that attribute inherited from its containing form. * * <p/> * * In Example 2, the textfield will inherite both the tooltipDelay and * tooltipIconPath attribute from its containing form, but the tooltipDelay * attribute is overriden at the textfield itself. Hence, the textfield actually will * have its tooltipIcon defined as /myImages/myIcon.gif, inherited from its containing form, and * tooltipDelay defined as 5000. * * <p/> * * Example 3, 4 and 5 show different ways of setting the tooltip configuration attribute.<br/> * <b>Example 3:</b> Set tooltip config through the body of the param tag<br/> * <b>Example 4:</b> Set tooltip config through the value attribute of the param tag<br/> * <b>Example 5:</b> Set tooltip config through the tooltip attributes of the component tag<br/> * * <!-- END SNIPPET: tooltipdescription --> * * * <pre> * <!-- START SNIPPET: tooltipexample --> * * &lt;!-- Example 1: --&gt; * &lt;s:form * tooltipDelay="500" * tooltipIconPath="/myImages/myIcon.gif" .... &gt; * .... * &lt;s:textfield label="Customer Name" tooltip="Enter the customer name" .... /&gt; * .... * &lt;/s:form&gt; * * &lt;!-- Example 2: --&gt; * &lt;s:form * tooltipDelay="500" * tooltipIconPath="/myImages/myIcon.gif" .... &gt; * .... * &lt;s:textfield label="Address" * tooltip="Enter your address" * tooltipDelay="5000" /&gt; * .... * &lt;/s:form&gt; * * * &lt;-- Example 3: --&gt; * &lt;s:textfield * label="Customer Name" * tooltip="One of our customer Details"&gt; * &lt;s:param name="tooltipDelay"&gt; * 500 * &lt;/s:param&gt; * &lt;s:param name="tooltipIconPath"&gt; * /myImages/myIcon.gif * &lt;/s:param&gt; * &lt;/s:textfield&gt; * * * &lt;-- Example 4: --&gt; * &lt;s:textfield * label="Customer Address" * tooltip="Enter The Customer Address" &gt; * &lt;s:param * name="tooltipDelay" * value="500" /&gt; * &lt;/s:textfield&gt; * * * &lt;-- Example 5: --&gt; * &lt;s:textfield * label="Customer Telephone Number" * tooltip="Enter customer Telephone Number" * tooltipDelay="500" * tooltipIconPath="/myImages/myIcon.gif" /&gt; * * <!-- END SNIPPET: tooltipexample --> * </pre> * */ public abstract class UIBean extends Component { private static final Logger LOG = LoggerFactory.getLogger(UIBean.class); protected HttpServletRequest request; protected HttpServletResponse response; public UIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack); this.request = request; this.response = response; this.templateSuffix = ContextUtil.getTemplateSuffix(stack.getContext()); } // The templateSuffic to use, overrides the default one if not null. protected String templateSuffix; // The template to use, overrides the default one. protected String template; // templateDir and theme attributes protected String templateDir; protected String theme; // shortcut, sets label, name, and value protected String key; protected String id; protected String cssClass; protected String cssStyle; protected String disabled; protected String label; protected String labelPosition; protected String labelSeparator; protected String requiredposition; protected String name; protected String required; protected String tabindex; protected String value; protected String title; // HTML scripting events attributes protected String onclick; protected String ondblclick; protected String onmousedown; protected String onmouseup; protected String onmouseover; protected String onmousemove; protected String onmouseout; protected String onfocus; protected String onblur; protected String onkeypress; protected String onkeydown; protected String onkeyup; protected String onselect; protected String onchange; // common html attributes protected String accesskey; // javascript tooltip attribute protected String tooltip; protected String tooltipConfig; protected String javascriptTooltip; protected String tooltipDelay; protected String tooltipCssClass; protected String tooltipIconPath; // dynamic attributes protected Map<String,Object> dynamicAttributes = new HashMap<String,Object>(); protected String defaultTemplateDir; protected String defaultUITheme; protected TemplateEngineManager templateEngineManager; @Inject(StrutsConstants.STRUTS_UI_TEMPLATEDIR) public void setDefaultTemplateDir(String dir) { this.defaultTemplateDir = dir; } @Inject(StrutsConstants.STRUTS_UI_THEME) public void setDefaultUITheme(String theme) { this.defaultUITheme = theme; } @Inject public void setTemplateEngineManager(TemplateEngineManager mgr) { this.templateEngineManager = mgr; } public boolean end(Writer writer, String body) { evaluateParams(); try { super.end(writer, body, false); mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate())); } catch (Exception e) { LOG.error("error when rendering", e); } finally { popComponentStack(); } return false; } /** * A contract that requires each concrete UI Tag to specify which template should be used as a default. For * example, the CheckboxTab might return "checkbox.vm" while the RadioTag might return "radio.vm". This value * <strong>not</strong> begin with a '/' unless you intend to make the path absolute rather than relative to the * current theme. * * @return The name of the template to be used as the default. */ protected abstract String getDefaultTemplate(); protected Template buildTemplateName(String myTemplate, String myDefaultTemplate) { String template = myDefaultTemplate; if (myTemplate != null) { template = findString(myTemplate); } String templateDir = getTemplateDir(); String theme = getTheme(); return new Template(templateDir, theme, template); } protected void mergeTemplate(Writer writer, Template template) throws Exception { final TemplateEngine engine = templateEngineManager.getTemplateEngine(template, templateSuffix); if (engine == null) { throw new ConfigurationException("Unable to find a TemplateEngine for template " + template); } if (LOG.isDebugEnabled()) { LOG.debug("Rendering template " + template); } final TemplateRenderingContext context = new TemplateRenderingContext(template, writer, getStack(), getParameters(), this); engine.renderTemplate(context); } public String getTemplateDir() { String templateDir = null; if (this.templateDir != null) { templateDir = findString(this.templateDir); } // If templateDir is not explicitly given, // try to find attribute which states the dir set to use if ((templateDir == null) || (templateDir.equals(""))) { templateDir = (String) stack.findValue("#attr.templateDir"); } // Default template set if ((templateDir == null) || (templateDir.equals(""))) { templateDir = defaultTemplateDir; } // Defaults to 'template' if ((templateDir == null) || (templateDir.equals(""))) { templateDir = "template"; } return templateDir; } public String getTheme() { String theme = null; if (this.theme != null) { theme = findString(this.theme); } if ( theme == null || theme.equals("") ) { Form form = (Form) findAncestor(Form.class); if (form != null) { theme = form.getTheme(); } } // If theme set is not explicitly given, // try to find attribute which states the theme set to use if ((theme == null) || (theme.equals(""))) { theme = (String) stack.findValue("#attr.theme"); } // Default theme set if ((theme == null) || (theme.equals(""))) { theme = defaultUITheme; } return theme; } public void evaluateParams() { addParameter("templateDir", getTemplateDir()); addParameter("theme", getTheme()); String name = null; if (this.key != null) { if(this.name == null) { this.name = key; } if(this.label == null) { this.label = "%{getText('"+ key +"')}"; } } if (this.name != null) { name = findString(this.name); addParameter("name", name); } if (label != null) { addParameter("label", findString(label)); } if (labelSeparator != null) { addParameter("labelseparator", findString(labelSeparator)); } if (labelPosition != null) { addParameter("labelposition", findString(labelPosition)); } if (requiredposition != null) { addParameter("requiredposition", findString(requiredposition)); } if (required != null) { addParameter("required", findValue(required, Boolean.class)); } if (disabled != null) { addParameter("disabled", findValue(disabled, Boolean.class)); } if (tabindex != null) { addParameter("tabindex", findString(tabindex)); } if (onclick != null) { addParameter("onclick", findString(onclick)); } if (ondblclick != null) { addParameter("ondblclick", findString(ondblclick)); } if (onmousedown != null) { addParameter("onmousedown", findString(onmousedown)); } if (onmouseup != null) { addParameter("onmouseup", findString(onmouseup)); } if (onmouseover != null) { addParameter("onmouseover", findString(onmouseover)); } if (onmousemove != null) { addParameter("onmousemove", findString(onmousemove)); } if (onmouseout != null) { addParameter("onmouseout", findString(onmouseout)); } if (onfocus != null) { addParameter("onfocus", findString(onfocus)); } if (onblur != null) { addParameter("onblur", findString(onblur)); } if (onkeypress != null) { addParameter("onkeypress", findString(onkeypress)); } if (onkeydown != null) { addParameter("onkeydown", findString(onkeydown)); } if (onkeyup != null) { addParameter("onkeyup", findString(onkeyup)); } if (onselect != null) { addParameter("onselect", findString(onselect)); } if (onchange != null) { addParameter("onchange", findString(onchange)); } if (accesskey != null) { addParameter("accesskey", findString(accesskey)); } if (cssClass != null) { addParameter("cssClass", findString(cssClass)); } if (cssStyle != null) { addParameter("cssStyle", findString(cssStyle)); } if (title != null) { addParameter("title", findString(title)); } // see if the value was specified as a parameter already if (parameters.containsKey("value")) { parameters.put("nameValue", parameters.get("value")); } else { if (evaluateNameValue()) { final Class valueClazz = getValueClassType(); if (valueClazz != null) { if (value != null) { addParameter("nameValue", findValue(value, valueClazz)); } else if (name != null) { String expr = name; if (altSyntax()) { expr = "%{" + expr + "}"; } addParameter("nameValue", findValue(expr, valueClazz)); } } else { if (value != null) { addParameter("nameValue", findValue(value)); } else if (name != null) { addParameter("nameValue", findValue(name)); } } } } final Form form = (Form) findAncestor(Form.class); // create HTML id element populateComponentHtmlId(form); if (form != null ) { addParameter("form", form.getParameters()); if ( name != null ) { // list should have been created by the form component List tags = (List) form.getParameters().get("tagNames"); tags.add(name); } } // tooltip & tooltipConfig if (tooltipConfig != null) { addParameter("tooltipConfig", findValue(tooltipConfig)); } if (tooltip != null) { addParameter("tooltip", findString(tooltip)); Map tooltipConfigMap = getTooltipConfig(this); if (form != null) { // inform the containing form that we need tooltip javascript included form.addParameter("hasTooltip", Boolean.TRUE); // tooltipConfig defined in component itseilf will take precedence // over those defined in the containing form Map overallTooltipConfigMap = getTooltipConfig(form); overallTooltipConfigMap.putAll(tooltipConfigMap); // override parent form's tooltip config for (Iterator i = overallTooltipConfigMap.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); addParameter((String) entry.getKey(), entry.getValue()); } } else { LOG.warn("No ancestor Form found, javascript based tooltip will not work, however standard HTML tooltip using alt and title attribute will still work "); } //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped String jsTooltipEnabled = (String) getParameters().get("jsTooltipEnabled"); if (jsTooltipEnabled != null) this.javascriptTooltip = jsTooltipEnabled; //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped String tooltipIcon = (String) getParameters().get("tooltipIcon"); if (tooltipIcon != null) this.addParameter("tooltipIconPath", tooltipIcon); if (this.tooltipIconPath != null) this.addParameter("tooltipIconPath", findString(this.tooltipIconPath)); //TODO: this is to keep backward compatibility, remove once when tooltipConfig is dropped String tooltipDelayParam = (String) getParameters().get("tooltipDelay"); if (tooltipDelayParam != null) this.addParameter("tooltipDelay", tooltipDelayParam); if (this.tooltipDelay != null) this.addParameter("tooltipDelay", findString(this.tooltipDelay)); if (this.javascriptTooltip != null) { Boolean jsTooltips = (Boolean) findValue(this.javascriptTooltip, Boolean.class); //TODO use a Boolean model when tooltipConfig is dropped this.addParameter("jsTooltipEnabled", jsTooltips.toString()); if (form != null) form.addParameter("hasTooltip", jsTooltips); if (this.tooltipCssClass != null) this.addParameter("tooltipCssClass", findString(this.tooltipCssClass)); } } addParameter("dynamicAttributes", dynamicAttributes); evaluateExtraParams(); } protected String escape(String name) { // escape any possible values that can make the ID painful to work with in JavaScript if (name != null) { return name.replaceAll("[\\.\\[\\]]", "_"); } else { return ""; } } protected void evaluateExtraParams() { } protected boolean evaluateNameValue() { return true; } protected Class getValueClassType() { return String.class; } public void addFormParameter(String key, Object value) { Form form = (Form) findAncestor(Form.class); if (form != null) { form.addParameter(key, value); } } protected void enableAncestorFormCustomOnsubmit() { Form form = (Form) findAncestor(Form.class); if (form != null) { form.addParameter("customOnsubmitEnabled", Boolean.TRUE); } else { LOG.warn("Cannot find an Ancestor form, custom onsubmit is NOT enabled"); } } protected Map getTooltipConfig(UIBean component) { Object tooltipConfigObj = component.getParameters().get("tooltipConfig"); Map tooltipConfig = new LinkedHashMap(); if (tooltipConfigObj instanceof Map) { // we get this if its configured using // 1] UI component's tooltipConfig attribute OR // 2] <param name="tooltip" value="" /> param tag value attribute tooltipConfig = new LinkedHashMap((Map)tooltipConfigObj); } else if (tooltipConfigObj instanceof String) { // we get this if its configured using // <param name="tooltipConfig"> ... </param> tag's body String tooltipConfigStr = (String) tooltipConfigObj; String[] tooltipConfigArray = tooltipConfigStr.split("\\|"); for (int a=0; a<tooltipConfigArray.length; a++) { String[] configEntry = ((String)tooltipConfigArray[a].trim()).split("="); String key = configEntry[0].trim(); String value = null; if (configEntry.length > 1) { value = configEntry[1].trim(); tooltipConfig.put(key, value); } else { LOG.warn("component "+component+" tooltip config param "+key+" has no value defined, skipped"); } } } if (component.javascriptTooltip != null) tooltipConfig.put("jsTooltipEnabled", component.javascriptTooltip); if (component.tooltipIconPath != null) tooltipConfig.put("tooltipIcon", component.tooltipIconPath); if (component.tooltipDelay != null) tooltipConfig.put("tooltipDelay", component.tooltipDelay); return tooltipConfig; } /** * Create HTML id element for the component and populate this component parmaeter * map. Additionally, a parameter named escapedId is populated which contains the found id value filtered by * {@link #escape(String)}, needed eg. for naming Javascript identifiers based on the id value. * * The order is as follows :- * <ol> * <li>This component id attribute</li> * <li>[containing_form_id]_[this_component_name]</li> * <li>[this_component_name]</li> * </ol> * * @param form */ protected void populateComponentHtmlId(Form form) { String tryId; if (id != null) { // this check is needed for backwards compatibility with 2.1.x if (altSyntax()) { tryId = findString(id); } else { tryId = id; } } else if (form != null) { tryId = form.getParameters().get("id") + "_" + escape(name != null ? findString(name) : null); } else { tryId = escape(name != null ? findString(name) : null); } addParameter("id", tryId); addParameter("escapedId", escape(tryId)); } /** * Get's the id for referencing element. * @return the id for referencing element. */ public String getId() { return id; } @StrutsTagAttribute(description="HTML id attribute") public void setId(String id) { if (id != null) { this.id = findString(id); } } @StrutsTagAttribute(description="The template directory.") public void setTemplateDir(String templateDir) { this.templateDir = templateDir; } @StrutsTagAttribute(description="The theme (other than default) to use for rendering the element") public void setTheme(String theme) { this.theme = theme; } public String getTemplate() { return template; } @StrutsTagAttribute(description="The template (other than default) to use for rendering the element") public void setTemplate(String template) { this.template = template; } @StrutsTagAttribute(description="The css class to use for element") public void setCssClass(String cssClass) { this.cssClass = cssClass; } @StrutsTagAttribute(description="The css style definitions for element to use") public void setCssStyle(String cssStyle) { this.cssStyle = cssStyle; } @StrutsTagAttribute(description="Set the html title attribute on rendered html element") public void setTitle(String title) { this.title = title; } @StrutsTagAttribute(description="Set the html disabled attribute on rendered html element") public void setDisabled(String disabled) { this.disabled = disabled; } @StrutsTagAttribute(description="Label expression used for rendering a element specific label") public void setLabel(String label) { this.label = label; } @StrutsTagAttribute(description="String that will be appended to the labe", defaultValue=":") public void setLabelSeparator(String labelseparator) { this.labelSeparator = labelseparator; } @StrutsTagAttribute(description="Define label position of form element (top/left)") public void setLabelposition(String labelPosition) { this.labelPosition = labelPosition; } @StrutsTagAttribute(description="Define required position of required form element (left|right)") public void setRequiredposition(String requiredposition) { this.requiredposition = requiredposition; } @StrutsTagAttribute(description="The name to set for element") public void setName(String name) { this.name = name; } @StrutsTagAttribute(description="If set to true, the rendered element will indicate that input is required", type="Boolean", defaultValue="false") public void setRequired(String required) { this.required = required; } @StrutsTagAttribute(description="Set the html tabindex attribute on rendered html element") public void setTabindex(String tabindex) { this.tabindex = tabindex; } @StrutsTagAttribute(description="Preset the value of input element.") public void setValue(String value) { this.value = value; } @StrutsTagAttribute(description="Set the html onclick attribute on rendered html element") public void setOnclick(String onclick) { this.onclick = onclick; } @StrutsTagAttribute(description="Set the html ondblclick attribute on rendered html element") public void setOndblclick(String ondblclick) { this.ondblclick = ondblclick; } @StrutsTagAttribute(description="Set the html onmousedown attribute on rendered html element") public void setOnmousedown(String onmousedown) { this.onmousedown = onmousedown; } @StrutsTagAttribute(description="Set the html onmouseup attribute on rendered html element") public void setOnmouseup(String onmouseup) { this.onmouseup = onmouseup; } @StrutsTagAttribute(description="Set the html onmouseover attribute on rendered html element") public void setOnmouseover(String onmouseover) { this.onmouseover = onmouseover; } @StrutsTagAttribute(description="Set the html onmousemove attribute on rendered html element") public void setOnmousemove(String onmousemove) { this.onmousemove = onmousemove; } @StrutsTagAttribute(description="Set the html onmouseout attribute on rendered html element") public void setOnmouseout(String onmouseout) { this.onmouseout = onmouseout; } @StrutsTagAttribute(description="Set the html onfocus attribute on rendered html element") public void setOnfocus(String onfocus) { this.onfocus = onfocus; } @StrutsTagAttribute(description=" Set the html onblur attribute on rendered html element") public void setOnblur(String onblur) { this.onblur = onblur; } @StrutsTagAttribute(description="Set the html onkeypress attribute on rendered html element") public void setOnkeypress(String onkeypress) { this.onkeypress = onkeypress; } @StrutsTagAttribute(description="Set the html onkeydown attribute on rendered html element") public void setOnkeydown(String onkeydown) { this.onkeydown = onkeydown; } @StrutsTagAttribute(description="Set the html onkeyup attribute on rendered html element") public void setOnkeyup(String onkeyup) { this.onkeyup = onkeyup; } @StrutsTagAttribute(description="Set the html onselect attribute on rendered html element") public void setOnselect(String onselect) { this.onselect = onselect; } @StrutsTagAttribute(description="Set the html onchange attribute on rendered html element") public void setOnchange(String onchange) { this.onchange = onchange; } @StrutsTagAttribute(description="Set the html accesskey attribute on rendered html element") public void setAccesskey(String accesskey) { this.accesskey = accesskey; } @StrutsTagAttribute(description="Set the tooltip of this particular component") public void setTooltip(String tooltip) { this.tooltip = tooltip; } @StrutsTagAttribute(description="Deprecated. Use individual tooltip configuration attributes instead.") public void setTooltipConfig(String tooltipConfig) { this.tooltipConfig = tooltipConfig; } @StrutsTagAttribute(description="Set the key (name, value, label) for this particular component") public void setKey(String key) { this.key = key; } @StrutsTagAttribute(description="Use JavaScript to generate tooltips", type="Boolean", defaultValue="false") public void setJavascriptTooltip(String javascriptTooltip) { this.javascriptTooltip = javascriptTooltip; } @StrutsTagAttribute(description="CSS class applied to JavaScrip tooltips", defaultValue="StrutsTTClassic") public void setTooltipCssClass(String tooltipCssClass) { this.tooltipCssClass = tooltipCssClass; } @StrutsTagAttribute(description="Delay in milliseconds, before showing JavaScript tooltips ", defaultValue="Classic") public void setTooltipDelay(String tooltipDelay) { this.tooltipDelay = tooltipDelay; } @StrutsTagAttribute(description="Icon path used for image that will have the tooltip") public void setTooltipIconPath(String tooltipIconPath) { this.tooltipIconPath = tooltipIconPath; } public void setDynamicAttributes(Map<String,Object> dynamicAttributes) { this.dynamicAttributes = dynamicAttributes; } }

The table below shows all metrics for UIBean.java.

MetricValueDescription
BLOCKS137.00Number of blocks
BLOCK_COMMENT20.00Number of block comment lines
COMMENTS434.00Comment lines
COMMENT_DENSITY 1.00Comment density
COMPARISONS87.00Number of comparison operators
CYCLOMATIC145.00Cyclomatic complexity
DECL_COMMENTS13.00Comments in declarations
DOC_COMMENT382.00Number of javadoc comment lines
ELOC435.00Effective lines of code
EXEC_COMMENTS18.00Comments in executable code
EXITS47.00Procedure exits
FUNCTIONS60.00Number of function declarations
HALSTEAD_DIFFICULTY 0.36Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY118.00Interface complexity
JAVA0001 1.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 1.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003410.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 4.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011756.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 2.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 1.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 9.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 1.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
JAVA0289 4.00null
LINES1147.00Number of lines in the source file
LINE_COMMENT32.00Number of line comments
LOC562.00Lines of code
LOGICAL_LINES248.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1219.00Number of operands
OPERATORS2369.00Number of operators
PARAMS56.00Number of formal parameter declarations
PROGRAM_LENGTH3588.00Halstead program length
PROGRAM_VOCAB454.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS62.00Number of return points from functions
SIZE37696.00Size of the file in bytes
UNIQUE_OPERANDS405.00Number of unique operands
UNIQUE_OPERATORS49.00Number of unique operators
WHITESPACE151.00Number of whitespace lines