Return-Path: Delivered-To: apmail-tapestry-dev-archive@www.apache.org Received: (qmail 45665 invoked from network); 27 Oct 2009 23:14:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Oct 2009 23:14:04 -0000 Received: (qmail 20942 invoked by uid 500); 27 Oct 2009 20:27:24 -0000 Delivered-To: apmail-tapestry-dev-archive@tapestry.apache.org Received: (qmail 20871 invoked by uid 500); 27 Oct 2009 20:27:24 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 20862 invoked by uid 99); 27 Oct 2009 20:27:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 20:27:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 20:27:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A79422388909; Tue, 27 Oct 2009 20:26:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r830328 - in /tapestry/tapestry5/trunk/tapestry-beanvalidator/src: main/java/org/apache/tapestry5/beanvalidator/ main/java/org/apache/tapestry5/internal/beanvalidator/ test/java/org/apache/tapestry5/beanvalidator/integration/ test/java/org/... Date: Tue, 27 Oct 2009 20:26:58 -0000 To: commits@tapestry.apache.org From: drobiazko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091027202658.A79422388909@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: drobiazko Date: Tue Oct 27 20:26:57 2009 New Revision: 830328 URL: http://svn.apache.org/viewvc?rev=830328&view=rev Log: TAP5-895: Tracking issue for Tapestry/JSR-303 integration Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java (with props) tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java (with props) tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java (with props) tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties (with props) tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/InjectValidatorDemo.tml Modified: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/beanvalidator/BeanValidatorModule.java tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/Index.tml Modified: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/beanvalidator/BeanValidatorModule.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/beanvalidator/BeanValidatorModule.java?rev=830328&r1=830327&r2=830328&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/beanvalidator/BeanValidatorModule.java (original) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/beanvalidator/BeanValidatorModule.java Tue Oct 27 20:26:57 2009 @@ -13,6 +13,9 @@ // limitations under the License. package org.apache.tapestry5.beanvalidator; +import java.util.Locale; + +import javax.validation.MessageInterpolator; import javax.validation.Validator; import javax.validation.ValidatorFactory; import javax.validation.groups.Default; @@ -20,11 +23,14 @@ import org.apache.tapestry5.internal.beanvalidator.BeanFieldValidatorDefaultSource; import org.apache.tapestry5.internal.beanvalidator.BeanValidationGroupSourceImpl; import org.apache.tapestry5.internal.beanvalidator.BeanValidatorSourceImpl; +import org.apache.tapestry5.internal.beanvalidator.MessageInterpolatorImpl; import org.apache.tapestry5.ioc.Configuration; import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.Local; import org.apache.tapestry5.ioc.services.PropertyShadowBuilder; +import org.apache.tapestry5.ioc.services.ThreadLocale; import org.apache.tapestry5.services.FieldValidatorDefaultSource; /** @@ -65,5 +71,19 @@ { configuration.add(Default.class); } + + public static void contributeBeanValidatorSource( + final OrderedConfiguration configuration, final ThreadLocale threadLocale) + { + configuration.add("LocaleAwareMessageInterpolator", new BeanValidatorConfigurer() + { + public void configure(javax.validation.Configuration configuration) + { + MessageInterpolator defaultInterpolator = configuration.getDefaultMessageInterpolator(); + + configuration.messageInterpolator(new MessageInterpolatorImpl(defaultInterpolator, threadLocale)); + } + }); + } } Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java?rev=830328&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java (added) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java Tue Oct 27 20:26:57 2009 @@ -0,0 +1,52 @@ +// Copyright 2009 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.tapestry5.internal.beanvalidator; + +import java.util.Locale; + +import javax.validation.MessageInterpolator; + +import org.apache.tapestry5.ioc.services.ThreadLocale; +/** + * The default message interpolation algorithm uses {@link Locale#getDefault()}. This behavior is not appropriate for Tapestry applications, + * thus we need a {@link Locale} aware message interpolator. + */ +public class MessageInterpolatorImpl implements MessageInterpolator +{ + private final MessageInterpolator delegate; + private final ThreadLocale threadLocale; + + public MessageInterpolatorImpl(MessageInterpolator delegate, ThreadLocale threadLocale) + { + this.delegate = delegate; + this.threadLocale = threadLocale; + } + + /** + * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context) + */ + public String interpolate(String messageTemplate, Context context) + { + return interpolate(messageTemplate, context, threadLocale.getLocale()); + } + + /** + * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context, java.util.Locale) + */ + public String interpolate(String messageTemplate, Context context, Locale locale) + { + return this.delegate.interpolate(messageTemplate, context, locale); + } + +} Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/main/java/org/apache/tapestry5/internal/beanvalidator/MessageInterpolatorImpl.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java?rev=830328&r1=830327&r2=830328&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java (original) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java Tue Oct 27 20:26:57 2009 @@ -13,10 +13,7 @@ // limitations under the License. package org.apache.tapestry5.beanvalidator.integration; -import java.util.Locale; - import org.apache.tapestry5.test.AbstractIntegrationTestSuite; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @Test(sequential = true, groups = "integration") @@ -26,13 +23,6 @@ { super("src/test/webapp"); } - - @BeforeClass - public void setDefaultLocale() - { - //Hibernate validator uses Locale.getDefault() - Locale.setDefault(Locale.ENGLISH); - } public void form_validation() throws Exception { @@ -71,4 +61,13 @@ assertTextPresent("User Name size must be between 7 and 10", "User Name must match \"[0-9]+\""); } + + public void inject_validator() throws Exception + { + start("Inject Validator Demo"); + + clickAndWait(SUBMIT); + + assertTextPresent("User Name may not be null"); + } } \ No newline at end of file Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java?rev=830328&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java (added) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java Tue Oct 27 20:26:57 2009 @@ -0,0 +1,54 @@ +// Copyright 2009 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.example.testapp.pages; + +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validator; +import javax.validation.constraints.NotNull; + +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.beaneditor.Validate; +import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.example.testapp.services.Bar; + +public class InjectValidatorDemo +{ + @NotNull(groups=Bar.class) + @Validate("minlength=5") + @Property + @Persist + private String userName; + + @Inject + private Validator validator; + + @InjectComponent + private Form form; + + void onValidateForm() + { + Set> violations = validator.validate(this, Bar.class); + + for (ConstraintViolation next : violations) + { + form.recordError("User Name "+next.getMessage()); + } + } + +} Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/InjectValidatorDemo.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java?rev=830328&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java (added) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java Tue Oct 27 20:26:57 2009 @@ -0,0 +1,18 @@ +// Copyright 2009 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.example.testapp.services; + +public interface Bar +{ +} \ No newline at end of file Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/java/org/example/testapp/services/Bar.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties?rev=830328&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties (added) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties Tue Oct 27 20:26:57 2009 @@ -0,0 +1,17 @@ +javax.validation.constraints.AssertFalse.message=must be false +javax.validation.constraints.AssertTrue.message=must be true +javax.validation.constraints.DecimalMax.message=must be less than or equal to {value} +javax.validation.constraints.DecimalMin.message=must be greater than or equal to {value} +javax.validation.constraints.Digits.message=numeric value out of bounds (<{integer} digits>.<{fraction} digits> expected) +javax.validation.constraints.Future.message=must be in the future +javax.validation.constraints.Max.message=must be less than or equal to {value} +javax.validation.constraints.Min.message=must be greater than or equal to {value} +javax.validation.constraints.NotNull.message=may not be null +javax.validation.constraints.Null.message=must be null +javax.validation.constraints.Past.message=must be in the past +javax.validation.constraints.Pattern.message=must match "{regexp}" +javax.validation.constraints.Size.message=size must be between {min} and {max} +org.hibernate.validator.constraints.Email.message="{value}" is not a valid email address +org.hibernate.validator.constraints.Length.message=length must be between {min} and {max} +org.hibernate.validator.constraints.NotEmpty.message=may not be empty +org.hibernate.validator.constraints.Range.message={value} must be between {min} and {max} \ No newline at end of file Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/resources/ValidationMessages_en.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/Index.tml URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/Index.tml?rev=830328&r1=830327&r2=830328&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/Index.tml (original) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/Index.tml Tue Oct 27 20:26:57 2009 @@ -12,6 +12,9 @@
  • BeanEditForm Validation Demo
  • +
  • + Inject Validator Demo +
  • Added: tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/InjectValidatorDemo.tml URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/InjectValidatorDemo.tml?rev=830328&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/InjectValidatorDemo.tml (added) +++ tapestry/tapestry5/trunk/tapestry-beanvalidator/src/test/webapp/InjectValidatorDemo.tml Tue Oct 27 20:26:57 2009 @@ -0,0 +1,16 @@ + + + + + +
    + + + +
    + + + +
    + + \ No newline at end of file