You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2009/04/06 16:04:32 UTC
svn commit: r762346 - in
/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl: ./
src/main/java/org/apache/myfaces/trinidadinternal/facelets/
Author: matzew
Date: Mon Apr 6 14:04:32 2009
New Revision: 762346
URL: http://svn.apache.org/viewvc?rev=762346&view=rev
Log:
TRINIDAD-1441 - Facelets: Need Custom Validator and Converter handlers
applied components related change. Thx to Max Starets
Added:
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadConverterHandler.java
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadValidatorHandler.java
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/ValueExpressionTagRule.java
Modified:
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/pom.xml
myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadComponentHandler.java
Modified: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/pom.xml?rev=762346&r1=762345&r2=762346&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/pom.xml (original)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/pom.xml Mon Apr 6 14:04:32 2009
@@ -200,6 +200,8 @@
<trh>http://myfaces.apache.org/trinidad/html</trh>
</taglibs>
<faceletHandlerClass>org.apache.myfaces.trinidadinternal.facelets.TrinidadComponentHandler</faceletHandlerClass>
+ <faceletConverterHandlerClass>org.apache.myfaces.trinidadinternal.facelets.TrinidadConverterHandler</faceletConverterHandlerClass>
+ <faceletValidatorHandlerClass>org.apache.myfaces.trinidadinternal.facelets.TrinidadValidatorHandler</faceletValidatorHandlerClass>
<typePrefix>org.apache</typePrefix>
<renderKitPrefix>org.apache</renderKitPrefix>
<packageContains>org.apache</packageContains>
Added: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java?rev=762346&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java (added)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java Mon Apr 6 14:04:32 2009
@@ -0,0 +1,154 @@
+/*
+ * 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.myfaces.trinidadinternal.facelets;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+import com.sun.facelets.tag.TagAttributeException;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import java.text.DateFormat;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+class DatePropertyTagRule
+ extends MetaRule
+{
+ static DatePropertyTagRule Instance = new DatePropertyTagRule();
+
+ private static class LiteralPropertyMetadata extends Metadata
+ {
+ public LiteralPropertyMetadata(Method method, TagAttribute attribute,
+ boolean adjustToEnd)
+ {
+ _method = method;
+ _attribute = attribute;
+ _adjustToEnd = adjustToEnd;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ if (_params == null)
+ {
+ Date date = _coerceToDate(_attribute.getValue(), _adjustToEnd);
+ _params = new Object[]{date};
+ }
+ try
+ {
+ _method.invoke(instance, _params);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new TagAttributeException(_attribute, e.getCause());
+ }
+ catch (Exception e)
+ {
+ throw new TagAttributeException(_attribute, e);
+ }
+ }
+
+ private final Method _method;
+ private final TagAttribute _attribute;
+ private final boolean _adjustToEnd;
+ private Object[] _params;
+ }
+
+ public Metadata applyRule(String name, TagAttribute attribute,
+ MetadataTarget meta)
+ {
+ if (meta.getPropertyType(name) == _DATE_TYPE && attribute.isLiteral())
+ {
+ Method m = meta.getWriteMethod(name);
+
+ // if the property is writable
+ if (m != null)
+ {
+ return new LiteralPropertyMetadata(m, attribute, _MAX_VALUE.equals(name));
+ }
+ }
+
+ return null;
+ }
+
+ static private Date _coerceToDate(String str, boolean adjustToEnd)
+ {
+ if (str == null)
+ return null;
+
+ try
+ {
+ Date date = _getDateFormat().parse(str);
+
+ // This code is taken from UIXComponentELTag
+ // We should probably not do the ajustment here,
+ // but instead be smarter when days are compared.
+ if (adjustToEnd)
+ {
+ Calendar c = Calendar.getInstance();
+ TimeZone tz = RequestContext.getCurrentInstance().getTimeZone();
+ if (tz != null)
+ c.setTimeZone(tz);
+ c.setTime(date);
+ // Original value had 00:00:00 for hours,mins, seconds now maximize those
+ // to get the latest time value for the date supplied.
+ c.set (Calendar.HOUR_OF_DAY, 23);
+ c.set (Calendar.MINUTE, 59);
+ c.set (Calendar.SECOND, 59);
+ c.set (Calendar.MILLISECOND, 999);
+ }
+
+ return date;
+ }
+ catch (ParseException pe)
+ {
+ _LOG.info("CANNOT_PARSE_VALUE_INTO_DATE", str);
+ return null;
+ }
+ }
+
+ // We rely strictly on ISO 8601 formats
+ private static DateFormat _getDateFormat()
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ TimeZone tz = RequestContext.getCurrentInstance().getTimeZone();
+ if (tz != null)
+ sdf.setTimeZone(tz);
+ return sdf;
+ }
+
+ static private final Class<? extends Date> _DATE_TYPE = Date.class;
+ static private final String _MAX_VALUE = "maxValue";
+
+ static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(DatePropertyTagRule.class);
+}
Modified: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadComponentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadComponentHandler.java?rev=762346&r1=762345&r2=762346&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadComponentHandler.java (original)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadComponentHandler.java Mon Apr 6 14:04:32 2009
@@ -68,6 +68,7 @@
m.addRule(StringArrayPropertyTagRule.Instance);
m.addRule(TrinidadListenersTagRule.Instance);
m.addRule(AccessKeyPropertyTagRule.Instance);
+ m.addRule(DatePropertyTagRule.Instance);
return m;
}
Added: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadConverterHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadConverterHandler.java?rev=762346&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadConverterHandler.java (added)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadConverterHandler.java Mon Apr 6 14:04:32 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.myfaces.trinidadinternal.facelets;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ConvertHandler;
+import com.sun.facelets.tag.jsf.ConverterConfig;
+
+public class TrinidadConverterHandler
+ extends ConvertHandler
+{
+ public TrinidadConverterHandler(ConverterConfig config)
+ {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type)
+ {
+ MetaRuleset m = super.createMetaRuleset(type);
+ m.addRule(StringArrayPropertyTagRule.Instance);
+ m.addRule(ValueExpressionTagRule.Instance);
+ return m;
+ }
+}
Added: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadValidatorHandler.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadValidatorHandler.java?rev=762346&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadValidatorHandler.java (added)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/TrinidadValidatorHandler.java Mon Apr 6 14:04:32 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.myfaces.trinidadinternal.facelets;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ValidateHandler;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+public class TrinidadValidatorHandler
+ extends ValidateHandler
+{
+ public TrinidadValidatorHandler(ValidatorConfig config)
+ {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type)
+ {
+ MetaRuleset m = super.createMetaRuleset(type);
+ m.addRule(StringArrayPropertyTagRule.Instance);
+ m.addRule(ValueExpressionTagRule.Instance);
+ m.addRule(DatePropertyTagRule.Instance);
+ return m;
+ }
+}
Added: myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/ValueExpressionTagRule.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/ValueExpressionTagRule.java?rev=762346&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/ValueExpressionTagRule.java (added)
+++ myfaces/trinidad/branches/1.2.11.2-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/ValueExpressionTagRule.java Mon Apr 6 14:04:32 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.myfaces.trinidadinternal.facelets;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.el.ValueExpression;
+
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+class ValueExpressionTagRule extends MetaRule
+{
+
+ static ValueExpressionTagRule Instance = new ValueExpressionTagRule();
+
+ public Metadata applyRule(String name, TagAttribute attribute,
+ MetadataTarget meta)
+ {
+ // This rule should be used only for objects implementing setValueExpression().
+
+ if (!attribute.isLiteral())
+ {
+ Class type = meta.getPropertyType(name);
+ if (type == null) {
+ type = Object.class;
+ }
+ return new ValueExpressionMetadata(name, type, attribute);
+ }
+
+ return null;
+ }
+
+ private final static class ValueExpressionMetadata extends Metadata
+ {
+ private final String _name;
+ private final TagAttribute _attr;
+ private final Class _type;
+
+ public ValueExpressionMetadata(String name, Class type, TagAttribute attr)
+ {
+ _name = name;
+ _attr = attr;
+ _type = type;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ Class klass = instance.getClass();
+ try
+ {
+ Method setter = klass.getMethod("setValueExpression", _SETTER_ARGS);
+ setter.invoke(instance, new Object[]{_name, _attr.getValueExpression(ctx, _type)});
+ }
+ // No user-readable messages are needed since we should never install this rule
+ // for objects not supportingg setvalueExpression()
+ catch (NoSuchMethodException ncm)
+ {
+ _LOG.severe(ncm);
+ }
+ catch(IllegalAccessException iae)
+ {
+ _LOG.severe(iae);
+ }
+ catch(InvocationTargetException ite)
+ {
+ _LOG.severe(ite);
+ }
+ }
+
+ private static final Class _SETTER_ARGS[] = {String.class, ValueExpression.class};
+ }
+
+ private static final TrinidadLogger _LOG =
+ TrinidadLogger.createTrinidadLogger(ValueExpressionTagRule.class);
+}