You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2008/08/06 11:34:45 UTC
svn commit: r683198 [5/8] - in
/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext: ./ .settings/
src/ src/META-INF/ src/org/ src/org/apache/ src/org/apache/empire/
src/org/apache/empire/struts2/ src/org/apache/empire/struts2/action/
src/org/apac...
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,348 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.Locale;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.empire.commons.ErrorInfo;
+import org.apache.empire.commons.ErrorType;
+import org.apache.empire.commons.Options;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.struts2.action.RequestParamProvider;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.views.util.TextUtil;
+
+
+public abstract class InputControl
+{
+ // Logger
+ protected static Log log = LogFactory.getLog(InputControl.class);
+
+ // Special Input Column Attributes
+ public static final String NUMBER_FORMAT_ATTRIBUTE = "numberFormat"; // "Integer", "Currency", "Percent"
+ public static final String NUMBER_GROUPSEP_ATTRIBUTE = "numberGroupSeparator"; // boolean
+ public static final String NUMBER_FRACTION_DIGITS = "numberFractionDigits"; // integer
+ public static final String MINVALUE_ATTRIBUTE = "minValue";
+ public static final String MAXVALUE_ATTRIBUTE = "maxValue";
+ public static final String CURRENCY_CODE_ATTRIBUTE = "currencyCode"; // "ISO 4217 code of the currency"
+ public static final String FILE_DATA_COLUMN_ATTRIBUTE = "fileDataColumn";
+
+ /**
+ * This interface allows access to a value and its metainformation
+ * used with the renderData function
+ */
+ public interface ValueInfo
+ {
+ Column getColumn();
+ Options getOptions();
+ Object getValue();
+ Object getNullValue();
+ Locale getUserLocale();
+ String getFormat(); // Custom Formatting options specific to each InputControl-type
+ String getOnclick();
+ String getOndblclick();
+ String getTranslation(String text);
+ String getCssClass();
+ String getCssStyle();
+ String getId();
+ }
+
+ /**
+ * This interface extends the value information by information about the input control
+ * used with the renderInput function
+ */
+ public interface ControlInfo extends ValueInfo
+ {
+ String getName();
+ boolean hasError(); // Indicates wheter the value supplied might be invalid
+ boolean getDisabled(); // readOnly
+ int getHSize();
+ int getVSize();
+ String getTabindex();
+ // String getAccesskey();
+ String getOnchange();
+ String getOnfocus();
+ String getOnblur();
+ }
+
+ /**
+ * The NO_VALUE constant is used as a return value from getFieldValue
+ * to indicate that the value for this column has not been provided
+ */
+ public static final Object NO_VALUE = null; // Fiels has not been specified and will be ignored
+
+ /**
+ * The NULL_VALUE constant is used as a return value from getFieldValue
+ * to indicate that the field value was provided with the request, but is empty
+ * so that the underlying database field should be set to null
+ */
+ public static final Object NULL_VALUE = ""; // Field will be set to NULL
+
+
+ /**
+ * This class wraps a parsing or validation error.
+ * You should not use this class directly but through the error function of InputControl
+ */
+ public static final class FieldValueError implements ErrorInfo
+ {
+ private ErrorType errType; // Type of error
+ private String[] errParams; // Error message params
+ private String errSource; // Source object's class name
+ private String errValue;
+ public FieldValueError(ErrorType errorType, String[] msgParams, String value, Class source)
+ {
+ errType = errorType;
+ errParams = msgParams;
+ errSource = source.getName();
+ this.errValue = value;
+ }
+ public boolean hasError()
+ {
+ return true;
+ }
+ public ErrorType getErrorType()
+ {
+ return errType;
+ }
+ public String getValue()
+ {
+ return errValue;
+ }
+ public String[] getErrorParams()
+ {
+ return errParams;
+ }
+ public String getErrorSource()
+ {
+ return errSource;
+ }
+
+ }
+
+ /**
+ * This method can be used to return a parsing or validation error
+ * To be used in the getFieldValue, the parseValue or the validate function.
+ * It is a shortcut for writing
+ * return error(InputErrors.xxxx, null, value)
+ * instead of
+ * return new FieldValueError(InputErrors.xxxx, null, value, getClass());
+ *
+ * @return the field Error Object
+ */
+ protected final FieldValueError error(ErrorType errorType, String[] msgParams, String value)
+ {
+ return new FieldValueError(errorType, msgParams, value, getClass());
+ }
+
+ protected final FieldValueError error(ErrorType errorType, Object msgParam, String value)
+ {
+ return error(errorType, new String[] { StringUtils.toString(msgParam) }, value);
+ }
+
+ /**
+ * This method determines whether an id should be put on the input label
+ * If true than the renderInput function must add an id attribute to an input field
+ * The value of the id is supplied with the ControlInfo
+ *
+ * @return true if an id should be set on the label or false otherwise
+ */
+ public boolean useLabelId()
+ {
+ return true;
+ }
+
+ /**
+ * this method parses and validates the value of a particular column from the request
+ *
+ * @param name the name under which the param is stored on the request
+ * @param request used to access the request Parameters
+ * @param column the column for which the value should be
+ * @return the parsed and validated record field value or a FieldValueError if an error occurred
+ */
+ public Object getFieldValue(String name, RequestParamProvider request, Locale locale, Column column)
+ {
+ String value = request.getRequestParam(name);
+ if (value==null)
+ return NO_VALUE;
+ // Empty String?
+ value = value.trim();
+ if (value.length()==0)
+ return NULL_VALUE;
+ // Parse value
+ Object object = parseValue(value, locale, column);
+ if (object instanceof FieldValueError)
+ return object;
+ // Done
+ return validate(object, locale, column, value);
+ }
+
+ /**
+ * this method renders a record value read only
+ * this can be either in a read only form or a table
+ *
+ * @param writer the HtmlWriter for html write-out
+ * @param vi Object holding the value and meta-information about the value
+ */
+ public void renderText(HtmlWriter writer, ValueInfo vi)
+ {
+ if (vi instanceof ControlInfo)
+ { // Wrap read only in a div if it's a control
+ ControlInfo ci = ((ControlInfo)vi);
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlTag div = writer.startTag(dic.InputReadOnlyDataWrapperTag());
+ div.addAttribute("id", ci.getId());
+ div.addAttribute("class", ci.getCssClass());
+ div.addAttribute("style", ci.getCssStyle());
+ div.beginBody();
+ internalRenderText(writer, vi);
+ div.endTag();
+ }
+ else
+ {
+ internalRenderText(writer, vi);
+ }
+ }
+
+ /**
+ * this method renders a record value for input
+ *
+ * @param writer the HtmlWriter for html write-out
+ * @param ci Object holding the value and meta-information about the value and the control
+ */
+ public abstract void renderInput(HtmlWriter writer, ControlInfo ci);
+
+ // ------- helpers -------
+
+ /**
+ * this method renders a record value read only
+ * it is internally called by renderText
+ *
+ * @param writer the HtmlWriter for html write-out
+ * @param vi Object holding the value and meta-information about the value
+ */
+ protected void internalRenderText(HtmlWriter writer, ValueInfo vi)
+ {
+ printText(writer, formatValue(vi), " ");
+ }
+
+ /**
+ * writes out plain text to the output stream
+ * if the text supplied is null or an empty String then a is written
+ *
+ * @param writer the HtmlWriter for html write-out
+ * @param text the text to write
+ */
+ protected final void printText(HtmlWriter writer, String text, String defaultValue)
+ {
+ writer.print((text!=null && text.length()>0) ? text : defaultValue);
+ }
+
+ /**
+ * this function may be overridden to parse and convert the input value
+ * to the data type of the supplied column
+ *
+ * @param value the value string from the request
+ * @param the user locale
+ * @param the column for which the value is supplied
+ *
+ * @return the parsed value
+ */
+ protected Object parseValue(String value, Locale locale, Column column)
+ {
+ return value;
+ }
+
+ /**
+ * this function may be overridden to validate a value that has
+ * previously been parsed
+ *
+ * @param value the parsed object value
+ * @param the column for which the value should be validated
+ * @param s the unparsed value string. In case of an error this should be forwarded to the error function.
+ *
+ * @return the parsed value
+ */
+ protected Object validate(Object value, Locale locale, Column column, String s)
+ {
+ return value;
+ }
+
+ /**
+ * Returns the value formated as a string
+ * this is a simple default implementation that does no type-secific formatting
+ * Derived classes may override formatString an provide further formmatting
+ * see TextInputControl for details
+ *
+ * @param value the value to be formatted
+ * @param vi Meta-information about the value
+ *
+ * @return the formatted value
+ */
+ protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+ {
+ // Lookup and Print value
+ Options options = vi.getOptions();
+ if (options != null && !options.isEmpty())
+ { // Check for Options
+ String text = options.get(value);
+ if (text != null)
+ return vi.getTranslation(text);
+ // Error
+ log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list.");
+ }
+ // value
+ if (value==null)
+ value = vi.getNullValue();
+ // Convert to String
+ String s = StringUtils.valueOf(value);
+ if (hasFormatOption(vi, "noencode"))
+ return s;
+ // Encode Html
+ return TextUtil.escapeHTML(s, false);
+ }
+
+ /**
+ * Returns the value formated as a string
+ * This is a shortcut for formatString(vi.getValue(), vi)
+ * Derived classes may override formatString
+ */
+ protected final String formatValue(ValueInfo vi)
+ {
+ boolean hasError = ((vi instanceof ControlInfo) && ((ControlInfo)vi).hasError());
+ return formatValue(vi.getValue(), vi, hasError);
+ }
+
+ /**
+ * checks if a particular formating option has been specified.
+ * @param vi the value info
+ * @param option the formating option to check
+ * @return true if the requested formating option has been specified or false otherwise
+ */
+ protected boolean hasFormatOption(ValueInfo vi, String option)
+ {
+ String format = vi.getFormat();
+ return (format!=null ? format.indexOf(option)>=0 : false);
+ }
+
+ protected String getFormatOption(ValueInfo vi, String option)
+ {
+ // Is unit supplied with format
+ String format = vi.getFormat();
+ if (format==null)
+ return null;
+ // Check for option
+ int beg = format.indexOf(option);
+ if (beg < 0)
+ return null;
+ // Find
+ beg = beg + option.length();
+ int end = format.indexOf(';', beg+1);
+ if (end < beg)
+ return format.substring(beg);
+ // The cbValue
+ return format.substring(beg, end);
+ }
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControlManager.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControlManager.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControlManager.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/InputControlManager.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,38 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.HashMap;
+
+public final class InputControlManager
+{
+ static HashMap<String, InputControl> controlMap = null;
+
+ static {
+
+ controlMap = new HashMap<String, InputControl>();
+
+ registerControl("text", new TextInputControl());
+ registerControl("select", new SelectInputControl());
+ registerControl("checkbox", new CheckboxInputControl());
+ registerControl("phone", new PhoneInputControl());
+ registerControl("radio", new RadioInputControl());
+ registerControl("textarea", new TextAreaInputControl());
+ registerControl("email", new EMailInputControl());
+ registerControl("hlink", new HLinkInputControl());
+ registerControl("password", new PasswordInputControl());
+ }
+
+ private InputControlManager()
+ {
+ // Default Constructor
+ }
+
+ public static void registerControl(String name, InputControl control)
+ {
+ controlMap.put(name, control);
+ }
+
+ public static InputControl getControl(String name)
+ {
+ return controlMap.get(name);
+ }
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PasswordInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PasswordInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PasswordInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PasswordInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,98 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.Locale;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.empire.struts2.web.WebErrors;
+
+
+public class PasswordInputControl extends InputControl
+{
+ public static final String PASSWORD_NOT_CHANGED = "********";
+
+
+ private int getMinPasswordLength()
+ {
+ return 6;
+ }
+
+ // ------- parsing -------
+
+ @Override
+ protected Object parseValue(String value, Locale locale, Column column)
+ {
+ // Has password changed
+ if (value.equals(PASSWORD_NOT_CHANGED))
+ return NO_VALUE;
+ // Default
+ return value;
+ }
+
+ @Override
+ protected Object validate(Object value, Locale locale, Column column, String s)
+ {
+ String pwd = StringUtils.toString(value);
+ int minLength = getMinPasswordLength();
+ if (pwd!=null && pwd.length()<minLength)
+ {
+ return error(WebErrors.InputTextTooShort, minLength, s);
+ }
+ // Default
+ return value;
+ }
+
+ // ------- formatting -------
+
+ @Override
+ protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+ {
+ String pwd = StringUtils.toString(value);
+ if (hasError)
+ return "";
+ // Replace by Default-Mask
+ return (StringUtils.isValid(pwd) ? PASSWORD_NOT_CHANGED : null);
+ }
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ HtmlTag input = writer.startTag("input");
+ input.addAttribute("type", "password");
+ input.addAttribute("id", ci.getId());
+ input.addAttribute("class", ci.getCssClass());
+ input.addAttribute("style", ci.getCssStyle());
+ if (ci.getDisabled()==false)
+ { // Name of the field
+ input.addAttribute("name", ci.getName());
+ // Get Max Length
+ int maxLength = (int)ci.getColumn().getSize();
+ if (maxLength>0)
+ {
+ input.addAttribute("maxlength", maxLength);
+ input.addAttribute("size", String.valueOf(Math.min(maxLength, ci.getHSize())));
+ }
+ }
+ else
+ { // Disabled text control
+ input.addAttribute("disabled");
+ // Get Max Length
+ int maxLength = (int)ci.getColumn().getSize();
+ if (maxLength>0)
+ {
+ input.addAttribute("size", String.valueOf(Math.min(maxLength, ci.getHSize())));
+ }
+ }
+ // Value
+ input.addAttribute("value", formatValue(ci));
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ input.endTag();
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PhoneInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PhoneInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PhoneInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/PhoneInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,181 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.Locale;
+
+import org.apache.empire.data.Column;
+import org.apache.empire.struts2.action.RequestParamProvider;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+
+
+public class PhoneInputControl extends InputControl
+{
+ // public static String TYPE_NAME = "phone";
+ /*
+ <input type="text" name="employee.lastName" size="40" value="" id="employeeDetail_employee_lastName"/
+ */
+
+ private static final String LKZ = "__LKZ"; // Landeskennzahl
+ private static final String OKZ = "__OKZ"; // Ortskennzahl
+ private static final String TKZ = "__TKZ"; // Teilenehmerkennzahl
+
+ @Override
+ public Object getFieldValue(String name, RequestParamProvider request, Locale locale, Column column)
+ {
+ String lkz = request.getRequestParam(name + LKZ);
+ String okz = request.getRequestParam(name + OKZ);
+ String tnk = request.getRequestParam(name + TKZ);
+ if (lkz==null && okz==null && tnk==null)
+ return NO_VALUE;
+ // Get Phone number
+ return getPhone(lkz, okz, tnk);
+ }
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ String phone = formatValue(ci);
+ String lkz = GetLKZ(phone);
+ String okz = GetOKZ(phone);
+ String tnr = GetTNR(phone);
+
+ renderPart(writer, ci, LKZ, lkz, 4, false);
+ writer.print(" - ");
+ renderPart(writer, ci, OKZ, okz, 8, false);
+ writer.print(" - ");
+ renderPart(writer, ci, TKZ, tnr, 20, true);
+ }
+
+ // Phone specific helper functions
+ private void renderPart(HtmlWriter writer, ControlInfo ci, String namePostFix, String part, int size, boolean setIdForLabel)
+ {
+ HtmlTag input = writer.startTag("input");
+ input.addAttribute("type", "text");
+ input.addAttribute("id", (setIdForLabel) ? ci.getId() : null);
+ input.addAttribute("class", ci.getCssClass());
+ input.addAttribute("style", ci.getCssStyle());
+ input.addAttribute("size", size);
+ if (ci.getDisabled()==false)
+ {
+ input.addAttribute("name", ci.getName() + namePostFix);
+ input.addAttribute("maxLength", size);
+ }
+ else
+ {
+ input.addAttribute("disabled");
+ }
+ input.addAttribute("value", part);
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ input.endTag();
+ }
+
+ private String GetLKZ(String phone)
+ {
+ if (phone == null)
+ return"";
+ int idx = phone.indexOf('-');
+ if (idx < 0)
+ return "";
+ int end = phone.indexOf('-', idx+1);
+ if (end<0)
+ return "";
+ // done
+ return (idx>0) ? phone.substring( 0, idx) : "";
+ }
+ private String GetOKZ(String phone)
+ {
+ if (phone == null)
+ return"";
+ int idx = phone.indexOf('-');
+ if (idx < 0)
+ return "";
+ int end = phone.indexOf('-', idx+1);
+ if (end<0)
+ return phone.substring( 0, idx);
+ // done
+ return phone.substring(idx+1, end);
+ }
+ private String GetTNR(String phone)
+ {
+ if (phone == null)
+ return"";
+ int idx = phone.indexOf('-');
+ if (idx < 0)
+ return phone;
+ int end = phone.indexOf('-', idx+1);
+ if (end<0)
+ return phone.substring( idx+1 );
+ // done
+ return phone.substring(end+1);
+ }
+
+ /**
+ * return the complete telefon number (with international area code and area
+ * code) as one String
+ *
+ * @param lkz
+ * the international area code
+ * @param okz
+ * the area code
+ * @param tkn
+ * the telephone number
+ */
+ private String getPhone(String lkz, String okz, String tkn)
+ {
+ StringBuffer buf = new StringBuffer();
+ if (lkz != null && lkz.length() > 0)
+ {
+ // Landeskennzahl
+ lkz = lkz.trim();
+ // replace all '-' with '§'
+ if (lkz.indexOf('-') >= 0)
+ lkz = lkz.replace('-', '§');
+ // replace leading '00' with '+'
+ if (lkz.startsWith("00"))
+ {
+ buf.append("+");
+ buf.append(lkz.substring(2));
+ } else
+ { // append leading '+' if misssing
+ if (lkz.startsWith("+") == false)
+ buf.append("+");
+ // append lkz
+ buf.append(lkz);
+ }
+ }
+ // DMB 20030616 always append the - even if there is no lkz
+ buf.append("-");
+
+ // Area code
+ if (okz != null && okz.length() > 0)
+ {
+ okz = okz.trim();
+ // replace all '-' with '§'
+ if (okz.indexOf('-') >= 0)
+ okz = okz.replace('-', '§');
+ // append okz
+ buf.append(okz);
+ }
+ // DMB 20030616 always append the - even if there is no okz
+ buf.append("-");
+
+ // Telephone number
+ if (tkn != null && tkn.length() > 0)
+ {
+ tkn = tkn.trim();
+ buf.append(tkn);
+ }
+
+ // check phone
+ String phone = buf.toString();
+ if (phone.equals("--"))
+ return ""; // Empty Phone Number
+ // done
+ return phone;
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/RadioInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/RadioInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/RadioInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/RadioInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,167 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.Locale;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.OptionEntry;
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.Column;
+import org.apache.empire.struts2.action.RequestParamProvider;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+
+
+public class RadioInputControl extends InputControl
+{
+ private static String RBCHECK_POSTFIX = "__RBCHECK";
+
+ @Override
+ public Object getFieldValue(String name, RequestParamProvider request, Locale locale, Column column)
+ {
+ Object val = super.getFieldValue(name, request, locale, column);
+ if (val==NO_VALUE)
+ { // Is Hidden Value present
+ if (request.getRequestParam(name + RBCHECK_POSTFIX)!=null)
+ return NULL_VALUE;
+ }
+ return val;
+ }
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ HtmlTag radioGroupWrapper = writer.startTag("table");
+ radioGroupWrapper.addAttribute("cellspacing", "0");
+ radioGroupWrapper.addAttribute("cellpadding", "0");
+ radioGroupWrapper.addAttribute("id", ci.getId());
+ radioGroupWrapper.addAttribute("class", ci.getCssClass());
+ radioGroupWrapper.addAttribute("style", ci.getCssStyle());
+ radioGroupWrapper.beginBody();
+
+ // Get options
+ Options options = ci.getOptions();
+ if (options!=null)
+ { // Doing a label top, radio bottom table layout
+ if (hasFormatOption(ci, "labelAbove"))
+ {
+ renderLabelAboveControl(writer, ci, options);
+ }
+ else
+ { // Label next to control (to the left or to the right)
+ renderLabelNextToControl(writer, ci, options, hasFormatOption(ci, "labelLeft"));
+ }
+ // Add hidden field for NULL_VALUE checking
+ if (options.contains(ci.getValue())==false && ci.getDisabled()==false)
+ { // Additionally add a hidden field
+ // to detect unchecked state
+ HtmlTag hidden = writer.startTag("input");
+ hidden.addAttribute("type", "hidden");
+ hidden.addAttribute("name", ci.getName() + RBCHECK_POSTFIX);
+ hidden.addAttribute("value", ci.getValue());
+ hidden.endTag();
+ }
+ }
+ else
+ { // Error
+ log.error("No option list supplied for control type 'radio'");
+ }
+ // End Tag
+ radioGroupWrapper.endTag();
+ }
+
+ // render helpers
+ private void renderInput(HtmlWriter writer, ControlInfo ci, OptionEntry entry, int pairs)
+ {
+ boolean disabled = ci.getDisabled();
+ // Get the current value
+ Object current = ci.getValue();
+ Object value = entry.getValue();
+ // Check if the current value is the option being rendered
+ HtmlTag input = writer.startTag("input");
+ input.addAttribute("type", "radio");
+ input.addAttribute("id", ci.getId() + pairs);
+ input.addAttribute("value", value);
+ input.addAttribute("name", ci.getName());
+ // Set Checked
+ if(ObjectUtils.compareEqual(current, value))
+ {
+ input.addAttribute("checked");
+ }
+ if (disabled)
+ {
+ input.addAttribute("disabled");
+ }
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ input.endTag();
+ }
+
+ private void renderLabel(HtmlWriter writer, ControlInfo ci, OptionEntry entry, int pairs)
+ {
+ HtmlTag label = writer.startTag("label");
+ label.addAttribute("for", ci.getId() + pairs);
+ label.beginBody(ci.getTranslation(entry.getText()));
+ label.endTag();
+ }
+
+ private void renderLabelAboveControl(HtmlWriter writer, ControlInfo ci, Options options)
+ {
+ int pairs = 1;
+ HtmlTag row = writer.startTag("tr");
+ // do label row (th)
+ row.beginBody();
+ for (OptionEntry entry : options)
+ {
+ HtmlTag td = writer.startTag("th");
+ td.beginBody();
+ renderLabel(writer, ci, entry, pairs);
+ td.endTag();
+ pairs ++;
+ }
+ row.endTag();
+
+ // do radio input row (td)
+ pairs = 1;
+ row = writer.startTag("tr");
+ row.beginBody();
+ for (OptionEntry entry : options)
+ {
+ HtmlTag td = writer.startTag("td");
+ td.beginBody();
+ renderInput(writer, ci, entry, pairs);
+ td.endTag();
+ pairs ++;
+ }
+ row.endTag();
+ }
+
+ private void renderLabelNextToControl(HtmlWriter writer, ControlInfo ci, Options options, boolean labelFirst)
+ {
+ int pairs = 1;
+ // Render out the radio options in a single row table
+ HtmlTag row = writer.startTag("tr");
+ row.beginBody();
+ for (OptionEntry entry : options)
+ {
+ HtmlTag radioOptionWrapper = writer.startTag("td");
+ radioOptionWrapper.beginBody();
+ // Decide render order: (label, input) or (input, label)
+ if( labelFirst )
+ { // render td's with label buttons first then radio
+ renderLabel(writer, ci, entry, pairs);
+ renderInput(writer, ci, entry, pairs);
+ }
+ else
+ { // render td's with radio buttons first then label
+ renderInput(writer, ci, entry, pairs);
+ renderLabel(writer, ci, entry, pairs);
+ }
+ pairs ++;
+ radioOptionWrapper.endTag();
+ }
+ row.endTag();
+ }
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/SelectInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/SelectInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/SelectInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/SelectInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,76 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.OptionEntry;
+import org.apache.empire.commons.Options;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+
+
+public class SelectInputControl extends InputControl
+{
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ boolean disabled = ci.getDisabled();
+
+ HtmlTag input = writer.startTag("select");
+ input.addAttribute("id", ci.getId());
+ input.addAttribute("class", ci.getCssClass());
+ input.addAttribute("style", ci.getCssStyle());
+ if (disabled)
+ {
+ input.addAttribute("disabled");
+ } else
+ {
+ input.addAttribute("name", ci.getName());
+ }
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ input.beginBody(true);
+ // Render List of Options
+ Options options = ci.getOptions();
+ if (options!=null)
+ { // Render option list
+ Object current = ci.getValue();
+ if (hasFormatOption(ci, "allownull") && options.contains(null)==false)
+ { // add an empty entry
+ addEmtpyEntry(writer, ObjectUtils.isEmpty(current));
+ }
+ for (OptionEntry entry : options)
+ {
+ Object value = entry.getValue();
+ boolean isCurrent = ObjectUtils.compareEqual(current, value);
+ if (isCurrent == false && disabled)
+ continue; //
+ // Add Option entry
+ HtmlTag option = writer.startTag("option");
+ option.addAttributeNoCheck("value", value, true);
+ option.addAttribute("selected", isCurrent);
+ option.beginBody(ci.getTranslation(entry.getText()));
+ option.endTag(true);
+ }
+ }
+ else
+ { // No Option list available
+ log.error("No options available for select input control.");
+ }
+ // done
+ input.endTag();
+ }
+
+ private void addEmtpyEntry(HtmlWriter writer, boolean isCurrent)
+ {
+ // Add Option entry
+ HtmlTag option = writer.startTag("option");
+ option.addAttributeNoCheck("value", "", false);
+ option.addAttribute("selected", isCurrent);
+ option.beginBody("");
+ option.endTag(true);
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextAreaInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextAreaInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextAreaInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextAreaInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,112 @@
+/*
+ * ESTEAM Software GmbH, 22.07.2007
+ */
+package org.apache.empire.struts2.jsp.controls;
+
+import java.util.Locale;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+
+import com.opensymphony.xwork2.util.TextUtils;
+
+
+public class TextAreaInputControl extends InputControl
+{
+ private static final char NBSP = 160; // Non breaking space
+
+ @Override
+ protected Object parseValue(String value, Locale locale, Column column)
+ {
+ int idx;
+ int len = value.length();
+ // Remove trailing whitespace + nbsp
+ for (idx=len-1; idx>=0; idx--)
+ if (value.charAt(idx)!=NBSP && value.charAt(idx)!=' ')
+ break;
+ idx++;
+ if (idx<len)
+ value = value.substring(0, idx);
+ len = idx;
+ // Remove leading whitespace + nbsp
+ for (idx=0; idx<len; idx++)
+ if (value.charAt(idx)!=NBSP && value.charAt(idx)!=' ')
+ break;
+ if (idx>0)
+ value = value.substring(idx);
+ // Done
+ return value;
+ }
+
+ @Override
+ public void renderText(HtmlWriter writer, ValueInfo vi)
+ {
+ // Wrap read only in a div if it's a control
+ if ((vi instanceof ControlInfo))
+ {
+ ControlInfo ci = ((ControlInfo)vi);
+ // cssSTyle
+ String style = StringUtils.valueOf(ci.getCssStyle());
+ if (style.toLowerCase().indexOf("height")<0)
+ {
+ if (style.length()>0)
+ style += ";";
+ // append height
+ double height = Math.max(ci.getVSize(), 2) * 1.25;
+ style += "height:" + height + "em";
+ }
+ // Wrap read only in a div if it's a control
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlTag div = writer.startTag(dic.InputReadOnlyDataWrapperTag());
+ div.addAttribute("id", ci.getId());
+ div.addAttribute("class", ci.getCssClass());
+ div.addAttribute("style", style);
+ div.beginBody();
+ internalRenderText(writer, vi);
+ div.endTag();
+ }
+ else
+ {
+ super.internalRenderText(writer, vi);
+ }
+ }
+
+ @Override
+ protected void internalRenderText(HtmlWriter writer, ValueInfo vi)
+ {
+ String text = formatValue(vi);
+ text = StringUtils.replaceAll(text, "\r", "");
+ text = StringUtils.replaceAll(text, "\n", "<br />");
+ printText(writer, text, " ");
+ }
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ // <textarea rows="35" name="richtext" cols="120">
+
+ HtmlTag input = writer.startTag("textarea");
+ input.addAttribute("id", ci.getId());
+ input.addAttribute("class", ci.getCssClass());
+ input.addAttribute("style", ci.getCssStyle());
+ input.addAttribute("name", ci.getName());
+ input.addAttribute("disabled", ci.getDisabled());
+ input.addAttribute("rows", Math.max(ci.getVSize(), 2));
+ input.addAttribute("cols", Math.max(ci.getHSize(), 1));
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ // Body
+ String value = StringUtils.toString(ci.getValue());
+ value = TextUtils.htmlEncode(value);
+ input.beginBody(value);
+ // End
+ input.endTag();
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextInputControl.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextInputControl.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextInputControl.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/TextInputControl.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,390 @@
+package org.apache.empire.struts2.jsp.controls;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import java.util.Currency;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.Options;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.data.DataType;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.empire.struts2.web.WebErrors;
+import org.apache.struts2.views.util.TextUtil;
+
+
+public class TextInputControl extends InputControl
+{
+ public static final String FORMAT_UNIT = "unit:";
+
+ // ------- parsing -------
+
+ @Override
+ protected Object parseValue(String value, Locale locale, Column column)
+ {
+ // Check Data Type
+ DataType type = column.getDataType();
+ if (type==DataType.TEXT)
+ return value;
+ // Check other types
+ if (type==DataType.INTEGER)
+ { return parseInteger(value);
+ }
+ if (type==DataType.DECIMAL)
+ { return parseDecimal(value, getNumberFormat(column.getDataType(), locale, column));
+ }
+ if (type==DataType.DATE || type==DataType.DATETIME)
+ { return parseDate(value, getDateFormat(column.getDataType(), locale, column));
+ }
+ if (type==DataType.AUTOINC)
+ { // autoinc
+ log.error("Autoinc-value cannot be changed.");
+ return NO_VALUE;
+ }
+ // Default
+ return value;
+ }
+
+ // ------- validation -------
+
+ @Override
+ protected Object validate(Object o, Locale locale, Column column, String s)
+ {
+ if (o instanceof Number)
+ {
+ Object min = column.getAttribute(InputControl.MINVALUE_ATTRIBUTE);
+ Object max = column.getAttribute(InputControl.MAXVALUE_ATTRIBUTE);
+ if (min!=null && max!=null)
+ {
+ Number n = (Number)o;
+ if (n.intValue()<ObjectUtils.getInteger(min) ||
+ n.intValue()>ObjectUtils.getInteger(max))
+ { // Out of Range
+ return error(WebErrors.InputValueOutOfRange, new String[] { min.toString(), max.toString() }, s);
+ }
+ }
+ }
+ return o;
+ }
+
+ // ------- formatting -------
+
+ @Override
+ protected String formatValue(Object value, ValueInfo vi, boolean hasError)
+ {
+ // Lookup and Print value
+ Options options = vi.getOptions();
+ if (options != null && !options.isEmpty())
+ { // Check for Options
+ String text = options.get(value);
+ if (text != null)
+ return vi.getTranslation(text);
+ // Error
+ log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list.");
+ }
+ // Check Value
+ if (value == null)
+ { // Try to use default value
+ if (value!=vi.getNullValue())
+ return formatValue(vi.getNullValue(), vi, false);
+ // Empty String
+ return "";
+ }
+ // Format Value
+ Column column = vi.getColumn();
+ DataType dataType = getValueType(value, (column != null) ? column.getDataType() : DataType.UNKNOWN);
+ if (dataType == DataType.TEXT || dataType == DataType.UNKNOWN)
+ { // String
+ String s = String.valueOf(value);
+ if (hasFormatOption(vi, "noencode"))
+ return s;
+ // Encoded text
+ return TextUtil.escapeHTML(s);
+ }
+ if (dataType == DataType.INTEGER || dataType == DataType.AUTOINC)
+ { // Integer
+ NumberFormat nf = NumberFormat.getIntegerInstance(vi.getUserLocale());
+ nf.setGroupingUsed(false);
+ return nf.format(value);
+ }
+ if (dataType == DataType.DECIMAL || dataType == DataType.DOUBLE)
+ { // Dezimal oder Double
+ NumberFormat nf = getNumberFormat(dataType, vi.getUserLocale(), column);
+ return nf.format(value);
+ }
+ if (dataType == DataType.DATE || dataType == DataType.DATETIME)
+ { // Date or DateTime
+ if (dataType== DataType.DATETIME && hasFormatOption(vi, "notime"))
+ dataType = DataType.DATE;
+ // Now format the date according to the user's locale
+ DateFormat df = getDateFormat(dataType, vi.getUserLocale(), column);
+ return df.format(value);
+ }
+ /*
+ * if (dataType == DBDataType.BOOL) {
+ * }
+ */
+ // Convert to String
+ return TextUtil.escapeHTML(String.valueOf(value));
+ }
+
+ protected String formatValue(ValueInfo vi, boolean appendUnit)
+ {
+ String text = super.formatValue(vi);
+ if (appendUnit && text!=null && text.length()>0)
+ {
+ String unit = getUnitString(vi);
+ if (unit != null)
+ { // Append unit
+ text += " " + unit;
+ }
+ }
+ return text;
+ }
+
+ // ------- render -------
+
+ @Override
+ protected void internalRenderText(HtmlWriter writer, ValueInfo vi)
+ {
+ String text = formatValue(vi, true);
+ printText(writer, text, " ");
+ }
+
+ @Override
+ public void renderInput(HtmlWriter writer, ControlInfo ci)
+ {
+ HtmlTag input = writer.startTag("input");
+ input.addAttribute("type", "text");
+ input.addAttribute("id", ci.getId());
+ input.addAttribute("class", ci.getCssClass());
+ input.addAttribute("style", ci.getCssStyle());
+ if (ci.getDisabled()==false)
+ { // Name of the field
+ input.addAttribute("name", ci.getName());
+ // Get Max Length
+ int maxLength = getMaxInputLength(ci.getColumn());
+ if (maxLength>0)
+ {
+ input.addAttribute("maxlength", maxLength);
+ input.addAttribute("size", String.valueOf(Math.min(maxLength, ci.getHSize())));
+ }
+ }
+ else
+ { // Disabled text control
+ input.addAttribute("disabled");
+ // Get Max Length
+ int maxLength = getMaxInputLength(ci.getColumn());
+ if (maxLength>0)
+ {
+ input.addAttribute("size", String.valueOf(Math.min(maxLength, ci.getHSize())));
+ }
+ }
+ // Value
+ input.addAttribute("value", formatValue(ci, ci.getDisabled()));
+ // Event Attributes
+ input.addAttribute("onclick", ci.getOnclick());
+ input.addAttribute("onchange", ci.getOnchange());
+ input.addAttribute("onfocus", ci.getOnfocus());
+ input.addAttribute("onblur", ci.getOnblur());
+ input.endTag();
+ // Add Unit
+ if (ci.getDisabled()==false)
+ {
+ String unit = getUnitString(ci);
+ if (unit != null)
+ { writer.print(" ");
+ writer.print(unit);
+ }
+ }
+ }
+
+ // ------- Input Helpers -------
+
+ protected int getMaxInputLength(Column col)
+ {
+ // cast to DBTableColumn
+ DataType type = col.getDataType();
+ if (type==DataType.AUTOINC ||
+ type==DataType.INTEGER)
+ return 10;
+ if (type==DataType.DOUBLE)
+ return 18;
+ if (type==DataType.DECIMAL)
+ {
+ double size = col.getSize();
+ int len = (int)size;
+ size = (size - len)*10; // Ganzahlanteil
+ if (((int)size)>0)
+ len += ((int)size)+1; // Dezimaltrenner plus Nachkommastellen
+ return len;
+ }
+ if (type==DataType.BOOL)
+ return 1;
+ if (type==DataType.DATE)
+ return 10;
+ if (type==DataType.DATETIME)
+ return 16;
+ if (type==DataType.CLOB)
+ return 0; // unlimited (use 0x7FFFFFFF instead?)
+ // Default
+ return (int)col.getSize();
+ }
+
+ protected DataType getValueType(Object value, DataType desiredType)
+ {
+ // Detect Data Type from Value
+ if (value instanceof String)
+ return DataType.TEXT;
+ if (value instanceof Number)
+ { // Check desired type
+ if (desiredType == DataType.AUTOINC || desiredType == DataType.INTEGER ||
+ desiredType == DataType.DOUBLE || desiredType == DataType.DECIMAL)
+ return desiredType;
+ // Detect type
+ if (value instanceof Integer || value instanceof Long || value instanceof Short)
+ return DataType.INTEGER;
+ if (value instanceof Float || value instanceof Double)
+ return DataType.DOUBLE;
+ // default
+ return DataType.DECIMAL;
+ }
+ if (value instanceof Date)
+ { // Check desired type
+ if (desiredType == DataType.DATETIME || desiredType == DataType.DATE)
+ return desiredType;
+ // Detect type
+ if (value instanceof Timestamp)
+ return DataType.DATETIME;
+ // Just a date
+ return DataType.DATE;
+ }
+ if (value instanceof Boolean)
+ return DataType.BOOL;
+ // Default Datatype
+ return DataType.UNKNOWN;
+ }
+
+ protected NumberFormat getNumberFormat(DataType dataType, Locale locale, Column column)
+ {
+ if (column==null)
+ return NumberFormat.getNumberInstance(locale);
+ // Column is supplied
+ String type = StringUtils.valueOf(column.getAttribute(InputControl.NUMBER_FORMAT_ATTRIBUTE));
+ NumberFormat nf = null;
+ if (type.equalsIgnoreCase("Integer"))
+ nf = NumberFormat.getIntegerInstance(locale);
+ /*
+ else if (type.equalsIgnoreCase("Currency"))
+ { // nf = NumberFormat.getCurrencyInstance(locale);
+ // Currency does not work as desired!
+ nf = NumberFormat.getNumberInstance(locale);
+ }
+ else if (type.equalsIgnoreCase("Percent"))
+ nf = NumberFormat.getPercentInstance(locale);
+ */
+ else
+ nf = NumberFormat.getNumberInstance(locale);
+ // Groups Separator?
+ Object groupSep = column.getAttribute(InputControl.NUMBER_GROUPSEP_ATTRIBUTE);
+ if (groupSep!=null)
+ nf.setGroupingUsed(ObjectUtils.getBoolean(groupSep));
+ // Fraction Digits?
+ Object fractDigit = column.getAttribute(InputControl.NUMBER_FRACTION_DIGITS);
+ if (fractDigit!=null)
+ { int fractionDigits = ObjectUtils.getInteger(fractDigit);
+ nf.setMaximumFractionDigits(fractionDigits);
+ nf.setMinimumFractionDigits(fractionDigits);
+ }
+ // Number format
+ return nf;
+ }
+
+ protected DateFormat getDateFormat(DataType dataType, Locale locale, Column column)
+ {
+ DateFormat df;
+ if (dataType==DataType.DATE)
+ df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
+ else
+ df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
+ return df;
+ }
+
+ private String getUnitString(ValueInfo vi)
+ {
+ // Is unit supplied as a format option
+ String format = getFormatOption(vi, FORMAT_UNIT);
+ if (format!=null)
+ return format;
+ // Is it a currency column
+ Column column = vi.getColumn();
+ if (column!=null && column.getDataType()==DataType.DECIMAL)
+ {
+ String numberType = StringUtils.toString(column.getAttribute(InputControl.NUMBER_FORMAT_ATTRIBUTE));
+ if (numberType!=null)
+ {
+ if (numberType.equalsIgnoreCase("Currency"))
+ {
+ String currencyCode = StringUtils.toString(column.getAttribute(InputControl.CURRENCY_CODE_ATTRIBUTE));
+ if (currencyCode!=null)
+ { // nf = NumberFormat.getCurrencyInstance(locale);
+ Currency currency = Currency.getInstance(currencyCode);
+ return (currency!=null) ? currency.getSymbol() : null;
+ }
+ } else if (numberType.equalsIgnoreCase("Percent"))
+ {
+ return "%";
+ }
+ }
+ }
+ // No Unit supplied
+ return null;
+ }
+
+ // ------- value parsing -------
+
+ protected Object parseInteger(String s)
+ {
+ // Try to convert
+ try {
+ // Parse String
+ return Integer.parseInt(s);
+ } catch(Exception e) {
+ return error(WebErrors.InputNoIntegerFormat, null, s);
+ }
+ }
+
+ protected Object parseDecimal(String s, NumberFormat nf)
+ {
+ // Try to convert
+ try {
+ // Check for characters
+ for (int i=0; i<s.length(); i++)
+ { if (s.charAt(i)>='A')
+ return error(WebErrors.InputNoNumberFormat, null, s);
+ }
+ // Parse String
+ return nf.parseObject(s);
+ } catch(Exception e) {
+ return error(WebErrors.InputNoNumberFormat, null, s);
+ }
+ }
+
+ protected Object parseDate(String s, DateFormat df)
+ {
+ // Try to convert
+ try {
+ // Parse Date
+ df.setLenient(true);
+ return df.parseObject(s);
+ } catch(Exception e) {
+ return error(WebErrors.InputNoDateFormat, null, s);
+ }
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/package.html
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/package.html?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/package.html (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/controls/package.html Wed Aug 6 02:34:41 2008
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+/*
+ * ESTEAM Software GmbH, 12.12.2007
+ */
+-->
+</head>
+<body>
+
+
+
+</body></html>
\ No newline at end of file
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionErrorsTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionErrorsTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionErrorsTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionErrorsTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,154 @@
+/*
+ * ESTEAM Software GmbH, 21.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.commons.ErrorInfo;
+import org.apache.empire.struts2.action.ActionErrorProvider;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class ActionErrorsTag extends EmpireTagSupport
+{
+ private String actionErrorClass;
+ private String fieldErrorClass;
+
+ @Override
+ protected void resetParams()
+ {
+ actionErrorClass = null;
+ fieldErrorClass = null;
+ // Value
+ super.resetParams();
+ }
+
+ @Override
+ public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+ {
+ return null;
+ }
+
+ @Override
+ public int doStartTag()
+ throws JspException
+ {
+ // Get the action
+ Object action = getAction();
+ if (action instanceof ActionErrorProvider)
+ { // Tabel cell tag
+ HtmlWriter w = new HtmlWriter(pageContext.getOut());
+ renderAllErrors(w, (ActionErrorProvider)action);
+ }
+ else
+ { // Error: Action does implement ActionErrorProvider
+ log.error("Cannot render errors. Action does implement ActionErrorProvider.");
+ }
+ // wrap.beginBody(getTextValue());
+ // return usesBody ? EVAL_BODY_BUFFERED : EVAL_BODY_INCLUDE;
+ return SKIP_BODY;
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ { // done
+ resetParams();
+ return EVAL_PAGE;
+ }
+
+ // ------- render helpers -------
+
+ @SuppressWarnings("null")
+ private void renderAllErrors(HtmlWriter w, ActionErrorProvider provider)
+ {
+ // Get errors
+ ErrorInfo lastActionError = provider.getLastActionError(true);
+ Map<String, ErrorInfo> fieldErrors = provider.getItemErrors();
+
+ boolean hasActionError = (lastActionError!=null && lastActionError.hasError());
+ boolean hasFieldErrors = (fieldErrors!=null && fieldErrors.size()>0);
+
+ // Check wether we have an error to render
+ if (hasActionError==false && hasFieldErrors==false)
+ { // No Errors, nothing to render
+ return;
+ }
+
+ // Render error list
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlTag list = w.startTag(dic.ErrorListTag());
+ addStandardAttributes(list, dic.ErrorListClass());
+ list.beginBody();
+
+ // Are there field errors to render?
+ if (hasFieldErrors)
+ { // Render all field errors
+ Collection<ErrorInfo> errors = fieldErrors.values();
+ String fieldErrClass = str(fieldErrorClass, dic.ErrorItemEntryClass());
+ for (ErrorInfo e : errors)
+ {
+ String msg = provider.getLocalizedErrorMessage(e);
+ renderError(w, fieldErrClass, msg);
+ }
+ }
+
+ // Render last action error
+ if (hasActionError)
+ { // Render action error
+ String actionErrClass = str(actionErrorClass, dic.ErrorActionEntryClass());
+ String msg = provider.getLocalizedErrorMessage(lastActionError);
+ renderError(w, actionErrClass, msg);
+ }
+
+ // done
+ list.endTag();
+ }
+
+ private void renderError(HtmlWriter w, String cssClassName, String msg)
+ {
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlTag tag = w.startTag(dic.ErrorEntryTag());
+ // Check whether additional wrapper is desired
+ String wrapTag = dic.ErrorEntryWrapperTag();
+ if (wrapTag!=null && wrapTag.length()>0)
+ { tag.beginBody();
+ // Item wrapper tag
+ HtmlTag wrap = w.startTag(wrapTag);
+ wrap.addAttribute("class", cssClassName);
+ wrap.endTag(msg);
+ }
+ else
+ { // No additional error wrapper tag
+ tag.addAttribute("class", cssClassName);
+ tag.beginBody(msg);
+ }
+ // end
+ tag.endTag();
+ }
+
+ // ------- Property Accessors -------
+
+ public void setActionErrorClass(String actionErrorClass)
+ {
+ this.actionErrorClass = actionErrorClass;
+ }
+
+ public void setFieldErrorClass(String fieldErrorClass)
+ {
+ this.fieldErrorClass = fieldErrorClass;
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionMessageTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionMessageTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionMessageTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ActionMessageTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,72 @@
+/*
+ * ESTEAM Software GmbH, 21.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.action.ActionErrorProvider;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class ActionMessageTag extends EmpireTagSupport
+{
+ @Override
+ public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+ {
+ return null;
+ }
+
+ @Override
+ public int doStartTag()
+ throws JspException
+ {
+ // Get the action
+ Object action = getAction();
+ if (action instanceof ActionErrorProvider)
+ { // Tabel cell tag
+ HtmlWriter w = new HtmlWriter(pageContext.getOut());
+ renderMessage(w, (ActionErrorProvider)action);
+ }
+ else
+ { // Error: Action does implement ActionErrorProvider
+ log.error("Cannot render message. Action does implement ActionErrorProvider.");
+ }
+ // wrap.beginBody(getTextValue());
+ // return usesBody ? EVAL_BODY_BUFFERED : EVAL_BODY_INCLUDE;
+ return SKIP_BODY;
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ { // done
+ resetParams();
+ return EVAL_PAGE;
+ }
+
+ // ------- render helpers -------
+
+ private void renderMessage(HtmlWriter w, ActionErrorProvider provider)
+ {
+ // Get errors
+ String msg = provider.getLastActionMessage(true);
+ if (msg==null || msg.length()==0)
+ return; // Nothing to render
+
+ // Render error list
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlTag tag = w.startTag(dic.MessageTag());
+ addStandardAttributes(tag, dic.MessageClass());
+ tag.endTag(msg);
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ButtonTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ButtonTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ButtonTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ButtonTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,87 @@
+/*
+ * ESTEAM Software GmbH, 25.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+
+
+@SuppressWarnings("serial")
+public class ButtonTag extends LinkTag
+{
+ /*
+ * InputControlTag Constructor
+ */
+ /*
+ public ButtonTag()
+ {
+ }
+
+ @Override
+ protected void resetParams()
+ {
+ // Reset Params
+ super.resetParams();
+ }
+ */
+
+ @Override
+ public int doStartTag()
+ throws JspException
+ {
+ // check visibility
+ if (getBoolean(visible, true)==false)
+ { // not visible
+ return SKIP_BODY;
+ }
+ // Start Tag
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlWriter w = new HtmlWriter(pageContext.getOut());
+ HtmlTag button = w.startTag ( dic.ButtonTag() );
+ addStandardAttributes(button, dic.ButtonClass());
+ button.beginBody();
+ // Start Value
+ this.id=null;
+ this.cssClass=null;
+ this.cssStyle=null;
+ // OnClick
+ if (onclick==null && action!=null)
+ {
+ if (action.startsWith("!"))
+ onclick = dic.ButtonSameActionDefaultOnClickScript();
+ else
+ onclick = dic.ButtonOtherActionDefaultOnClickScript();
+ }
+ // Render Value
+ return super.doStartTag();
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ {
+ // check visibility
+ if (getBoolean(visible, true)==false)
+ { // Not visible
+ if (autoResetParams)
+ resetParams();
+ return EVAL_PAGE;
+ }
+ // End Tag
+ int result = super.doEndTag();
+ // Write End Tag
+ HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+ HtmlWriter w = new HtmlWriter(pageContext.getOut());
+ HtmlTag td = w.continueTag(dic.ButtonTag(), true);
+ td.endTag();
+ // done
+ return result;
+ }
+
+ // ------- Property accessors -------
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CalendarTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CalendarTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CalendarTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CalendarTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,186 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.empire.struts2.jsp.components.CalendarComponent;
+import org.apache.empire.struts2.jsp.components.info.CalendarInfo;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class CalendarTag extends EmpireTagSupport
+{
+ // Properties
+ protected CalendarInfo calendarInfo;
+ protected String selectDateAction;
+ protected String selectWeekdayAction;
+ protected String selectWeekAction;
+ protected String selectMonthAction;
+ protected String cellpadding;
+ protected String cellspacing;
+ protected String monthClass;
+ protected String dayOfWeekClass;
+ protected String weekOfYearClass;
+ protected String dateEmptyClass;
+ protected String dateValidClass;
+ protected String dateLinkClass;
+ protected String dateTodayClass;
+ protected String dateSelectedClass;
+ protected String param;
+
+ /*
+ * InputControlTag Constructor
+ */
+ public CalendarTag()
+ {
+ // Default constructor
+ }
+
+ /*
+ * Clears all params since tag is reused
+ */
+ @Override
+ protected void resetParams()
+ {
+ // FormTag
+ calendarInfo = null;
+ selectDateAction = null;
+ selectWeekdayAction = null;
+ selectWeekAction = null;
+ selectMonthAction = null;
+ cellpadding = null;
+ cellspacing = null;
+ monthClass = null;
+ weekOfYearClass = null;
+ dayOfWeekClass = null;
+ dateEmptyClass = null;
+ dateValidClass = null;
+ dateLinkClass = null;
+ dateTodayClass = null;
+ dateSelectedClass = null;
+ param = null;
+ // reset
+ super.resetParams();
+ }
+
+ @Override
+ public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+ {
+ return new CalendarComponent(stack, req, res);
+ }
+
+ @Override
+ protected void populateParams()
+ {
+ selectDateAction = checkAction(selectDateAction);
+ selectWeekdayAction = checkAction(selectWeekdayAction);
+ selectWeekAction = checkAction(selectWeekAction);
+ selectMonthAction = checkAction(selectMonthAction);
+
+ super.populateParams();
+
+ // Form Component
+ CalendarComponent comp = (CalendarComponent)component;
+ comp.setCalendarInfo(calendarInfo);
+ comp.setSelectDateAction(selectDateAction);
+ comp.setSelectMonthAction(selectMonthAction);
+ comp.setSelectWeekdayAction(selectWeekdayAction);
+ comp.setSelectWeekAction(selectWeekAction);
+ comp.setCellpadding(cellpadding);
+ comp.setCellspacing(cellspacing);
+ comp.setMonthClass(monthClass);
+ comp.setDayOfWeekClass(dayOfWeekClass);
+ comp.setWeekOfYearClass(weekOfYearClass);
+ comp.setDateEmptyClass(dateEmptyClass);
+ comp.setDateValidClass(dateValidClass);
+ comp.setDateLinkClass(dateLinkClass);
+ comp.setDateTodayClass(dateTodayClass);
+ comp.setDateSelectedClass(dateSelectedClass);
+ comp.setParamName(param);
+ }
+
+ // ------- Setters -------
+
+ public void setCalendarInfo(CalendarInfo calendarInfo)
+ {
+ this.calendarInfo = calendarInfo;
+ }
+
+ public void setParam(String param)
+ {
+ this.param = param;
+ }
+
+ public void setSelectDateAction(String selectDateAction)
+ {
+ this.selectDateAction = selectDateAction;
+ }
+
+ public void setSelectMonthAction(String selectMonthAction)
+ {
+ this.selectMonthAction = selectMonthAction;
+ }
+
+ public void setSelectWeekdayAction(String selectWeekdayAction)
+ {
+ this.selectWeekdayAction = selectWeekdayAction;
+ }
+ public void setSelectWeekAction(String selectWeekAction)
+ {
+ this.selectWeekAction = selectWeekAction;
+ }
+
+ public void setCellpadding(String cellpadding)
+ {
+ this.cellpadding = cellpadding;
+ }
+
+ public void setCellspacing(String cellspacing)
+ {
+ this.cellspacing = cellspacing;
+ }
+
+ public void setDateEmptyClass(String dateEmptyClass)
+ {
+ this.dateEmptyClass = dateEmptyClass;
+ }
+
+ public void setDateLinkClass(String dateLinkClass)
+ {
+ this.dateLinkClass = dateLinkClass;
+ }
+
+ public void setDateTodayClass(String dateTodayClass)
+ {
+ this.dateTodayClass = dateTodayClass;
+ }
+
+ public void setDateValidClass(String dateValidClass)
+ {
+ this.dateValidClass = dateValidClass;
+ }
+
+ public void setDayOfWeekClass(String dayOfWeekClass)
+ {
+ this.dayOfWeekClass = dayOfWeekClass;
+ }
+
+ public void setWeekOfYearClass(String weekOfYearClass)
+ {
+ this.weekOfYearClass = weekOfYearClass;
+ }
+
+ public void setMonthClass(String monthClass)
+ {
+ this.monthClass = monthClass;
+ }
+
+ public void setDateSelectedClass(String dateSelectedClass)
+ {
+ this.dateSelectedClass = dateSelectedClass;
+ }
+
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CheckboxTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CheckboxTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CheckboxTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/CheckboxTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,169 @@
+/*
+ * ESTEAM Software GmbH, 17.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class CheckboxTag extends EmpireValueTagSupport
+{
+ // Checkbox Tag
+ protected String name;
+ protected String hiddenName;
+ protected Object checked;
+ protected Object disabled;
+ // More UI
+ protected String tabindex;
+ protected String onclick;
+ protected String onchange;
+ protected String onfocus;
+ protected String onblur;
+
+ @Override
+ protected void resetParams()
+ {
+ name = null;
+ checked = null;
+ disabled = null;
+ // AbstractUITag
+ onclick = null;
+ onchange = null;
+ onfocus = null;
+ onblur = null;
+ tabindex = null;
+ // Value
+ super.resetParams();
+ }
+
+ @Override
+ public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+ {
+ return null;
+ }
+
+ @Override
+ public int doStartTag()
+ throws JspException
+ {
+ // Tabel cell tag
+ HtmlWriter w = new HtmlWriter(pageContext.getOut());
+ HtmlTag cb = w.startTag("input");
+ cb.addAttribute("type", "checkbox");
+ addStandardAttributes(cb, null);
+ cb.addAttribute("name", getTagName(name));
+ cb.addAttributeNoCheck("value", getStringValue(), true);
+ cb.addAttribute("checked", getChecked());
+ cb.addAttribute("disabled", getBoolean(disabled, false));
+ cb.addAttribute("tabindex", this.tabindex);
+ // Event Attributes
+ cb.addAttribute("onclick", this.onclick);
+ cb.addAttribute("onchange", this.onchange);
+ cb.addAttribute("onfocus", this.onfocus);
+ cb.addAttribute("onblur", this.onblur);
+ cb.endTag();
+ // wrap.beginBody(getTextValue());
+ if (hiddenName!=null)
+ { // Render Additional Hidden Control
+ HtmlTag hidden = w.startTag("input");
+ hidden.addAttribute("type", "hidden");
+ hidden.addAttribute("name", hiddenName);
+ hidden.addAttributeNoCheck("value", getStringValue(), true);
+ hidden.endTag();
+ }
+ // return usesBody ? EVAL_BODY_BUFFERED : EVAL_BODY_INCLUDE;
+ return SKIP_BODY;
+ }
+
+ @Override
+ public int doEndTag()
+ throws JspException
+ { // done
+ resetParams();
+ return EVAL_PAGE;
+ }
+
+ // ------- helpers -------
+
+ public boolean getChecked()
+ {
+ if (checked!=null)
+ {
+ return getBoolean(checked, false);
+ }
+ if (hasDefaultValue())
+ {
+ Object value = getValue();
+ Object defval = getDefaultValue();
+ if ((value instanceof String) && ((String)value).length()==0)
+ value = null;
+ if ((defval instanceof String) && ((String)defval).length()==0)
+ defval = null;
+ return ObjectUtils.compareEqual(value, defval);
+ }
+ // Done
+ return false;
+ }
+
+ // -------------------------------- Property accessors -----------------------------
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setDisabled(Object disabled)
+ {
+ this.disabled = disabled;
+ }
+
+ public void setHiddenName(String hiddenName)
+ {
+ this.hiddenName = hiddenName;
+ }
+
+ public void setChecked(Object checked)
+ {
+ this.checked = checked;
+ }
+
+ public void setCheck(Object check)
+ {
+ this.checked = check;
+ }
+
+ public void setTabindex(String tabindex)
+ {
+ this.tabindex = tabindex;
+ }
+
+ public void setOnclick(String onclick)
+ {
+ this.onclick = onclick;
+ }
+
+ public void setOnchange(String onchange)
+ {
+ this.onchange = onchange;
+ }
+
+ public void setOnfocus(String onfocus)
+ {
+ this.onfocus = onfocus;
+ }
+
+ public void setOnblur(String onblur)
+ {
+ this.onblur = onblur;
+ }
+}
Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/DataValueTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/DataValueTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/DataValueTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/DataValueTag.java Wed Aug 6 02:34:41 2008
@@ -0,0 +1,199 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.ColumnExpr;
+import org.apache.empire.struts2.jsp.components.DataValueComponent;
+import org.apache.empire.struts2.jsp.controls.InputControl;
+import org.apache.empire.struts2.jsp.controls.InputControlManager;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class DataValueTag extends EmpireValueTagSupport
+{
+ // Control Component
+ protected Options lookup;
+ protected String controlType;
+ protected String body; // body Usage
+ protected String format;
+ protected Object nullValue;
+ // Wrapper tag
+ protected String tag;
+ // Link attributes
+ protected String action;
+ protected Object alt;
+ protected Object item;
+ protected String param;
+ protected String anchorClass;
+ protected String onclick;
+ protected String ondblclick;
+
+ /*
+ * Clears all params since tag is reused
+ */
+ @Override
+ protected void resetParams()
+ {
+ lookup = null;
+ controlType = null;
+ body = null;
+ format = null;
+ nullValue = null;
+ // Wrapper tag
+ tag = null;
+ // Link attributes
+ action = null;
+ alt = null;
+ item = null;
+ param = null;
+ anchorClass = null;
+ onclick = null;
+ ondblclick = null;
+ // Value
+ super.resetParams();
+ }
+
+ @Override
+ public Component getBean(ValueStack stack, HttpServletRequest req,
+ HttpServletResponse res)
+ {
+ // Detect control type and readOnly state
+ if (controlType==null)
+ controlType = getControlType();
+ // Create
+ InputControl control = InputControlManager.getControl(controlType);
+ if (control==null)
+ control= InputControlManager.getControl("text");
+ // Create component
+ return new DataValueComponent(control, stack, req, res);
+ }
+
+ @Override
+ protected void populateParams()
+ {
+ // Checks action param and warns if method is not supplied
+ action = checkAction(action);
+
+ super.populateParams();
+
+ // Component
+ DataValueComponent comp = (DataValueComponent)component;
+
+ // Control Component
+ comp.setOptions( getLookupOptions() );
+ comp.setColumn (getColumn());
+ comp.setRecordValue(getValue());
+ comp.setNullValue(getObject(nullValue, null));
+ comp.setBodyUsage(body);
+ comp.setFormat(format);
+
+ // Data Value Component
+ comp.setHtmlTag(tag);
+ if (action!=null)
+ {
+ comp.setAction(action);
+ comp.setAlt(getItemValue(alt));
+ comp.setAnchorClass(anchorClass);
+ comp.setParam(str(param, getActionItemPropertyName()), getItemValue(item));
+ }
+
+ // Common UI
+ comp.setOnclick(onclick);
+ comp.setOndblclick(ondblclick);
+ comp.setCssClass(cssClass);
+ comp.setCssStyle(cssStyle);
+
+ }
+
+ private Options getLookupOptions()
+ {
+ if (lookup != null)
+ return lookup;
+ // Get List from Column
+ ColumnExpr expr = getColumnExpr();
+ if (expr!=null)
+ return expr.getOptions();
+ /*
+ ColumnExpr expr = getColumnExpr();
+ if (expr instanceof DBAliasExpr)
+ expr = ((DBAliasExpr)expr).getExpr();
+ // Check whether column expression is a Column
+ if (expr instanceof Column)
+ return ((Column)expr).getOptions();
+ */
+ return null;
+ }
+
+ // -------------------------------- Property accessors -----------------------------
+
+ public void setLookup(Options lookup)
+ {
+ this.lookup = lookup;
+ }
+
+ public void setAction(String action)
+ {
+ this.action = action;
+ }
+
+ public void setItem(Object item)
+ {
+ this.item = item;
+ }
+
+ public void setAlt(Object alt)
+ {
+ this.alt = alt;
+ }
+
+ public void setAnchorClass(String anchorClass)
+ {
+ this.anchorClass = anchorClass;
+ }
+
+ public void setBody(String body)
+ {
+ this.body = body;
+ }
+
+ public void setTag(String tag)
+ {
+ this.tag = tag;
+ }
+
+ public void setFormat(String format)
+ {
+ this.format = format;
+ }
+
+ public void setControlType(String controlType)
+ {
+ this.controlType = controlType;
+ }
+
+ public void setNullValue(Object nullValue)
+ {
+ this.nullValue = nullValue;
+ }
+
+ public void setParam(String param)
+ {
+ this.param = param;
+ }
+
+ public void setOnclick(String onclick)
+ {
+ this.onclick = onclick;
+ }
+
+ public void setOndblclick(String ondblclick)
+ {
+ this.ondblclick = ondblclick;
+ }
+
+}