You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2005/12/14 22:53:29 UTC
svn commit: r356888 - in /incubator/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/ toba...
Author: bommel
Date: Wed Dec 14 13:52:59 2005
New Revision: 356888
URL: http://svn.apache.org/viewcvs?rev=356888&view=rev
Log:
added validator support for inputText components MYFACES-935
try fix MYFACES-946
Added:
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasValidator.java
Modified:
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InTagDeclaration.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTag.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTagDeclaration.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasActionListener.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/InExtensionTag.java
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/TextAreaExtensionTag.java
incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.jsp
incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java Wed Dec 14 13:52:59 2005
@@ -613,8 +613,10 @@
}
public static UIComponent createLabeledInputLayoutComponent() {
- return createComponent(UILabeledInputLayout.COMPONENT_TYPE,
+ UIComponent component = createComponent(UILabeledInputLayout.COMPONENT_TYPE,
RENDERER_TYPE_LABELED_INPUT_LAYOUT);
+ component.setId(FacesContext.getCurrentInstance().getViewRoot().createUniqueId());
+ return component;
}
public static UIComponent createComponent(String componentType, String rendererType) {
@@ -802,6 +804,17 @@
}
}
return items;
+ }
+ public static void setValidator(UIComponent component, String validator) {
+ EditableValueHolder editableValueHolder = (EditableValueHolder) component;
+ if (validator != null && editableValueHolder.getValidator() == null) {
+ if (UIComponentTag.isValueReference(validator)) {
+ Class arguments[] = { FacesContext.class, UIComponent.class, Object.class };
+ MethodBinding methodBinding =
+ FacesContext.getCurrentInstance().getApplication().createMethodBinding(validator,arguments);
+ ((EditableValueHolder)component).setValidator(methodBinding);
+ }
+ }
}
public static void setConverter(UIComponent component, String converter) {
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InTagDeclaration.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InTagDeclaration.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InTagDeclaration.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InTagDeclaration.java Wed Dec 14 13:52:59 2005
@@ -17,7 +17,6 @@
import org.apache.myfaces.tobago.apt.annotation.BodyContentDescription;
import org.apache.myfaces.tobago.apt.annotation.Tag;
-import org.apache.myfaces.tobago.taglib.component.TextInputTagDeclaration;
import org.apache.myfaces.tobago.taglib.decl.*;
/*
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTag.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTag.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTag.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTag.java Wed Dec 14 13:52:59 2005
@@ -31,6 +31,7 @@
private String accessKey;
private String labelWithAccessKey;
private String tip;
+ private String validator;
public void release() {
@@ -40,6 +41,7 @@
accessKey = null;
labelWithAccessKey = null;
tip = null;
+ validator = null;
}
protected void setProperties(UIComponent component) {
@@ -49,6 +51,7 @@
ComponentUtil.setStringProperty(component, ATTR_ACCESS_KEY, accessKey);
ComponentUtil.setStringProperty(component, ATTR_LABEL_WITH_ACCESS_KEY, labelWithAccessKey);
ComponentUtil.setStringProperty(component, ATTR_TIP, tip);
+ ComponentUtil.setValidator(component, validator);
}
public String getOnchange() {
@@ -89,6 +92,14 @@
public void setTip(String tip) {
this.tip = tip;
+ }
+
+ public String getValidator() {
+ return validator;
+ }
+
+ public void setValidator(String validator) {
+ this.validator = validator;
}
}
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTagDeclaration.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTagDeclaration.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTagDeclaration.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/component/InputTagDeclaration.java Wed Dec 14 13:52:59 2005
@@ -15,11 +15,13 @@
*/
package org.apache.myfaces.tobago.taglib.component;
+import org.apache.myfaces.tobago.taglib.decl.HasValidator;
+
/**
* Created: Aug 5, 2005 4:18:38 PM
* User: bommel
* $Id: $
*/
-public interface InputTagDeclaration extends BeanTagDeclaration {
+public interface InputTagDeclaration extends BeanTagDeclaration, HasValidator {
}
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasActionListener.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasActionListener.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasActionListener.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasActionListener.java Wed Dec 14 13:52:59 2005
@@ -17,6 +17,7 @@
import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
/**
* $Id$
@@ -30,6 +31,6 @@
* parameter, with a return type of void.
*
*/
- @TagAttribute @UIComponentTagAttribute()
+ @TagAttribute @UIComponentTagAttribute(expression=DynamicExpression.METHOD_BINDING)
void setActionListener(String actionListener);
}
Added: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasValidator.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasValidator.java?rev=356888&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasValidator.java (added)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasValidator.java Wed Dec 14 13:52:59 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2002-2005 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.myfaces.tobago.taglib.decl;
+
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: 13.12.2005
+ * Time: 20:10:50
+ */
+
+/**
+ *
+ */
+public interface HasValidator {
+ /**
+ * A method binding EL expression,
+ * accepting FacesContext, UIComponent,
+ * and Object parameters, and returning void, that validates
+ * the component's local value.
+ */
+ @TagAttribute
+ @UIComponentTagAttribute(type="javax.faces.el.MethodBinding",
+ expression = DynamicExpression.METHOD_BINDING)
+ public void setValidator(String validator) ;
+}
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/InExtensionTag.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/InExtensionTag.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/InExtensionTag.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/InExtensionTag.java Wed Dec 14 13:52:59 2005
@@ -27,17 +27,19 @@
import org.apache.myfaces.tobago.taglib.decl.IsPassword;
import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
import org.apache.myfaces.tobago.taglib.decl.IsRequired;
+import org.apache.myfaces.tobago.taglib.decl.HasValidator;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
@Tag(name="in")
public class InExtensionTag extends BodyTagSupport
- implements HasValue, HasIdBindingAndRendered,
+ implements HasValue, HasValidator, HasIdBindingAndRendered,
HasConverter, IsReadonly, IsDisabled,
IsRequired, HasTip, HasLabel, IsPassword, IsFocus {
private String binding;
private String converter;
+ private String validator;
private String disabled;
private String focus;
private String label;
@@ -79,6 +81,9 @@
if (converter != null) {
inTag.setConverter(converter);
}
+ if (validator != null) {
+ inTag.setValidator(validator);
+ }
if (disabled != null) {
inTag.setDisabled(disabled);
}
@@ -115,6 +120,7 @@
super.release();
binding = null;
converter = null;
+ validator = null;
disabled = null;
focus = null;
label = null;
@@ -150,6 +156,9 @@
this.converter = converter;
}
+ public void setValidator(String validator) {
+ this.validator = validator;
+ }
public void setPassword(String password) {
this.password = password;
}
Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/TextAreaExtensionTag.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/TextAreaExtensionTag.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/TextAreaExtensionTag.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/taglib/extension/TextAreaExtensionTag.java Wed Dec 14 13:52:59 2005
@@ -16,6 +16,9 @@
package org.apache.myfaces.tobago.taglib.extension;
import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
import org.apache.myfaces.tobago.taglib.component.TextAreaTag;
import org.apache.myfaces.tobago.taglib.decl.HasConverter;
import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
@@ -26,13 +29,14 @@
import org.apache.myfaces.tobago.taglib.decl.IsFocus;
import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
import org.apache.myfaces.tobago.taglib.decl.IsRequired;
+import org.apache.myfaces.tobago.taglib.decl.HasValidator;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
@Tag(name="textarea")
public class TextAreaExtensionTag extends BodyTagSupport
implements HasValue, HasIdBindingAndRendered,
- HasConverter, IsReadonly, IsDisabled,
+ HasConverter, HasValidator, IsReadonly, IsDisabled,
IsRequired, HasTip, HasLabel, IsFocus {
private String binding;
@@ -45,6 +49,7 @@
private String required;
private String tip;
private String value;
+ private String validator;
private LabelExtensionTag labelTag;
private TextAreaTag textAreaTag;
@@ -77,6 +82,9 @@
if (converter != null) {
textAreaTag.setConverter(converter);
}
+ if (validator != null) {
+ textAreaTag.setValidator(validator);
+ }
if (disabled != null) {
textAreaTag.setDisabled(disabled);
}
@@ -110,6 +118,7 @@
super.release();
binding = null;
converter = null;
+ validator = null;
disabled = null;
focus = null;
label = null;
@@ -142,6 +151,10 @@
public void setConverter(String converter) {
this.converter = converter;
+ }
+
+ public void setValidator(String validator) {
+ this.validator = validator;
}
public void setReadonly(String readonly) {
Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/TobagoDemoController.java Wed Dec 14 13:52:59 2005
@@ -32,8 +32,11 @@
import org.apache.myfaces.tobago.event.SheetStateChangeEvent;
import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
+import javax.faces.validator.ValidatorException;
+import javax.faces.application.FacesMessage;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import java.util.ArrayList;
@@ -453,6 +456,16 @@
public void stateChangeListener(SheetStateChangeEvent e) {
LOG.error("SheetState has Changed: " + e);
+ }
+
+ public void customValidator(FacesContext context, UIComponent component, Object value) throws ValidatorException {
+ if (value == null) {
+ return;
+ }
+ if (!"Tobago".equals(value)) {
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please type in 'Tobago'",
+ "Please type in 'Tobago'"));
+ }
}
public SelectItem[] getToolbarIconItems() {
Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.jsp
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.jsp?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.jsp (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.jsp Wed Dec 14 13:52:59 2005
@@ -44,6 +44,8 @@
<tx:in label="#{overviewBundle.validation_price}">
<f:validateDoubleRange minimum="0.01" maximum="1000" />
</tx:in>
+ <tx:in label="#{overviewBundle.validation_custom}" validator="#{demo.customValidator}" >
+ </tx:in>
</tc:panel>
<tx:textarea label="#{overviewBundle.validation_description}"
Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml?rev=356888&r1=356887&r2=356888&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml Wed Dec 14 13:52:59 2005
@@ -193,6 +193,7 @@
<entry key="validation_description">Description</entry>
<entry key="validation_number">Number</entry>
<entry key="validation_price">Price</entry>
+<entry key="validation_custom">Custom Validator</entry>
<entry key="validation_submit">Submit</entry>
<entry key="validation_text">Tobago provides easy to use possibilities for validation of user input.