Methods Summary |
---|
public void | addFormParameter(java.lang.String key, java.lang.Object value)
Form form = (Form) findAncestor(Form.class);
if (form != null) {
form.addParameter(key, value);
}
|
protected org.apache.struts2.components.template.Template | buildTemplateName(java.lang.String myTemplate, java.lang.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 | 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");
}
|
public boolean | end(java.io.Writer writer, java.lang.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;
|
protected java.lang.String | escape(java.lang.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;
|
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 (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 ");
}
}
evaluateExtraParams();
|
protected abstract java.lang.String | getDefaultTemplate()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
not begin with a '/' unless you intend to make the path absolute rather than relative to the
current theme.
|
public java.lang.String | getTemplate()
return template;
|
public java.lang.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 java.lang.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;
|
protected java.util.Map | getTooltipConfig(org.apache.struts2.components.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.toString());
}
else {
LOG.warn("component "+component+" tooltip config param "+key+" has no value defined, skipped");
}
}
}
return tooltipConfig;
|
protected java.lang.Class | getValueClassType()
return String.class;
|
protected void | mergeTemplate(java.io.Writer writer, org.apache.struts2.components.template.Template template)
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);
|
protected void | populateComponentHtmlId(Form form)Create HTML id element for the component and populate this component parmaeter
map.
The order is as follows :-
- This component id attribute
- [containing_form_id]_[this_component_name]
- [this_component_name]
if (id != null) {
// this check is needed for backwards compatibility with 2.1.x
if (altSyntax()) {
addParameter("id", findString(id));
} else {
addParameter("id", id);
}
} else if (form != null) {
addParameter("id", form.getParameters().get("id") + "_"
+ escape(name != null ? findString(name) : null));
} else {
addParameter("id", escape(name != null ? findString(name) : null));
}
|
public void | setAccesskey(java.lang.String accesskey)
this.accesskey = accesskey;
|
public void | setCssClass(java.lang.String cssClass)
this.cssClass = cssClass;
|
public void | setCssStyle(java.lang.String cssStyle)
this.cssStyle = cssStyle;
|
public void | setDefaultTemplateDir(java.lang.String dir)
this.defaultTemplateDir = dir;
|
public void | setDefaultUITheme(java.lang.String theme)
this.defaultUITheme = theme;
|
public void | setDisabled(java.lang.String disabled)
this.disabled = disabled;
|
public void | setKey(java.lang.String key)
this.key = key;
|
public void | setLabel(java.lang.String label)
this.label = label;
|
public void | setLabelposition(java.lang.String labelPosition)
this.labelPosition = labelPosition;
|
public void | setName(java.lang.String name)
this.name = name;
|
public void | setOnblur(java.lang.String onblur)
this.onblur = onblur;
|
public void | setOnchange(java.lang.String onchange)
this.onchange = onchange;
|
public void | setOnclick(java.lang.String onclick)
this.onclick = onclick;
|
public void | setOndblclick(java.lang.String ondblclick)
this.ondblclick = ondblclick;
|
public void | setOnfocus(java.lang.String onfocus)
this.onfocus = onfocus;
|
public void | setOnkeydown(java.lang.String onkeydown)
this.onkeydown = onkeydown;
|
public void | setOnkeypress(java.lang.String onkeypress)
this.onkeypress = onkeypress;
|
public void | setOnkeyup(java.lang.String onkeyup)
this.onkeyup = onkeyup;
|
public void | setOnmousedown(java.lang.String onmousedown)
this.onmousedown = onmousedown;
|
public void | setOnmousemove(java.lang.String onmousemove)
this.onmousemove = onmousemove;
|
public void | setOnmouseout(java.lang.String onmouseout)
this.onmouseout = onmouseout;
|
public void | setOnmouseover(java.lang.String onmouseover)
this.onmouseover = onmouseover;
|
public void | setOnmouseup(java.lang.String onmouseup)
this.onmouseup = onmouseup;
|
public void | setOnselect(java.lang.String onselect)
this.onselect = onselect;
|
public void | setRequired(java.lang.String required)
this.required = required;
|
public void | setRequiredposition(java.lang.String requiredposition)
this.requiredposition = requiredposition;
|
public void | setTabindex(java.lang.String tabindex)
this.tabindex = tabindex;
|
public void | setTemplate(java.lang.String template)
this.template = template;
|
public void | setTemplateDir(java.lang.String templateDir)
this.templateDir = templateDir;
|
public void | setTemplateEngineManager(org.apache.struts2.components.template.TemplateEngineManager mgr)
this.templateEngineManager = mgr;
|
public void | setTheme(java.lang.String theme)
this.theme = theme;
|
public void | setTitle(java.lang.String title)
this.title = title;
|
public void | setTooltip(java.lang.String tooltip)
this.tooltip = tooltip;
|
public void | setTooltipConfig(java.lang.String tooltipConfig)
this.tooltipConfig = tooltipConfig;
|
public void | setValue(java.lang.String value)
this.value = value;
|