WW-2077 Change parseWidgets to false in djConfig inside head FTL .Should be false for better performance!

* Now there is a new property "parseContent" in the "head" tag, which is set to "false" by default. If set to true, Dojo will scan the whole document looking for widgets.

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@569863 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2007-08-26 19:18:15 +00:00
parent 168bf5e8ab
commit add167aefd
42 changed files with 2771 additions and 2590 deletions
@@ -1,246 +1,256 @@
/*
* $Id: AbstractRemoteCallUIBean.java 508285 2007-02-16 02:42:24Z musachy $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* AbstractRemoteCallUIBean is superclass for all components dealing with remote
* calls.
*/
public abstract class AbstractRemoteBean extends ClosingUIBean implements RemoteBean {
protected String href;
protected String errorText;
protected String executeScripts;
protected String loadingText;
protected String listenTopics;
protected String handler;
protected String formId;
protected String formFilter;
protected String notifyTopics;
protected String showErrorTransportText;
protected String indicator;
protected String showLoadingText;
protected String beforeNotifyTopics;
protected String afterNotifyTopics;
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String separateScripts;
protected String transport;
protected String parseContent;
public AbstractRemoteBean(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
}
public void evaluateExtraParams() {
super.evaluateExtraParams();
if (href != null)
addParameter("href", findString(href));
if (errorText != null)
addParameter("errorText", findString(errorText));
if (loadingText != null)
addParameter("loadingText", findString(loadingText));
if (executeScripts != null)
addParameter("executeScripts", findValue(executeScripts, Boolean.class));
if (listenTopics != null)
addParameter("listenTopics", findValue(listenTopics, String.class));
if (notifyTopics != null)
addParameter("notifyTopics", findValue(notifyTopics, String.class));
if (handler != null)
addParameter("handler", findString(handler));
if (formId != null)
addParameter("formId", findString(formId));
if (formFilter != null)
addParameter("formFilter", findString(formFilter));
if (indicator != null)
addParameter("indicator", findString(indicator));
if (showErrorTransportText != null)
addParameter("showErrorTransportText", findValue(showErrorTransportText, Boolean.class));
else
addParameter("showErrorTransportText", true);
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (beforeNotifyTopics != null)
addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
if (afterNotifyTopics != null)
addParameter("afterNotifyTopics", findString(afterNotifyTopics));
if (errorNotifyTopics != null)
addParameter("errorNotifyTopics", findString(errorNotifyTopics));
if (highlightColor != null)
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
if (transport != null)
addParameter("transport", findString(transport));
if (parseContent != null)
addParameter("parseContent", findValue(parseContent, Boolean.class));
else
addParameter("parseContent", true);
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
@StrutsTagAttribute(description="Topic that will trigger the remote call")
public void setListenTopics(String listenTopics) {
this.listenTopics = listenTopics;
}
@StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
public void setHref(String href) {
this.href = href;
}
@StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
public void setErrorText(String errorText) {
this.errorText = errorText;
}
@StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
public void setExecuteScripts(String executeScripts) {
this.executeScripts = executeScripts;
}
@StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
public void setLoadingText(String loadingText) {
this.loadingText = loadingText;
}
@StrutsTagAttribute(description="Javascript function name that will make the request")
public void setHandler(String handler) {
this.handler = handler;
}
@StrutsTagAttribute(description="Function name used to filter the fields of the form.")
public void setFormFilter(String formFilter) {
this.formFilter = formFilter;
}
@StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
public void setFormId(String formId) {
this.formId = formId;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
public void setNotifyTopics(String notifyTopics) {
this.notifyTopics = notifyTopics;
}
@StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
public void setShowErrorTransportText(String showError) {
this.showErrorTransportText = showError;
}
@StrutsTagAttribute(description="Id of element that will be shown while making request")
public void setIndicator(String indicator) {
this.indicator = indicator;
}
@StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
public void setShowLoadingText(String showLoadingText) {
this.showLoadingText = showLoadingText;
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
public void setAfterNotifyTopics(String afterNotifyTopics) {
this.afterNotifyTopics = afterNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
public void setBeforeNotifyTopics(String beforeNotifyTopics) {
this.beforeNotifyTopics = beforeNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
public void setErrorNotifyTopics(String errorNotifyTopics) {
this.errorNotifyTopics = errorNotifyTopics;
}
@StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute",
defaultValue = "none")
public void setHighlightColor(String highlightColor) {
this.highlightColor = highlightColor;
}
@StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set",
defaultValue = "2000", type="Integer")
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
@StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
public void setTransport(String transport) {
this.transport = transport;
}
@StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
/*
* $Id: AbstractRemoteCallUIBean.java 508285 2007-02-16 02:42:24Z musachy $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.dojo.components;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* AbstractRemoteCallUIBean is superclass for all components dealing with remote
* calls.
*/
public abstract class AbstractRemoteBean extends ClosingUIBean implements RemoteBean {
protected String href;
protected String errorText;
protected String executeScripts;
protected String loadingText;
protected String listenTopics;
protected String handler;
protected String formId;
protected String formFilter;
protected String notifyTopics;
protected String showErrorTransportText;
protected String indicator;
protected String showLoadingText;
protected String beforeNotifyTopics;
protected String afterNotifyTopics;
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String separateScripts;
protected String transport;
protected String parseContent;
public AbstractRemoteBean(ValueStack stack, HttpServletRequest request,
HttpServletResponse response) {
super(stack, request, response);
}
public void evaluateExtraParams() {
super.evaluateExtraParams();
if (href != null)
addParameter("href", findString(href));
if (errorText != null)
addParameter("errorText", findString(errorText));
if (loadingText != null)
addParameter("loadingText", findString(loadingText));
if (executeScripts != null)
addParameter("executeScripts", findValue(executeScripts, Boolean.class));
if (listenTopics != null)
addParameter("listenTopics", findValue(listenTopics, String.class));
if (notifyTopics != null)
addParameter("notifyTopics", findValue(notifyTopics, String.class));
if (handler != null)
addParameter("handler", findString(handler));
if (formId != null)
addParameter("formId", findString(formId));
if (formFilter != null)
addParameter("formFilter", findString(formFilter));
if (indicator != null)
addParameter("indicator", findString(indicator));
if (showErrorTransportText != null)
addParameter("showErrorTransportText", findValue(showErrorTransportText, Boolean.class));
else
addParameter("showErrorTransportText", true);
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (beforeNotifyTopics != null)
addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
if (afterNotifyTopics != null)
addParameter("afterNotifyTopics", findString(afterNotifyTopics));
if (errorNotifyTopics != null)
addParameter("errorNotifyTopics", findString(errorNotifyTopics));
if (highlightColor != null)
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
if (transport != null)
addParameter("transport", findString(transport));
if (parseContent != null)
addParameter("parseContent", findValue(parseContent, Boolean.class));
else
addParameter("parseContent", true);
boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
addParameter("pushId", generateId);
if ((this.id == null || this.id.length() == 0) && generateId) {
Random random = new Random();
this.id = "widget_" + Math.abs(random.nextInt());
addParameter("id", this.id);
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
@StrutsTagAttribute(description="Topic that will trigger the remote call")
public void setListenTopics(String listenTopics) {
this.listenTopics = listenTopics;
}
@StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
public void setHref(String href) {
this.href = href;
}
@StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
public void setErrorText(String errorText) {
this.errorText = errorText;
}
@StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
public void setExecuteScripts(String executeScripts) {
this.executeScripts = executeScripts;
}
@StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
public void setLoadingText(String loadingText) {
this.loadingText = loadingText;
}
@StrutsTagAttribute(description="Javascript function name that will make the request")
public void setHandler(String handler) {
this.handler = handler;
}
@StrutsTagAttribute(description="Function name used to filter the fields of the form.")
public void setFormFilter(String formFilter) {
this.formFilter = formFilter;
}
@StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
public void setFormId(String formId) {
this.formId = formId;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
public void setNotifyTopics(String notifyTopics) {
this.notifyTopics = notifyTopics;
}
@StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
public void setShowErrorTransportText(String showError) {
this.showErrorTransportText = showError;
}
@StrutsTagAttribute(description="Id of element that will be shown while making request")
public void setIndicator(String indicator) {
this.indicator = indicator;
}
@StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
public void setShowLoadingText(String showLoadingText) {
this.showLoadingText = showLoadingText;
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
public void setAfterNotifyTopics(String afterNotifyTopics) {
this.afterNotifyTopics = afterNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
public void setBeforeNotifyTopics(String beforeNotifyTopics) {
this.beforeNotifyTopics = beforeNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
public void setErrorNotifyTopics(String errorNotifyTopics) {
this.errorNotifyTopics = errorNotifyTopics;
}
@StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute",
defaultValue = "none")
public void setHighlightColor(String highlightColor) {
this.highlightColor = highlightColor;
}
@StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set",
defaultValue = "2000", type="Integer")
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
@StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
public void setTransport(String transport) {
this.transport = transport;
}
@StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,420 +1,429 @@
/*
* $Id: DateTimePicker.java 512580 2007-02-28 02:48:06Z musachy $
*
* 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.dojo.components;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.components.UIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* <p>
* Renders a date/time picker in a dropdown container.
* </p>
* <p>
* A stand-alone DateTimePicker widget that makes it easy to select a date/time, or increment by week, month,
* and/or year.
* </p>
*
* <p>
* It is possible to customize the user-visible formatting with either the
* 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By defaulty current
* locale will be used.</p>
* </p>
*
* Syntax supported by 'displayFormat' is (http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns):-
* <table border="1">
* <tr>
* <td>Format</td>
* <td>Description</td>
* </tr>
* <tr>
* <td>d</td>
* <td>Day of the month</td>
* </tr>
* <tr>
* <td>D</td>
* <td>Day of year</td>
* </tr>
* <tr>
* <td>M</td>
* <td>Month - Use one or two for the numerical month, three for the abbreviation, or four for the full name, or 5 for the narrow name.</td>
* </tr>
* <tr>
* <td>y</td>
* <td>Year</td>
* </tr>
* <tr>
* <td>h</td>
* <td>Hour [1-12].</td>
* </tr>
* <tr>
* <td>H</td>
* <td>Hour [0-23].</td>
* </tr>
* <tr>
* <td>m</td>
* <td>Minute. Use one or two for zero padding.</td>
* </tr>
* <tr>
* <td>s</td>
* <td>Second. Use one or two for zero padding.</td>
* </tr>
* </table>
*
* <p>
* The value sent to the server is a locale-independent value, in a hidden field as defined
* by the name attribute. The value will be formatted conforming to RFC3 339
* (yyyy-MM-dd'T'HH:mm:ss)
* </p>
* <p>
* The following formats(in order) will be used to parse the values of the attributes 'value',
* 'startDate' and 'endDate':
* </p>
* <ul>
* <li>SimpleDateFormat built using RFC 3339 (yyyy-MM-dd'T'HH:mm:ss)
* <li>SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
* <li>SimpleDateFormat.getDateInstance(DateFormat.SHORT)
* <li>SimpleDateFormat.getDateInstance(DateFormat.MEDIUM)
* <li>SimpleDateFormat.getDateInstance(DateFormat.FULL)
* <li>SimpleDateFormat.getDateInstance(DateFormat.LONG)
* <li>SimpleDateFormat built using the value of the 'displayFormat' attribute(if any)
* </ul>
* <!-- END SNIPPET: javadoc -->
*
* <b>Examples</b>
*
* <pre>
* <!-- START SNIPPET: example1 -->
*
* Example 1:
* &lt;sx:datetimepicker name="order.date" label="Order Date" /&gt;
* Example 2:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd" /&gt;
* Example 3:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}" /&gt;
* Example 4:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}" /&gt;
* Example 5:
* &lt;sx:datetimepicker name="order.date" label="Order Date" value="%{'today'}"/&gt;
* <!-- END SNIPPET: example1 -->
* </pre>
*
* <!-- START SNIPPET: example2 -->
* <p>Getting and getting the datetimepicker value, from JavaScript</p>
* <pre>
* &lt;sx:datetimepicker id="picker" label="Order Date" /&gt;
* &lt;script type="text/javascript"&gt;
* function setValue() {
* var picker = dojo.widget.byId("picker");
*
* //string value
* picker.setValue('2007-01-01');
*
* //Date value
* picker.setValue(new Date());
* }
*
* function showValue() {
* var picker = dojo.widget.byId("picker");
*
* //string value
* var stringValue = picker.getValue();
* alert(stringValue);
*
* //date value
* var dateValue = picker.getDate();
* alert(dateValue);
* }
* &lt;/script&gt;
* </pre>
* <!-- END SNIPPET: example2 -->
*
* <!-- START SNIPPET: example3 -->
* <p>Publish topic when value changes</p>
* <pre>
* &lt;sx:datetimepicker id="picker" label="Order Date" valueNotifyTopics="/value"/&gt;
*
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/value", function(textEntered, date, widget){
* alert('value changed');
* //textEntered: String enetered in the textbox
* //date: JavaScript Date object with the value selected
* //widet: widget that published the topic
* });
* &lt;/script&gt;
* </pre>
* <!-- END SNIPPET: example3 -->
*/
@StrutsTag(name="datetimepicker", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DateTimePickerTag", description="Render datetimepicker")
public class DateTimePicker extends UIBean {
final public static String TEMPLATE = "datetimepicker";
final private static SimpleDateFormat RFC3339_FORMAT = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss");
final protected static Log LOG = LogFactory.getLog(DateTimePicker.class);
protected String iconPath;
protected String formatLength;
protected String displayFormat;
protected String toggleType;
protected String toggleDuration;
protected String type;
protected String displayWeeks;
protected String adjustWeeks;
protected String startDate;
protected String endDate;
protected String weekStartsOn;
protected String staticDisplay;
protected String dayWidth;
protected String language;
protected String templateCssPath;
protected String valueNotifyTopics;
public DateTimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
public void evaluateParams() {
super.evaluateParams();
if(displayFormat != null)
addParameter("displayFormat", findString(displayFormat));
if(displayWeeks != null)
addParameter("displayWeeks", findString(displayWeeks));
if(adjustWeeks != null)
addParameter("adjustWeeks", findValue(adjustWeeks, Boolean.class));
if(startDate != null)
addParameter("startDate", format(findValue(startDate)));
if(endDate != null)
addParameter("endDate", format(findValue(endDate)));
if(weekStartsOn != null)
addParameter("weekStartsOn", findString(weekStartsOn));
if(staticDisplay != null)
addParameter("staticDisplay", findValue(staticDisplay, Boolean.class));
if(dayWidth != null)
addParameter("dayWidth", findValue(dayWidth, Integer.class));
if(language != null)
addParameter("language", findString(language));
if(value != null)
addParameter("value", format(findValue(value)));
if(iconPath != null)
addParameter("iconPath", findString(iconPath));
if(formatLength != null)
addParameter("formatLength", findString(formatLength));
if(toggleType != null)
addParameter("toggleType", findString(toggleType));
if(toggleDuration != null)
addParameter("toggleDuration", findValue(toggleDuration,
Integer.class));
if(type != null)
addParameter("type", findString(type));
else
addParameter("type", "date");
if(templateCssPath != null)
addParameter("templateCssPath", findString(templateCssPath));
if(valueNotifyTopics != null)
addParameter("valueNotifyTopics", findString(valueNotifyTopics));
// format the value to RFC 3399
if(parameters.containsKey("value")) {
parameters.put("nameValue", parameters.get("value"));
} else {
if(name != null) {
addParameter("nameValue", format(findValue(name)));
}
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
@StrutsTagAttribute(description="If true, weekly size of calendar changes to acomodate the month if false," +
" 42 day format is used", type="Boolean", defaultValue="false")
public void setAdjustWeeks(String adjustWeeks) {
this.adjustWeeks = adjustWeeks;
}
@StrutsTagAttribute(description="How to render the names of the days in the header(narrow, abbr or wide)", defaultValue="narrow")
public void setDayWidth(String dayWidth) {
this.dayWidth = dayWidth;
}
@StrutsTagAttribute(description="Total weeks to display", type="Integer", defaultValue="6")
public void setDisplayWeeks(String displayWeeks) {
this.displayWeeks = displayWeeks;
}
@StrutsTagAttribute(description="Last available date in the calendar set", type="Date", defaultValue="2941-10-12")
public void setEndDate(String endDate) {
this.endDate = endDate;
}
@StrutsTagAttribute(description="First available date in the calendar set", type="Date", defaultValue="1492-10-12")
public void setStartDate(String startDate) {
this.startDate = startDate;
}
@StrutsTagAttribute(description="Disable all incremental controls, must pick a date in the current display", type="Boolean", defaultValue="false")
public void setStaticDisplay(String staticDisplay) {
this.staticDisplay = staticDisplay;
}
@StrutsTagAttribute(description="Adjusts the first day of the week 0==Sunday..6==Saturday", type="Integer", defaultValue="0")
public void setWeekStartsOn(String weekStartsOn) {
this.weekStartsOn = weekStartsOn;
}
@StrutsTagAttribute(description="Language to display this widget in", defaultValue="brower's specified preferred language")
public void setLanguage(String language) {
this.language = language;
}
@StrutsTagAttribute(description="A pattern used for the visual display of the formatted date, e.g. dd/MM/yyyy")
public void setDisplayFormat(String displayFormat) {
this.displayFormat = displayFormat;
}
@StrutsTagAttribute(description="Type of formatting used for visual display. Possible values are " +
"long, short, medium or full", defaultValue="short")
public void setFormatLength(String formatLength) {
this.formatLength = formatLength;
}
@StrutsTagAttribute(description="Path to icon used for the dropdown")
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
@StrutsTagAttribute(description="Duration of toggle in milliseconds", type="Integer", defaultValue="100")
public void setToggleDuration(String toggleDuration) {
this.toggleDuration = toggleDuration;
}
@StrutsTagAttribute(description="Defines the type of the picker on the dropdown. Possible values are 'date'" +
" for a DateTimePicker, and 'time' for a timePicker", defaultValue="date")
public void setType(String type) {
this.type = type;
}
@StrutsTagAttribute(description="oggle type of the dropdown. Possible values are plain,wipe,explode,fade", defaultValue="plain")
public void setToggleType(String toggleType) {
this.toggleType = toggleType;
}
@StrutsTagAttribute(description="Template css path")
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
@StrutsTagAttribute(description="Preset the value of input element")
public void setValue(String arg0) {
super.setValue(arg0);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published when a value is selected")
public void setValueNotifyTopics(String valueNotifyTopics) {
this.valueNotifyTopics = valueNotifyTopics;
}
private String format(Object obj) {
if(obj == null)
return null;
if(obj instanceof Date) {
return RFC3339_FORMAT.format((Date) obj);
} else if(obj instanceof Calendar) {
return RFC3339_FORMAT.format(((Calendar) obj).getTime());
}
else {
// try to parse a date
String dateStr = obj.toString();
if(dateStr.equalsIgnoreCase("today"))
return RFC3339_FORMAT.format(new Date());
Date date = null;
//formats used to parse the date
List<DateFormat> formats = new ArrayList<DateFormat>();
formats.add(RFC3339_FORMAT);
formats.add(SimpleDateFormat.getTimeInstance(DateFormat.SHORT));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.SHORT));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.MEDIUM));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.FULL));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.LONG));
if (this.displayFormat != null) {
try {
SimpleDateFormat displayFormat = new SimpleDateFormat(
(String) getParameters().get("displayFormat"));
formats.add(displayFormat);
} catch (Exception e) {
// don't use it then (this attribute is used by Dojo, not java code)
LOG.error(e);
}
}
for (DateFormat format : formats) {
try {
date = format.parse(dateStr);
if (date != null)
return RFC3339_FORMAT.format(date);
} catch (Exception e) {
//keep going
}
}
// last resource, assume already in correct/default format
if (LOG.isDebugEnabled())
LOG.debug("Unable to parse date " + dateStr);
return dateStr;
}
}
}
/*
* $Id: DateTimePicker.java 512580 2007-02-28 02:48:06Z musachy $
*
* 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.dojo.components;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.components.UIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* <p>
* Renders a date/time picker in a dropdown container.
* </p>
* <p>
* A stand-alone DateTimePicker widget that makes it easy to select a date/time, or increment by week, month,
* and/or year.
* </p>
*
* <p>
* It is possible to customize the user-visible formatting with either the
* 'formatLength' (long, short, medium or full) or 'displayFormat' attributes. By defaulty current
* locale will be used.</p>
* </p>
*
* Syntax supported by 'displayFormat' is (http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns):-
* <table border="1">
* <tr>
* <td>Format</td>
* <td>Description</td>
* </tr>
* <tr>
* <td>d</td>
* <td>Day of the month</td>
* </tr>
* <tr>
* <td>D</td>
* <td>Day of year</td>
* </tr>
* <tr>
* <td>M</td>
* <td>Month - Use one or two for the numerical month, three for the abbreviation, or four for the full name, or 5 for the narrow name.</td>
* </tr>
* <tr>
* <td>y</td>
* <td>Year</td>
* </tr>
* <tr>
* <td>h</td>
* <td>Hour [1-12].</td>
* </tr>
* <tr>
* <td>H</td>
* <td>Hour [0-23].</td>
* </tr>
* <tr>
* <td>m</td>
* <td>Minute. Use one or two for zero padding.</td>
* </tr>
* <tr>
* <td>s</td>
* <td>Second. Use one or two for zero padding.</td>
* </tr>
* </table>
*
* <p>
* The value sent to the server is a locale-independent value, in a hidden field as defined
* by the name attribute. The value will be formatted conforming to RFC3 339
* (yyyy-MM-dd'T'HH:mm:ss)
* </p>
* <p>
* The following formats(in order) will be used to parse the values of the attributes 'value',
* 'startDate' and 'endDate':
* </p>
* <ul>
* <li>SimpleDateFormat built using RFC 3339 (yyyy-MM-dd'T'HH:mm:ss)
* <li>SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
* <li>SimpleDateFormat.getDateInstance(DateFormat.SHORT)
* <li>SimpleDateFormat.getDateInstance(DateFormat.MEDIUM)
* <li>SimpleDateFormat.getDateInstance(DateFormat.FULL)
* <li>SimpleDateFormat.getDateInstance(DateFormat.LONG)
* <li>SimpleDateFormat built using the value of the 'displayFormat' attribute(if any)
* </ul>
* <!-- END SNIPPET: javadoc -->
*
* <b>Examples</b>
*
* <pre>
* <!-- START SNIPPET: example1 -->
*
* Example 1:
* &lt;sx:datetimepicker name="order.date" label="Order Date" /&gt;
* Example 2:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd" /&gt;
* Example 3:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}" /&gt;
* Example 4:
* &lt;sx:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}" /&gt;
* Example 5:
* &lt;sx:datetimepicker name="order.date" label="Order Date" value="%{'today'}"/&gt;
* <!-- END SNIPPET: example1 -->
* </pre>
*
* <!-- START SNIPPET: example2 -->
* <p>Getting and getting the datetimepicker value, from JavaScript</p>
* <pre>
* &lt;sx:datetimepicker id="picker" label="Order Date" /&gt;
* &lt;script type="text/javascript"&gt;
* function setValue() {
* var picker = dojo.widget.byId("picker");
*
* //string value
* picker.setValue('2007-01-01');
*
* //Date value
* picker.setValue(new Date());
* }
*
* function showValue() {
* var picker = dojo.widget.byId("picker");
*
* //string value
* var stringValue = picker.getValue();
* alert(stringValue);
*
* //date value
* var dateValue = picker.getDate();
* alert(dateValue);
* }
* &lt;/script&gt;
* </pre>
* <!-- END SNIPPET: example2 -->
*
* <!-- START SNIPPET: example3 -->
* <p>Publish topic when value changes</p>
* <pre>
* &lt;sx:datetimepicker id="picker" label="Order Date" valueNotifyTopics="/value"/&gt;
*
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/value", function(textEntered, date, widget){
* alert('value changed');
* //textEntered: String enetered in the textbox
* //date: JavaScript Date object with the value selected
* //widet: widget that published the topic
* });
* &lt;/script&gt;
* </pre>
* <!-- END SNIPPET: example3 -->
*/
@StrutsTag(name="datetimepicker", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.DateTimePickerTag", description="Render datetimepicker")
public class DateTimePicker extends UIBean {
final public static String TEMPLATE = "datetimepicker";
final private static SimpleDateFormat RFC3339_FORMAT = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss");
final protected static Log LOG = LogFactory.getLog(DateTimePicker.class);
protected String iconPath;
protected String formatLength;
protected String displayFormat;
protected String toggleType;
protected String toggleDuration;
protected String type;
protected String displayWeeks;
protected String adjustWeeks;
protected String startDate;
protected String endDate;
protected String weekStartsOn;
protected String staticDisplay;
protected String dayWidth;
protected String language;
protected String templateCssPath;
protected String valueNotifyTopics;
public DateTimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
public void evaluateParams() {
super.evaluateParams();
if(displayFormat != null)
addParameter("displayFormat", findString(displayFormat));
if(displayWeeks != null)
addParameter("displayWeeks", findString(displayWeeks));
if(adjustWeeks != null)
addParameter("adjustWeeks", findValue(adjustWeeks, Boolean.class));
if(startDate != null)
addParameter("startDate", format(findValue(startDate)));
if(endDate != null)
addParameter("endDate", format(findValue(endDate)));
if(weekStartsOn != null)
addParameter("weekStartsOn", findString(weekStartsOn));
if(staticDisplay != null)
addParameter("staticDisplay", findValue(staticDisplay, Boolean.class));
if(dayWidth != null)
addParameter("dayWidth", findValue(dayWidth, Integer.class));
if(language != null)
addParameter("language", findString(language));
if(value != null)
addParameter("value", format(findValue(value)));
if(iconPath != null)
addParameter("iconPath", findString(iconPath));
if(formatLength != null)
addParameter("formatLength", findString(formatLength));
if(toggleType != null)
addParameter("toggleType", findString(toggleType));
if(toggleDuration != null)
addParameter("toggleDuration", findValue(toggleDuration,
Integer.class));
if(type != null)
addParameter("type", findString(type));
else
addParameter("type", "date");
if(templateCssPath != null)
addParameter("templateCssPath", findString(templateCssPath));
if(valueNotifyTopics != null)
addParameter("valueNotifyTopics", findString(valueNotifyTopics));
// format the value to RFC 3399
if(parameters.containsKey("value")) {
parameters.put("nameValue", parameters.get("value"));
} else {
if(name != null) {
addParameter("nameValue", format(findValue(name)));
}
}
boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
addParameter("pushId", generateId);
if ((this.id == null || this.id.length() == 0) && generateId) {
Random random = new Random();
this.id = "widget_" + Math.abs(random.nextInt());
addParameter("id", this.id);
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
@StrutsTagAttribute(description="If true, weekly size of calendar changes to acomodate the month if false," +
" 42 day format is used", type="Boolean", defaultValue="false")
public void setAdjustWeeks(String adjustWeeks) {
this.adjustWeeks = adjustWeeks;
}
@StrutsTagAttribute(description="How to render the names of the days in the header(narrow, abbr or wide)", defaultValue="narrow")
public void setDayWidth(String dayWidth) {
this.dayWidth = dayWidth;
}
@StrutsTagAttribute(description="Total weeks to display", type="Integer", defaultValue="6")
public void setDisplayWeeks(String displayWeeks) {
this.displayWeeks = displayWeeks;
}
@StrutsTagAttribute(description="Last available date in the calendar set", type="Date", defaultValue="2941-10-12")
public void setEndDate(String endDate) {
this.endDate = endDate;
}
@StrutsTagAttribute(description="First available date in the calendar set", type="Date", defaultValue="1492-10-12")
public void setStartDate(String startDate) {
this.startDate = startDate;
}
@StrutsTagAttribute(description="Disable all incremental controls, must pick a date in the current display", type="Boolean", defaultValue="false")
public void setStaticDisplay(String staticDisplay) {
this.staticDisplay = staticDisplay;
}
@StrutsTagAttribute(description="Adjusts the first day of the week 0==Sunday..6==Saturday", type="Integer", defaultValue="0")
public void setWeekStartsOn(String weekStartsOn) {
this.weekStartsOn = weekStartsOn;
}
@StrutsTagAttribute(description="Language to display this widget in", defaultValue="brower's specified preferred language")
public void setLanguage(String language) {
this.language = language;
}
@StrutsTagAttribute(description="A pattern used for the visual display of the formatted date, e.g. dd/MM/yyyy")
public void setDisplayFormat(String displayFormat) {
this.displayFormat = displayFormat;
}
@StrutsTagAttribute(description="Type of formatting used for visual display. Possible values are " +
"long, short, medium or full", defaultValue="short")
public void setFormatLength(String formatLength) {
this.formatLength = formatLength;
}
@StrutsTagAttribute(description="Path to icon used for the dropdown")
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
@StrutsTagAttribute(description="Duration of toggle in milliseconds", type="Integer", defaultValue="100")
public void setToggleDuration(String toggleDuration) {
this.toggleDuration = toggleDuration;
}
@StrutsTagAttribute(description="Defines the type of the picker on the dropdown. Possible values are 'date'" +
" for a DateTimePicker, and 'time' for a timePicker", defaultValue="date")
public void setType(String type) {
this.type = type;
}
@StrutsTagAttribute(description="oggle type of the dropdown. Possible values are plain,wipe,explode,fade", defaultValue="plain")
public void setToggleType(String toggleType) {
this.toggleType = toggleType;
}
@StrutsTagAttribute(description="Template css path")
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
@StrutsTagAttribute(description="Preset the value of input element")
public void setValue(String arg0) {
super.setValue(arg0);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published when a value is selected")
public void setValueNotifyTopics(String valueNotifyTopics) {
this.valueNotifyTopics = valueNotifyTopics;
}
private String format(Object obj) {
if(obj == null)
return null;
if(obj instanceof Date) {
return RFC3339_FORMAT.format((Date) obj);
} else if(obj instanceof Calendar) {
return RFC3339_FORMAT.format(((Calendar) obj).getTime());
}
else {
// try to parse a date
String dateStr = obj.toString();
if(dateStr.equalsIgnoreCase("today"))
return RFC3339_FORMAT.format(new Date());
Date date = null;
//formats used to parse the date
List<DateFormat> formats = new ArrayList<DateFormat>();
formats.add(RFC3339_FORMAT);
formats.add(SimpleDateFormat.getTimeInstance(DateFormat.SHORT));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.SHORT));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.MEDIUM));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.FULL));
formats.add(SimpleDateFormat.getDateInstance(DateFormat.LONG));
if (this.displayFormat != null) {
try {
SimpleDateFormat displayFormat = new SimpleDateFormat(
(String) getParameters().get("displayFormat"));
formats.add(displayFormat);
} catch (Exception e) {
// don't use it then (this attribute is used by Dojo, not java code)
LOG.error(e);
}
}
for (DateFormat format : formats) {
try {
date = format.parse(dateStr);
if (date != null)
return RFC3339_FORMAT.format(date);
} catch (Exception e) {
//keep going
}
}
// last resource, assume already in correct/default format
if (LOG.isDebugEnabled())
LOG.debug("Unable to parse date " + dateStr);
return dateStr;
}
}
}
@@ -76,13 +76,17 @@ import com.opensymphony.xwork2.util.ValueStack;
*
* <p>The "locale" attribute configures Dojo's locale:</p>
*
* "The locale Dojo uses on a page may be overridden by setting djConfig.locale. This may be
* <p>"The locale Dojo uses on a page may be overridden by setting djConfig.locale. This may be
* done to accomodate applications with a known user profile or server pages which do manual
* assembly and assume a certain locale. You may also set djConfig.extraLocale to load
* localizations in addition to your own, in case you want to specify a particular
* translation or have multiple languages appear on your page."</p>
*
* <p>Dojo 0.4.2 is distributed with the Dojo plugin, to use a different Dojo version, the
* <p>To improve loading time, the property "parseContent" is set to false by default. This property will
* instruct Dojo to only build widgets using specific element ids. If the property is set to true
* Dojo will scan the whole document looking for widgets.</p>
*
* <p>Dojo 0.4.3 is distributed with the Dojo plugin, to use a different Dojo version, the
* "baseRelativePath" attribute can be set to the URL of the Dojo root folder on your application.
* </p>
* <!-- END SNIPPET: javadoc -->
@@ -113,13 +117,15 @@ import com.opensymphony.xwork2.util.ValueStack;
@StrutsTagSkipInheritance
public class Head extends org.apache.struts2.components.Head {
public static final String TEMPLATE = "head";
public static final String PARSE_CONTENT = "struts.dojo.head.parseContent";
private String debug;
private String compressed;
private String baseRelativePath;
private String extraLocales;
private String locale;
private String cache;
private String parseContent;
public Head(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
@@ -146,6 +152,14 @@ public class Head extends org.apache.struts2.components.Head {
addParameter("locale", findString(this.locale));
if (this.cache != null)
addParameter("cache", findValue(this.cache, Boolean.class));
if (this.parseContent != null) {
Boolean shouldParseContent = (Boolean) findValue(this.parseContent, Boolean.class);
addParameter("parseContent", shouldParseContent);
stack.getContext().put(PARSE_CONTENT, shouldParseContent);
} else {
addParameter("parseContent", false);
stack.getContext().put(PARSE_CONTENT, false);
}
}
@Override
@@ -193,4 +207,9 @@ public class Head extends org.apache.struts2.components.Head {
public void setCache(String cache) {
this.cache = cache;
}
@StrutsTagAttribute(description="Parse the whole document for widgets", defaultValue="false", type="Boolean")
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
@@ -1,466 +1,475 @@
/*
* $Id: Submit.java 508285 2007-02-16 02:42:24Z musachy $
*
* 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.dojo.components;
import java.io.Writer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.components.Form;
import org.apache.struts2.components.FormButton;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* Renders a submit button that can submit a form asynchronously.
* The submit can have three different types of rendering:
* <ul>
* <li>input: renders as html &lt;input type="submit"...&gt;</li>
* <li>image: renders as html &lt;input type="image"...&gt;</li>
* <li>button: renders as html &lt;button type="submit"...&gt;</li>
* </ul>
* Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
* text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
* <!-- END SNIPPET: javadoc -->
*
* <p>Examples</p>
* <pre>
* <!-- START SNIPPET: example1 -->
* &lt;sx:submit value="%{'Submit'}" /&gt;
* <!-- END SNIPPET: example1 -->
* </pre>
* <pre>
* <!-- START SNIPPET: example2 -->
* Render an image submit:
* &lt;sx:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/&gt;
* <!-- END SNIPPET: example2 -->
* </pre>
* <pre>
* <!-- START SNIPPET: example3 -->
* Render an button submit:
* &lt;sx:submit type="button" value="%{'Submit'}" label="Submit the form"/&gt;
* <!-- END SNIPPET: example3 -->
* </pre>
*
* <!-- START SNIPPET: example4 -->
* <p>Update target content with html returned from an action:</p>
* <pre>
* &lt;div id="div1"&gt;Div 1&lt;/div&gt;
* &lt;s:url id="ajaxTest" value="/AjaxTest.action"/&gt;
*
* &lt;sx:submit id="link1" href="%{ajaxTest}" target="div1" /&gt;
* </pre>
* <!-- END SNIPPET: example4 -->
*
* <!-- START SNIPPET: example5 -->
* <p>Submit form(inside the form):</p>
* <pre>
* &lt;s:form id="form" action="AjaxTest"&gt;
* &lt;input type="textbox" name="data"&gt;
* &lt;sx:submit /&gt;
* &lt;/s:form&gt;
* </pre>
* <!-- END SNIPPET: example5 -->
*
* <!-- START SNIPPET: example6 -->
* <p>Submit form(outside the form)</p>
* <pre>
* &lt;s:form id="form" action="AjaxTest"&gt;
* &lt;input type="textbox" name="data"&gt;
* &lt;/s:form&gt;
*
* &lt;sx:submit formId="form" /&gt;
* </pre>
* <!-- END SNIPPET: example6 -->
*
* <!-- START SNIPPET: example7 -->
* <p>Using beforeNotifyTopics:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/before", function(event, widget){
* alert('inside a topic event. before request');
* //event: set event.cancel = true, to cancel request
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;sx:submit beforeNotifyTopics="/before" /&gt;
* </pre>
* <!-- END SNIPPET: example7 -->
*
* <!-- START SNIPPET: example8 -->
* <p>Using afterNotifyTopics and highlight target:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/after", function(data, request, widget){
* alert('inside a topic event. after request');
* //data : text returned from request(the html)
* //request: XMLHttpRequest object
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;sx:submit afterNotifyTopics="/after" highlightColor="red" href="%{#ajaxTest}" /&gt;
* </pre>
* <!-- END SNIPPET: example5 -->
*
* <!-- START SNIPPET: example6 -->
* <p>Using errorNotifyTopics and indicator:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/error", function(error, request, widget){
* alert('inside a topic event. on error');
* //error : error object (error.message has the error message)
* //request: XMLHttpRequest object
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;img id="ind1" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none"/&gt;
* &lt;sx:submit errorNotifyTopics="/error" indicator="ind1" href="%{#ajaxTest}" /&gt;
* </pre>
* <!-- END SNIPPET: example6 -->
*/
@StrutsTag(name="submit", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.SubmitTag", description="Render a submit button")
public class Submit extends FormButton implements RemoteBean {
private static final Log LOG = LogFactory.getLog(Submit.class);
final public static String TEMPLATE = "submit";
protected String href;
protected String errorText;
protected String executeScripts;
protected String loadingText;
protected String listenTopics;
protected String handler;
protected String formId;
protected String formFilter;
protected String src;
protected String notifyTopics;
protected String showErrorTransportText;
protected String indicator;
protected String showLoadingText;
protected String targets;
protected String beforeNotifyTopics;
protected String afterNotifyTopics;
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
protected String separateScripts;
protected String transport;
protected String parseContent;
public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
public void evaluateParams() {
if ((key == null) && (value == null)) {
value = "Submit";
}
if (((key != null)) && (value == null)) {
this.value = "%{getText('"+key +"')}";
}
super.evaluateParams();
}
public void evaluateExtraParams() {
super.evaluateExtraParams();
if (href != null)
addParameter("href", findString(href));
if (errorText != null)
addParameter("errorText", findString(errorText));
if (loadingText != null)
addParameter("loadingText", findString(loadingText));
if (executeScripts != null)
addParameter("executeScripts", findValue(executeScripts, Boolean.class));
if (listenTopics != null)
addParameter("listenTopics", findString(listenTopics));
if (notifyTopics != null)
addParameter("notifyTopics", findString(notifyTopics));
if (handler != null)
addParameter("handler", findString(handler));
if (formId != null)
addParameter("formId", findString(formId));
if (formFilter != null)
addParameter("formFilter", findString(formFilter));
if (src != null)
addParameter("src", findString(src));
if (indicator != null)
addParameter("indicator", findString(indicator));
if (targets != null)
addParameter("targets", findString(targets));
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (beforeNotifyTopics != null)
addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
if (afterNotifyTopics != null)
addParameter("afterNotifyTopics", findString(afterNotifyTopics));
if (errorNotifyTopics != null)
addParameter("errorNotifyTopics", findString(errorNotifyTopics));
if (highlightColor != null)
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
if (transport != null)
addParameter("transport", findString(transport));
if (parseContent != null)
addParameter("parseContent", findValue(parseContent, Boolean.class));
Boolean validateValue = false;
if (validate != null) {
validateValue = (Boolean) findValue(validate, Boolean.class);
addParameter("validate", validateValue);
}
Form form = (Form) findAncestor(Form.class);
if (form != null)
addParameter("parentTheme", form.getTheme());
if (ajaxAfterValidation != null)
addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
/**
* Indicate whether the concrete button supports the type "image".
*
* @return <tt>true</tt> to indicate type image is supported.
*/
protected boolean supportsImageType() {
return true;
}
/**
* Overrides to be able to render body in a template rather than always before the template
*/
public boolean end(Writer writer, String body) {
evaluateParams();
try {
addParameter("body", body);
mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
} catch (Exception e) {
LOG.error("error when rendering", e);
}
finally {
popComponentStack();
}
return false;
}
@StrutsTagAttribute(description="Topic that will trigger the remote call")
public void setListenTopics(String listenTopics) {
this.listenTopics = listenTopics;
}
@StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
public void setHref(String href) {
this.href = href;
}
@StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
public void setErrorText(String errorText) {
this.errorText = errorText;
}
@StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
public void setExecuteScripts(String executeScripts) {
this.executeScripts = executeScripts;
}
@StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
public void setLoadingText(String loadingText) {
this.loadingText = loadingText;
}
@StrutsTagAttribute(description="Javascript function name that will make the request")
public void setHandler(String handler) {
this.handler = handler;
}
@StrutsTagAttribute(description="Function name used to filter the fields of the form.")
public void setFormFilter(String formFilter) {
this.formFilter = formFilter;
}
@StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
public void setFormId(String formId) {
this.formId = formId;
}
@StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
public void setSrc(String src) {
this.src = src;
}
@StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
public void setTargets(String targets) {
this.targets = targets;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
public void setNotifyTopics(String notifyTopics) {
this.notifyTopics = notifyTopics;
}
@StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
public void setShowErrorTransportText(String showErrorTransportText) {
this.showErrorTransportText = showErrorTransportText;
}
@StrutsTagAttribute(description="Set indicator")
public void setIndicator(String indicator) {
this.indicator = indicator;
}
@StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
public void setShowLoadingText(String showLoadingText) {
this.showLoadingText = showLoadingText;
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
@StrutsTagAttribute(description="The type of submit to use. Valid values are <i>input</i>, " +
"<i>button</i> and <i>image</i>.", defaultValue="input")
public void setType(String type) {
super.setType(type);
}
@StrutsTagAttribute(description="Preset the value of input element.")
public void setValue(String value) {
super.setValue(value);
}
@StrutsTagAttribute(description="Label expression used for rendering a element specific label")
public void setLabel(String label) {
super.setLabel(label);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
public void setAfterNotifyTopics(String afterNotifyTopics) {
this.afterNotifyTopics = afterNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
public void setBeforeNotifyTopics(String beforeNotifyTopics) {
this.beforeNotifyTopics = beforeNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
public void setErrorNotifyTopics(String errorNotifyTopics) {
this.errorNotifyTopics = errorNotifyTopics;
}
@StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute",
defaultValue = "none")
public void setHighlightColor(String highlightColor) {
this.highlightColor = highlightColor;
}
@StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set",
defaultValue = "1000")
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
defaultValue = "false")
public void setValidate(String validate) {
this.validate = validate;
}
@StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid if 'validate' is 'true'", type="Boolean",
defaultValue = "false")
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
@StrutsTagSkipInheritance
public void setAction(String action) {
super.setAction(action);
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
@StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
public void setTransport(String transport) {
this.transport = transport;
}
@StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
/*
* $Id: Submit.java 508285 2007-02-16 02:42:24Z musachy $
*
* 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.dojo.components;
import java.io.Writer;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.components.Form;
import org.apache.struts2.components.FormButton;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* Renders a submit button that can submit a form asynchronously.
* The submit can have three different types of rendering:
* <ul>
* <li>input: renders as html &lt;input type="submit"...&gt;</li>
* <li>image: renders as html &lt;input type="image"...&gt;</li>
* <li>button: renders as html &lt;button type="submit"...&gt;</li>
* </ul>
* Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
* text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
* <!-- END SNIPPET: javadoc -->
*
* <p>Examples</p>
* <pre>
* <!-- START SNIPPET: example1 -->
* &lt;sx:submit value="%{'Submit'}" /&gt;
* <!-- END SNIPPET: example1 -->
* </pre>
* <pre>
* <!-- START SNIPPET: example2 -->
* Render an image submit:
* &lt;sx:submit type="image" value="%{'Submit'}" label="Submit the form" src="submit.gif"/&gt;
* <!-- END SNIPPET: example2 -->
* </pre>
* <pre>
* <!-- START SNIPPET: example3 -->
* Render an button submit:
* &lt;sx:submit type="button" value="%{'Submit'}" label="Submit the form"/&gt;
* <!-- END SNIPPET: example3 -->
* </pre>
*
* <!-- START SNIPPET: example4 -->
* <p>Update target content with html returned from an action:</p>
* <pre>
* &lt;div id="div1"&gt;Div 1&lt;/div&gt;
* &lt;s:url id="ajaxTest" value="/AjaxTest.action"/&gt;
*
* &lt;sx:submit id="link1" href="%{ajaxTest}" target="div1" /&gt;
* </pre>
* <!-- END SNIPPET: example4 -->
*
* <!-- START SNIPPET: example5 -->
* <p>Submit form(inside the form):</p>
* <pre>
* &lt;s:form id="form" action="AjaxTest"&gt;
* &lt;input type="textbox" name="data"&gt;
* &lt;sx:submit /&gt;
* &lt;/s:form&gt;
* </pre>
* <!-- END SNIPPET: example5 -->
*
* <!-- START SNIPPET: example6 -->
* <p>Submit form(outside the form)</p>
* <pre>
* &lt;s:form id="form" action="AjaxTest"&gt;
* &lt;input type="textbox" name="data"&gt;
* &lt;/s:form&gt;
*
* &lt;sx:submit formId="form" /&gt;
* </pre>
* <!-- END SNIPPET: example6 -->
*
* <!-- START SNIPPET: example7 -->
* <p>Using beforeNotifyTopics:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/before", function(event, widget){
* alert('inside a topic event. before request');
* //event: set event.cancel = true, to cancel request
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;sx:submit beforeNotifyTopics="/before" /&gt;
* </pre>
* <!-- END SNIPPET: example7 -->
*
* <!-- START SNIPPET: example8 -->
* <p>Using afterNotifyTopics and highlight target:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/after", function(data, request, widget){
* alert('inside a topic event. after request');
* //data : text returned from request(the html)
* //request: XMLHttpRequest object
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;sx:submit afterNotifyTopics="/after" highlightColor="red" href="%{#ajaxTest}" /&gt;
* </pre>
* <!-- END SNIPPET: example5 -->
*
* <!-- START SNIPPET: example6 -->
* <p>Using errorNotifyTopics and indicator:</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/error", function(error, request, widget){
* alert('inside a topic event. on error');
* //error : error object (error.message has the error message)
* //request: XMLHttpRequest object
* //widget: widget that published the topic
* });
* &lt;/script&gt;
*
* &lt;img id="ind1" src="${pageContext.request.contextPath}/images/indicator.gif" style="display:none"/&gt;
* &lt;sx:submit errorNotifyTopics="/error" indicator="ind1" href="%{#ajaxTest}" /&gt;
* </pre>
* <!-- END SNIPPET: example6 -->
*/
@StrutsTag(name="submit", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.SubmitTag", description="Render a submit button")
public class Submit extends FormButton implements RemoteBean {
private static final Log LOG = LogFactory.getLog(Submit.class);
final public static String TEMPLATE = "submit";
protected String href;
protected String errorText;
protected String executeScripts;
protected String loadingText;
protected String listenTopics;
protected String handler;
protected String formId;
protected String formFilter;
protected String src;
protected String notifyTopics;
protected String showErrorTransportText;
protected String indicator;
protected String showLoadingText;
protected String targets;
protected String beforeNotifyTopics;
protected String afterNotifyTopics;
protected String errorNotifyTopics;
protected String highlightColor;
protected String highlightDuration;
protected String validate;
protected String ajaxAfterValidation;
protected String separateScripts;
protected String transport;
protected String parseContent;
public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
public void evaluateParams() {
if ((key == null) && (value == null)) {
value = "Submit";
}
if (((key != null)) && (value == null)) {
this.value = "%{getText('"+key +"')}";
}
super.evaluateParams();
}
public void evaluateExtraParams() {
super.evaluateExtraParams();
if (href != null)
addParameter("href", findString(href));
if (errorText != null)
addParameter("errorText", findString(errorText));
if (loadingText != null)
addParameter("loadingText", findString(loadingText));
if (executeScripts != null)
addParameter("executeScripts", findValue(executeScripts, Boolean.class));
if (listenTopics != null)
addParameter("listenTopics", findString(listenTopics));
if (notifyTopics != null)
addParameter("notifyTopics", findString(notifyTopics));
if (handler != null)
addParameter("handler", findString(handler));
if (formId != null)
addParameter("formId", findString(formId));
if (formFilter != null)
addParameter("formFilter", findString(formFilter));
if (src != null)
addParameter("src", findString(src));
if (indicator != null)
addParameter("indicator", findString(indicator));
if (targets != null)
addParameter("targets", findString(targets));
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (showLoadingText != null)
addParameter("showLoadingText", findString(showLoadingText));
if (beforeNotifyTopics != null)
addParameter("beforeNotifyTopics", findString(beforeNotifyTopics));
if (afterNotifyTopics != null)
addParameter("afterNotifyTopics", findString(afterNotifyTopics));
if (errorNotifyTopics != null)
addParameter("errorNotifyTopics", findString(errorNotifyTopics));
if (highlightColor != null)
addParameter("highlightColor", findString(highlightColor));
if (highlightDuration != null)
addParameter("highlightDuration", findString(highlightDuration));
if (separateScripts != null)
addParameter("separateScripts", findValue(separateScripts, Boolean.class));
if (transport != null)
addParameter("transport", findString(transport));
if (parseContent != null)
addParameter("parseContent", findValue(parseContent, Boolean.class));
Boolean validateValue = false;
if (validate != null) {
validateValue = (Boolean) findValue(validate, Boolean.class);
addParameter("validate", validateValue);
}
Form form = (Form) findAncestor(Form.class);
if (form != null)
addParameter("parentTheme", form.getTheme());
if (ajaxAfterValidation != null)
addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
addParameter("pushId", generateId);
if ((this.id == null || this.id.length() == 0) && generateId) {
Random random = new Random();
this.id = "widget_" + Math.abs(random.nextInt());
addParameter("id", this.id);
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
/**
* Indicate whether the concrete button supports the type "image".
*
* @return <tt>true</tt> to indicate type image is supported.
*/
protected boolean supportsImageType() {
return true;
}
/**
* Overrides to be able to render body in a template rather than always before the template
*/
public boolean end(Writer writer, String body) {
evaluateParams();
try {
addParameter("body", body);
mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
} catch (Exception e) {
LOG.error("error when rendering", e);
}
finally {
popComponentStack();
}
return false;
}
@StrutsTagAttribute(description="Topic that will trigger the remote call")
public void setListenTopics(String listenTopics) {
this.listenTopics = listenTopics;
}
@StrutsTagAttribute(description="The URL to call to obtain the content. Note: If used with ajax context, the value must be set as an url tag value.")
public void setHref(String href) {
this.href = href;
}
@StrutsTagAttribute(description="The text to display to the user if the is an error fetching the content")
public void setErrorText(String errorText) {
this.errorText = errorText;
}
@StrutsTagAttribute(description="Javascript code in the fetched content will be executed", type="Boolean", defaultValue="false")
public void setExecuteScripts(String executeScripts) {
this.executeScripts = executeScripts;
}
@StrutsTagAttribute(description="Text to be shown while content is being fetched", defaultValue="Loading...")
public void setLoadingText(String loadingText) {
this.loadingText = loadingText;
}
@StrutsTagAttribute(description="Javascript function name that will make the request")
public void setHandler(String handler) {
this.handler = handler;
}
@StrutsTagAttribute(description="Function name used to filter the fields of the form.")
public void setFormFilter(String formFilter) {
this.formFilter = formFilter;
}
@StrutsTagAttribute(description="Form id whose fields will be serialized and passed as parameters")
public void setFormId(String formId) {
this.formId = formId;
}
@StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
public void setSrc(String src) {
this.src = src;
}
@StrutsTagAttribute(description="Comma delimited list of ids of the elements whose content will be updated")
public void setTargets(String targets) {
this.targets = targets;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before and after the request, and on errors")
public void setNotifyTopics(String notifyTopics) {
this.notifyTopics = notifyTopics;
}
@StrutsTagAttribute(description="Set whether errors will be shown or not", type="Boolean", defaultValue="true")
public void setShowErrorTransportText(String showErrorTransportText) {
this.showErrorTransportText = showErrorTransportText;
}
@StrutsTagAttribute(description="Set indicator")
public void setIndicator(String indicator) {
this.indicator = indicator;
}
@StrutsTagAttribute(description="Show loading text on targets", type="Boolean", defaultValue="false")
public void setShowLoadingText(String showLoadingText) {
this.showLoadingText = showLoadingText;
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
@StrutsTagAttribute(description="The type of submit to use. Valid values are <i>input</i>, " +
"<i>button</i> and <i>image</i>.", defaultValue="input")
public void setType(String type) {
super.setType(type);
}
@StrutsTagAttribute(description="Preset the value of input element.")
public void setValue(String value) {
super.setValue(value);
}
@StrutsTagAttribute(description="Label expression used for rendering a element specific label")
public void setLabel(String label) {
super.setLabel(label);
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request succeeds)")
public void setAfterNotifyTopics(String afterNotifyTopics) {
this.afterNotifyTopics = afterNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published before the request")
public void setBeforeNotifyTopics(String beforeNotifyTopics) {
this.beforeNotifyTopics = beforeNotifyTopics;
}
@StrutsTagAttribute(description="Comma delimmited list of topics that will published after the request(if the request fails)")
public void setErrorNotifyTopics(String errorNotifyTopics) {
this.errorNotifyTopics = errorNotifyTopics;
}
@StrutsTagAttribute(description = "Color used to perform a highlight effect on the elements specified in the 'targets' attribute",
defaultValue = "none")
public void setHighlightColor(String highlightColor) {
this.highlightColor = highlightColor;
}
@StrutsTagAttribute(description = "Duration of highlight effect in milliseconds. Only valid if 'highlightColor' attribute is set",
defaultValue = "1000")
public void setHighlightDuration(String highlightDuration) {
this.highlightDuration = highlightDuration;
}
@StrutsTagAttribute(description = "Perform Ajax calidation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
defaultValue = "false")
public void setValidate(String validate) {
this.validate = validate;
}
@StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid if 'validate' is 'true'", type="Boolean",
defaultValue = "false")
public void setAjaxAfterValidation(String ajaxAfterValidation) {
this.ajaxAfterValidation = ajaxAfterValidation;
}
@StrutsTagSkipInheritance
public void setAction(String action) {
super.setAction(action);
}
@StrutsTagAttribute(description="Run scripts in a separate scope, unique for each tag", defaultValue="true")
public void setSeparateScripts(String separateScripts) {
this.separateScripts = separateScripts;
}
@StrutsTagAttribute(description="Transport used by Dojo to make the request", defaultValue="XMLHTTPTransport")
public void setTransport(String transport) {
this.transport = transport;
}
@StrutsTagAttribute(description="Parse returned HTML for Dojo widgets", defaultValue="true", type="Boolean")
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
@@ -1,214 +1,223 @@
/*
* $Id: TabbedPanel.java 508575 2007-02-16 20:46:49Z musachy $
*
* 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.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* The tabbedpanel widget is primarily an AJAX component, where each tab can either be local content or remote
* content (refreshed each time the user selects that tab).</p>
* If the useSelectedTabCookie attribute is set to true, the id of the selected tab is saved in a cookie on activation.
* When coming back to this view, the cookie is read and the tab will be activated again, unless an actual value for the
* selectedTab attribute is specified.</p>
* If you want to use the cookie feature, please be sure that you provide a unique id for your tabbedpanel component,
* since this will also be the identifying name component of the stored cookie.</p>
* <!-- END SNIPPET: javadoc -->
*
* <p/> <b>Examples</b>
* <p/>
* <!-- START SNIPPET: exdesc -->
* The following is an example of a tabbedpanel and panel tag utilizing local and remote content.<p/>
* <!-- END SNIPPET: exdesc -->
*
* <!-- START SNIPPET: example -->
* <pre>
* &lt;s:tabbedpanel id="test" &gt;
* &lt;s:div id="one" label="one" theme="ajax" labelposition="top" &gt;
* This is the first pane&lt;br/&gt;
* &lt;s:form&gt;
* &lt;s:textfield name="tt" label="Test Text"/&gt; &lt;br/&gt;
* &lt;s:textfield name="tt2" label="Test Text2"/&gt;
* &lt;/s:form&gt;
* &lt;/s:div&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* This is the remote tab
* &lt;/s:div&gt;
* &lt;/s:tabbedpanel&gt;
* </pre>
* <!-- END SNIPPET: example -->
*
* <!-- START SNIPPET: example2 -->
* <p>Use notify topics to prevent a tab from being selected</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/beforeSelect", function(event, tab, tabContainer){
* event.cancel = true;
* });
* &lt;/script&gt;
*
* &lt;s:tabbedpanel id="test" beforeSelectTabNotifyTopics="/beforeSelect"&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* One Tab
* &lt;/s:div&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* Another tab
* &lt;/s:div&gt;
* &lt;/s:tabbedpanel&gt;
* </pre>
* <!-- END SNIPPET: example2 -->
*/
@StrutsTag(name="tabbedpanel", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TabbedPanelTag", description="Render a tabbedPanel widget.")
public class TabbedPanel extends ClosingUIBean {
public static final String TEMPLATE = "tabbedpanel";
public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
final private static String COMPONENT_NAME = TabbedPanel.class.getName();
protected String selectedTab;
protected String closeButton;
protected String doLayout ;
protected String templateCssPath;
protected String beforeSelectTabNotifyTopics;
protected String afterSelectTabNotifyTopics;
protected String disabledTabCssClass;
protected String useSelectedTabCookie;
public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected void evaluateExtraParams() {
super.evaluateExtraParams();
if (selectedTab != null)
addParameter("selectedTab", findString(selectedTab));
if (closeButton != null)
addParameter("closeButton", findString(closeButton));
addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE);
if (labelPosition != null) {
//dojo has some weird name for label positions
if(labelPosition.equalsIgnoreCase("left"))
labelPosition = "left-h";
if(labelPosition.equalsIgnoreCase("right"))
labelPosition = "right-h";
addParameter("labelPosition", null);
addParameter("labelPosition", labelPosition);
}
if (templateCssPath != null)
addParameter("templateCssPath", findString(templateCssPath));
if (beforeSelectTabNotifyTopics!= null)
addParameter("beforeSelectTabNotifyTopics", findString(beforeSelectTabNotifyTopics));
if (afterSelectTabNotifyTopics!= null)
addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics));
if (disabledTabCssClass!= null)
addParameter("disabledTabCssClass", findString(disabledTabCssClass));
if(useSelectedTabCookie != null) {
addParameter("useSelectedTabCookie", findString(useSelectedTabCookie));
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
public String getDefaultOpenTemplate() {
return TEMPLATE;
}
protected String getDefaultTemplate() {
return TEMPLATE_CLOSE;
}
public String getComponentName() {
return COMPONENT_NAME;
}
@StrutsTagAttribute(description="The id to assign to the component.", required=true)
public void setId(String id) {
// This is required to override tld generation attributes to required=true
super.setId(id);
}
@StrutsTagAttribute(description=" The id of the tab that will be selected by default")
public void setSelectedTab(String selectedTab) {
this.selectedTab = selectedTab;
}
@StrutsTagAttribute(description="Deprecated. Use 'closable' on each div(tab)")
public void setCloseButton(String closeButton) {
this.closeButton = closeButton;
}
@StrutsTagAttribute(description="If doLayout is false, the tab container's height equals the height of the currently selected tab", type="Boolean", defaultValue="false")
public void setDoLayout(String doLayout) {
this.doLayout = doLayout;
}
@StrutsTagAttribute(description="Template css path")
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
@StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (before it is selected)" +
"The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget." +
"The event can be cancelled setting to 'true' the 'cancel' property " +
"of the third parameter passed to the topics.")
public void setBeforeSelectTabNotifyTopics(String selectedTabNotifyTopics) {
this.beforeSelectTabNotifyTopics = selectedTabNotifyTopics;
}
@StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (after it is selected)." +
"The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget.")
public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
}
@StrutsTagAttribute(description="Css class to be applied to the tab button of disabled tabs", defaultValue="strutsDisabledTab")
public void setDisabledTabCssClass(String disabledTabCssClass) {
this.disabledTabCssClass = disabledTabCssClass;
}
@StrutsTagAttribute(required = false, defaultValue = "false", description = "If set to true, the id of the last selected " +
"tab will be stored in cookie. If the view is rendered, it will be tried to read this cookie and activate " +
"the corresponding tab on success, unless overridden by the selectedTab attribute. The cookie name is \"Struts2TabbedPanel_selectedTab_\"+id.")
public void setUseSelectedTabCookie( String useSelectedTabCookie ) {
this.useSelectedTabCookie = useSelectedTabCookie;
}
}
/*
* $Id: TabbedPanel.java 508575 2007-02-16 20:46:49Z musachy $
*
* 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.dojo.components;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
* The tabbedpanel widget is primarily an AJAX component, where each tab can either be local content or remote
* content (refreshed each time the user selects that tab).</p>
* If the useSelectedTabCookie attribute is set to true, the id of the selected tab is saved in a cookie on activation.
* When coming back to this view, the cookie is read and the tab will be activated again, unless an actual value for the
* selectedTab attribute is specified.</p>
* If you want to use the cookie feature, please be sure that you provide a unique id for your tabbedpanel component,
* since this will also be the identifying name component of the stored cookie.</p>
* <!-- END SNIPPET: javadoc -->
*
* <p/> <b>Examples</b>
* <p/>
* <!-- START SNIPPET: exdesc -->
* The following is an example of a tabbedpanel and panel tag utilizing local and remote content.<p/>
* <!-- END SNIPPET: exdesc -->
*
* <!-- START SNIPPET: example -->
* <pre>
* &lt;s:tabbedpanel id="test" &gt;
* &lt;s:div id="one" label="one" theme="ajax" labelposition="top" &gt;
* This is the first pane&lt;br/&gt;
* &lt;s:form&gt;
* &lt;s:textfield name="tt" label="Test Text"/&gt; &lt;br/&gt;
* &lt;s:textfield name="tt2" label="Test Text2"/&gt;
* &lt;/s:form&gt;
* &lt;/s:div&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* This is the remote tab
* &lt;/s:div&gt;
* &lt;/s:tabbedpanel&gt;
* </pre>
* <!-- END SNIPPET: example -->
*
* <!-- START SNIPPET: example2 -->
* <p>Use notify topics to prevent a tab from being selected</p>
* <pre>
* &lt;script type="text/javascript"&gt;
* dojo.event.topic.subscribe("/beforeSelect", function(event, tab, tabContainer){
* event.cancel = true;
* });
* &lt;/script&gt;
*
* &lt;s:tabbedpanel id="test" beforeSelectTabNotifyTopics="/beforeSelect"&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* One Tab
* &lt;/s:div&gt;
* &lt;s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" &gt;
* Another tab
* &lt;/s:div&gt;
* &lt;/s:tabbedpanel&gt;
* </pre>
* <!-- END SNIPPET: example2 -->
*/
@StrutsTag(name="tabbedpanel", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TabbedPanelTag", description="Render a tabbedPanel widget.")
public class TabbedPanel extends ClosingUIBean {
public static final String TEMPLATE = "tabbedpanel";
public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
final private static String COMPONENT_NAME = TabbedPanel.class.getName();
protected String selectedTab;
protected String closeButton;
protected String doLayout ;
protected String templateCssPath;
protected String beforeSelectTabNotifyTopics;
protected String afterSelectTabNotifyTopics;
protected String disabledTabCssClass;
protected String useSelectedTabCookie;
public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
protected void evaluateExtraParams() {
super.evaluateExtraParams();
if (selectedTab != null)
addParameter("selectedTab", findString(selectedTab));
if (closeButton != null)
addParameter("closeButton", findString(closeButton));
addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE);
if (labelPosition != null) {
//dojo has some weird name for label positions
if(labelPosition.equalsIgnoreCase("left"))
labelPosition = "left-h";
if(labelPosition.equalsIgnoreCase("right"))
labelPosition = "right-h";
addParameter("labelPosition", null);
addParameter("labelPosition", labelPosition);
}
if (templateCssPath != null)
addParameter("templateCssPath", findString(templateCssPath));
if (beforeSelectTabNotifyTopics!= null)
addParameter("beforeSelectTabNotifyTopics", findString(beforeSelectTabNotifyTopics));
if (afterSelectTabNotifyTopics!= null)
addParameter("afterSelectTabNotifyTopics", findString(afterSelectTabNotifyTopics));
if (disabledTabCssClass!= null)
addParameter("disabledTabCssClass", findString(disabledTabCssClass));
if(useSelectedTabCookie != null) {
addParameter("useSelectedTabCookie", findString(useSelectedTabCookie));
}
boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
addParameter("pushId", generateId);
if ((this.id == null || this.id.length() == 0) && generateId) {
Random random = new Random();
this.id = "widget_" + Math.abs(random.nextInt());
addParameter("id", this.id);
}
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
public String getDefaultOpenTemplate() {
return TEMPLATE;
}
protected String getDefaultTemplate() {
return TEMPLATE_CLOSE;
}
public String getComponentName() {
return COMPONENT_NAME;
}
@StrutsTagAttribute(description="The id to assign to the component.", required=true)
public void setId(String id) {
// This is required to override tld generation attributes to required=true
super.setId(id);
}
@StrutsTagAttribute(description=" The id of the tab that will be selected by default")
public void setSelectedTab(String selectedTab) {
this.selectedTab = selectedTab;
}
@StrutsTagAttribute(description="Deprecated. Use 'closable' on each div(tab)")
public void setCloseButton(String closeButton) {
this.closeButton = closeButton;
}
@StrutsTagAttribute(description="If doLayout is false, the tab container's height equals the height of the currently selected tab", type="Boolean", defaultValue="false")
public void setDoLayout(String doLayout) {
this.doLayout = doLayout;
}
@StrutsTagAttribute(description="Template css path")
public void setTemplateCssPath(String templateCssPath) {
this.templateCssPath = templateCssPath;
}
@StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (before it is selected)" +
"The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget." +
"The event can be cancelled setting to 'true' the 'cancel' property " +
"of the third parameter passed to the topics.")
public void setBeforeSelectTabNotifyTopics(String selectedTabNotifyTopics) {
this.beforeSelectTabNotifyTopics = selectedTabNotifyTopics;
}
@StrutsTagAttribute(description="Comma separated list of topics to be published when a tab is clicked on (after it is selected)." +
"The tab container widget will be passed as the first argument to the topic. The second parameter is the tab widget.")
public void setAfterSelectTabNotifyTopics(String afterSelectTabNotifyTopics) {
this.afterSelectTabNotifyTopics = afterSelectTabNotifyTopics;
}
@StrutsTagAttribute(description="Css class to be applied to the tab button of disabled tabs", defaultValue="strutsDisabledTab")
public void setDisabledTabCssClass(String disabledTabCssClass) {
this.disabledTabCssClass = disabledTabCssClass;
}
@StrutsTagAttribute(required = false, defaultValue = "false", description = "If set to true, the id of the last selected " +
"tab will be stored in cookie. If the view is rendered, it will be tried to read this cookie and activate " +
"the corresponding tab on success, unless overridden by the selectedTab attribute. The cookie name is \"Struts2TabbedPanel_selectedTab_\"+id.")
public void setUseSelectedTabCookie( String useSelectedTabCookie ) {
this.useSelectedTabCookie = useSelectedTabCookie;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,136 +1,153 @@
/*
* $Id: TreeNode.java 497654 2007-01-19 00:21:57Z rgielen $
*
* 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.dojo.components;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
*
* Renders a tree node within a tree widget with AJAX support.<p/>
*
* Either of the following combinations should be used depending on if the tree
* is to be constrcted dynamically or statically. <p/>
*
* <b>Dynamically</b>
* <ul>
* <li>id - id of this tree node</li>
* <li>title - label to be displayed for this tree node</li>
* </ul>
*
* <b>Statically</b>
* <ul>
* <li>rootNode - the parent node of which this tree is derived from</li>
* <li>nodeIdProperty - property to obtained this current tree node's id</li>
* <li>nodeTitleProperty - property to obtained this current tree node's title</li>
* <li>childCollectionProperty - property that returnds this current tree node's children</li>
* </ul>
*
* <!-- END SNIPPET: javadoc -->
*
* <p/> <b>Examples</b>
*
* <pre>
* <!-- START SNIPPET: example -->
*
* &lt-- statically --&gt;
* &lt;s:tree id="..." label="..."&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;s:treenode id="..." label="..."&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &;lt;/s:treenode&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;/s:tree&gt;
*
* &lt;-- dynamically --&gt;
* &lt;s:tree
* id="..."
* rootNode="..."
* nodeIdProperty="..."
* nodeTitleProperty="..."
* childCollectionProperty="..." /&gt;
*
* <!-- END SNIPPET: example -->
* </pre>
*
*/
@StrutsTag(name="treenode", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TreeNodeTag", description="Render a tree node within a tree widget.")
public class TreeNode extends ClosingUIBean {
private static final String TEMPLATE = "treenode-close";
private static final String OPEN_TEMPLATE = "treenode";
public TreeNode(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
public String getDefaultOpenTemplate() {
return OPEN_TEMPLATE;
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
@StrutsTagAttribute(description="Label expression used for rendering tree node label.", required=true)
public void setLabel(String label) {
super.setLabel(label);
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
}
/*
* $Id: TreeNode.java 497654 2007-01-19 00:21:57Z rgielen $
*
* 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.dojo.components;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import org.apache.struts2.views.annotations.StrutsTagSkipInheritance;
import com.opensymphony.xwork2.util.ValueStack;
/**
* <!-- START SNIPPET: javadoc -->
*
* Renders a tree node within a tree widget with AJAX support.<p/>
*
* Either of the following combinations should be used depending on if the tree
* is to be constrcted dynamically or statically. <p/>
*
* <b>Dynamically</b>
* <ul>
* <li>id - id of this tree node</li>
* <li>title - label to be displayed for this tree node</li>
* </ul>
*
* <b>Statically</b>
* <ul>
* <li>rootNode - the parent node of which this tree is derived from</li>
* <li>nodeIdProperty - property to obtained this current tree node's id</li>
* <li>nodeTitleProperty - property to obtained this current tree node's title</li>
* <li>childCollectionProperty - property that returnds this current tree node's children</li>
* </ul>
*
* <!-- END SNIPPET: javadoc -->
*
* <p/> <b>Examples</b>
*
* <pre>
* <!-- START SNIPPET: example -->
*
* &lt-- statically --&gt;
* &lt;s:tree id="..." label="..."&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;s:treenode id="..." label="..."&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &;lt;/s:treenode&gt;
* &lt;s:treenode id="..." label="..." /&gt;
* &lt;/s:tree&gt;
*
* &lt;-- dynamically --&gt;
* &lt;s:tree
* id="..."
* rootNode="..."
* nodeIdProperty="..."
* nodeTitleProperty="..."
* childCollectionProperty="..." /&gt;
*
* <!-- END SNIPPET: example -->
* </pre>
*
*/
@StrutsTag(name="treenode", tldTagClass="org.apache.struts2.dojo.views.jsp.ui.TreeNodeTag", description="Render a tree node within a tree widget.")
public class TreeNode extends ClosingUIBean {
private static final String TEMPLATE = "treenode-close";
private static final String OPEN_TEMPLATE = "treenode";
public TreeNode(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
super(stack, request, response);
}
@Override
@StrutsTagSkipInheritance
public void setTheme(String theme) {
super.setTheme(theme);
}
@Override
public String getTheme() {
return "ajax";
}
public String getDefaultOpenTemplate() {
return OPEN_TEMPLATE;
}
protected String getDefaultTemplate() {
return TEMPLATE;
}
protected void evaluateExtraParams() {
super.evaluateExtraParams();
boolean generateId = !(Boolean)stack.getContext().get(Head.PARSE_CONTENT);
addParameter("pushId", generateId);
if ((this.id == null || this.id.length() == 0) && generateId) {
Random random = new Random();
this.id = "widget_" + Math.abs(random.nextInt());
addParameter("id", this.id);
}
Tree parentTree = (Tree) findAncestor(Tree.class);
parentTree.addChildrenId(this.id);
}
@StrutsTagAttribute(description="Label expression used for rendering tree node label.", required=true)
public void setLabel(String label) {
super.setLabel(label);
}
@StrutsTagAttribute(description="The css class to use for element")
public void setCssClass(String cssClass) {
super.setCssClass(cssClass);
}
@StrutsTagAttribute(description="The css style to use for element")
public void setCssStyle(String cssStyle) {
super.setCssStyle(cssStyle);
}
@StrutsTagAttribute(description="The id to use for the element")
public void setId(String id) {
super.setId(id);
}
@StrutsTagAttribute(description="The name to set for element")
public void setName(String name) {
super.setName(name);
}
}
@@ -42,6 +42,7 @@ public class HeadTag extends AbstractUITag {
private String extraLocales;
private String locale;
private String cache;
private String parseContent;
public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
return new Head(stack, req, res);
@@ -57,6 +58,7 @@ public class HeadTag extends AbstractUITag {
head.setExtraLocales(extraLocales);
head.setLocale(locale);
head.setCache(cache);
head.setParseContent(parseContent);
}
public void setDebug(String debug) {
@@ -82,4 +84,8 @@ public class HeadTag extends AbstractUITag {
public void setCache(String cache) {
this.cache = cache;
}
public void setParseContent(String parseContent) {
this.parseContent = parseContent;
}
}
@@ -21,3 +21,6 @@
*/
-->
</a>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -173,5 +173,8 @@
<#if parameters.label?if_exists != "">
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />
</#if>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -20,3 +20,6 @@
* under the License.
*/
-->
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -97,3 +97,6 @@
<#if parameters.label?if_exists != "">
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />
</#if>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -21,3 +21,6 @@
*/
-->
</div>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -42,6 +42,8 @@
</#list>
]
</#if>
,parseWidgets : ${parameters.parseContent?string}
};
</script>
@@ -93,4 +93,7 @@
<#else>
</span> <#t/>
</#if>
</#if>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -21,3 +21,6 @@
*/
-->
</div>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -21,3 +21,6 @@
*/
-->
</div>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("${parameters.id?html}");</script>
</#if>
@@ -21,3 +21,16 @@
*/
-->
<#if parameters.label?exists></div></#if></div>
<#if parameters.pushId>
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("treeSelector_${parameters.id?default("")?html}");
djConfig.searchIds.push("${parameters.id?html}");
<#if parameters.childrenIds?exists>
djConfig.searchIds.push(<#rt>
<#list parameters.childrenIds as childId>
"${childId?html}"<#if childId_has_next>,</#if><#t>
</#list>
);<#t>
</#if>
</script>
</#if>
@@ -30,7 +30,9 @@
</script>
<#if parameters.selectedNotifyTopics?exists || parameters.expandedNotifyTopics?exists
|| parameters.collapsedNotifyTopics?exists>
<struts:StrutsTreeSelector widgetId="treeSelector_${parameters.id?default("")}"
<struts:StrutsTreeSelector
id="treeSelector_${parameters.id?default("")}"
widgetId="treeSelector_${parameters.id?default("")}"
<#if parameters.selectedNotifyTopics?exists>
selectedNotifyTopics="${parameters.selectedNotifyTopics?html}"
</#if>
+2 -2
View File
@@ -1,8 +1,8 @@
To build the Struts Dojo profile:
1. Checkout Dojo from svn (${dojo} refers to root dir)
1. Checkout Dojo from svn (${dojo} refers to dojo's root dir) (make sure that ${dojo} is on the same folder as ${struts})
2. Copy struts.profile.js tp ${dojo}/buildscripts/profiles
2. Copy struts.profile.js to ${dojo}/buildscripts/profiles
3. Copy /plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/struts/ComboBox.css to
${dojo}/struts (Dojo build system doesn't resolve the relative paths that well in 0.4.2)
@@ -35,6 +35,7 @@ import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.dojo.TestAction;
import org.apache.struts2.dojo.components.Head;
import com.mockobjects.dynamic.Mock;
import com.opensymphony.xwork2.Action;
@@ -85,6 +86,7 @@ public abstract class AbstractTagTest extends StrutsTestCase {
stack = ValueStackFactory.getFactory().createValueStack();
context = stack.getContext();
stack.push(action);
context.put(Head.PARSE_CONTENT, false);
request = new StrutsMockHttpServletRequest();
request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
@@ -38,6 +38,7 @@ public class AutocompleterTest extends AbstractUITagTest {
tag.setSearchType("b");
tag.setDisabled("c");
tag.setName("f");
tag.setId("f");
tag.setValue("g");
tag.setIndicator("h");
tag.setKeyName("i");
@@ -70,6 +71,7 @@ public class AutocompleterTest extends AbstractUITagTest {
tag.setSearchType("b");
tag.setDisabled("c");
tag.setName("f");
tag.setId("f");
tag.setIconPath("i");
tag.setTemplateCssPath("j");
tag.setValueNotifyTopics("k");
@@ -21,6 +21,7 @@
package org.apache.struts2.dojo.views.jsp.ui;
import org.apache.struts2.dojo.TestAction;
import org.apache.struts2.dojo.components.Head;
/**
@@ -40,6 +40,7 @@ public class HeadTagTest extends AbstractUITagTest {
tag.setBaseRelativePath("/path");
tag.setLocale("es");
tag.setCache("true");
tag.setParseContent("true");
tag.doStartTag();
tag.doEndTag();
@@ -28,7 +28,7 @@ public class TabbedPanelTagTest extends AbstractUITagTest {
public void testSimple() throws Exception {
TabbedPanelTag tag = new TabbedPanelTag();
tag.setPageContext(pageContext);
tag.setId("a");
tag.doStartTag();
tag.doEndTag();
@@ -23,3 +23,4 @@
transport="m"
preload="true"
/>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("f");</script>
@@ -18,3 +18,4 @@
<option value="d">d</option>
<option value="e">e</option>
</select>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("f");</script>
@@ -25,4 +25,5 @@
"parseContent" : false
});
});
</script>
</script>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("a");</script>
@@ -14,4 +14,5 @@
valueNotifyTopics="k"
saveFormat="rfc">
</div>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("id");</script>
@@ -10,7 +10,8 @@
"a",
"b",
"c"
]
],
parseWidgets: true
};
</script>
@@ -1,32 +1,33 @@
<script language="JavaScript" type="text/javascript">
// Dojo configuration
djConfig={
isDebug: false,
bindEncoding: "ISO-8859-1",
baseRelativePath: "/struts/dojo/",
baseScriptUri: "/struts/dojo/",
locale: "es",
extraLocale: [
"a",
"b",
"c"
]
};
</script>
<script language="JavaScript" type="text/javascript" src="/struts/dojo/dojo.js">
</script>
<script language="JavaScript" type="text/javascript" src="/struts/ajax/dojoRequire.js">
</script>
<link rel="stylesheet" href="/struts/xhtml/styles.css" type="text/css"/>
<script language="JavaScript" src="/struts/utils.js" type="text/javascript">
</script>
<script language="JavaScript" src="/struts/xhtml/validation.js" type="text/javascript">
</script>
<script language="JavaScript"src="/struts/css_xhtml/validation.js" type="text/javascript">
<script language="JavaScript" type="text/javascript">
// Dojo configuration
djConfig={
isDebug: false,
bindEncoding: "ISO-8859-1",
baseRelativePath: "/struts/dojo/",
baseScriptUri: "/struts/dojo/",
locale: "es",
extraLocale: [
"a",
"b",
"c"
],
parseWidgets: false
};
</script>
<script language="JavaScript" type="text/javascript" src="/struts/dojo/dojo.js">
</script>
<script language="JavaScript" type="text/javascript" src="/struts/ajax/dojoRequire.js">
</script>
<link rel="stylesheet" href="/struts/xhtml/styles.css" type="text/css"/>
<script language="JavaScript" src="/struts/utils.js" type="text/javascript">
</script>
<script language="JavaScript" src="/struts/xhtml/validation.js" type="text/javascript">
</script>
<script language="JavaScript"src="/struts/css_xhtml/validation.js" type="text/javascript">
</script>
@@ -1,5 +1,7 @@
<linkrel="stylesheet" href="/struts/TabbedPanel.css" type="text/css"/>
<div
dojoType="struts:StrutsTabContainer"
id="a"
doLayout="false">
</div>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("a");</script>
@@ -14,4 +14,5 @@ dojo.addOnLoad(function(){
});
</script>
<div dojoType="struts:StrutsTabContainer" id="foo" doLayout="false">
</div>
</div>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("foo");</script>
@@ -10,4 +10,5 @@ dojo.addOnLoad(function(){
});
</script>
<div dojoType="struts:StrutsTabContainer" id="foo" selectedTab="bar" doLayout="false">
</div>
</div>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("foo");</script>
@@ -25,3 +25,4 @@
transport="q"
parseContent="false">
</div>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("mylabel");</script>
@@ -22,3 +22,4 @@
transport="o"
parseContent="false">
</a>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("mylink");</script>
@@ -25,3 +25,4 @@
transport="p"
parseContent="false"
/>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("a");</script>
@@ -17,4 +17,5 @@
indicator="l"
scriptSeparation="true"
value="i"
/>
/>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("a");</script>
@@ -20,4 +20,5 @@
handler="h"
indicator="l"
scriptSeparation="true"
/>
/>
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("a");</script>
@@ -39,4 +39,9 @@
id="child3"
title="Child 4">
</div>
</div></div>
</div></div>
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("treeSelector_rootId");
djConfig.searchIds.push("rootId");
djConfig.searchIds.push("child1","child1","child2","gChild1","gChild1","gChild2","gChild2","gChild3","gChild3","child2","child3","child3");
</script>
@@ -61,4 +61,8 @@
</div>
</div>
</div>
</div>
</div>
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("treeSelector_myTree");
djConfig.searchIds.push("myTree");
</script>