Locale-aware decimal number validation
Hi, I have a need for locale-aware number validation in my app (since Sweden use comma as decimal-separator instead of dot) and therefor I created my own DoubleTranslator and FloatTranslator that I contributed to the TranslatorSource from my module. Since it would have been nice to also have client validation working in a locale-aware manner I decided to take it a step further. :-D Please find attached a patch towards 5.0.19-SNAPSHOT which adds support for both client- and server-side locale-aware number-validation. I have the number of decimals fixed to two in the translators since I need to use it for monetary input. This should be nice to be able to configure per field in some way. I have placed the regexp for the client-side validation in the ValidationMessages.properties-file which might be the wrong place to have it. There is probably also a need to look at the regular expressions that are currently setup to make sure that they are correct for the various locales. Best regards, Joakim Index: tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java === --- tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java (revision 733115) +++ tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java (working copy) @@ -18,9 +18,12 @@ import org.apache.tapestry5.Link; import org.apache.tapestry5.RenderSupport; import org.apache.tapestry5.corelib.data.InsertPosition; +import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.internal.util.Defense; import org.apache.tapestry5.json.JSONArray; import org.apache.tapestry5.json.JSONObject; +import org.apache.tapestry5.services.PersistentLocale; +import org.apache.tapestry5.services.ValidationMessagesSource; public class ClientBehaviorSupportImpl implements ClientBehaviorSupport { @@ -28,9 +31,16 @@ private final JSONObject validations = new JSONObject(); -public ClientBehaviorSupportImpl(RenderSupport renderSupport) +private final ValidationMessagesSource validationMessagesSource; + +private final PersistentLocale locale; + +public ClientBehaviorSupportImpl(RenderSupport renderSupport, ValidationMessagesSource validationMessagesSource, PersistentLocale locale) { this.renderSupport = renderSupport; +this.validationMessagesSource = validationMessagesSource; +this.locale = locale; + } public void addZone(String clientId, String showFunctionName, String updateFunctionName) @@ -141,5 +151,6 @@ renderSupport.addInit(validate, parameters); } -} +Messages messages = validationMessagesSource.getValidationMessages(locale.get()); +renderSupport.addInit(localeSpecificFloatRegexp, messages.get(floatRegexp));} } Index: tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/FloatTranslator.java === --- tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/FloatTranslator.java (revision 733115) +++ tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/FloatTranslator.java (working copy) @@ -14,29 +14,40 @@ package org.apache.tapestry5.internal.translator; +import java.text.NumberFormat; +import java.text.ParseException; + import org.apache.tapestry5.Field; import org.apache.tapestry5.ValidationException; +import org.apache.tapestry5.services.PersistentLocale; public class FloatTranslator extends DecimalNumberTranslatorFloat { -public FloatTranslator() +private final PersistentLocale locale; + +public FloatTranslator(PersistentLocale locale) { super(float, Float.class); +this.locale = locale; } public String toClient(Float value) { -return value.toString(); +NumberFormat formatter = NumberFormat.getNumberInstance(this.locale.get()); +formatter.setMinimumFractionDigits(2); +formatter.setMaximumFractionDigits(2); +return formatter.format(value); } -public Float parseClient(Field field, String clientValue, String message) -throws ValidationException +public Float parseClient(Field field, String clientValue, String message) throws ValidationException { +NumberFormat formatter = NumberFormat.getNumberInstance(this.locale.get()); + try { -return new Float(clientValue.trim()); +return formatter.parse(clientValue.trim()).floatValue(); } -catch (NumberFormatException ex) +catch (ParseException ex) { throw new ValidationException(message); } Index: tapestry-core/src/main/java/org/apache/tapestry5/internal/translator/DoubleTranslator.java === ---
t5: when running tomcat behind Apache
Hi, When running Tomcat behind a Apache Http server using proxy/reverseproxy, following code returns 127.0.0.1 always, any solution to this? Thanks. @Inject private RequestGlobals requestGlobals; void setupRender() { String remoteIP = requestGlobals.getHTTPServletRequest().getRemoteAddr(); } -- View this message in context: http://www.nabble.com/t5%3A-when-running-tomcat-behind-Apache-tp21398829p21398829.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Locale-aware decimal number validation
Joakim, there has been quite some discussion on this already and there also exists a JIRA issue for this. Maybe you want to contribute there: https://issues.apache.org/jira/browse/TAP5-211 Please also sign up for JIRA and vote for it. Cheers, Uli Joakim Olsson schrieb: Hi, I have a need for locale-aware number validation in my app (since Sweden use comma as decimal-separator instead of dot) and therefor I created my own DoubleTranslator and FloatTranslator that I contributed to the TranslatorSource from my module. Since it would have been nice to also have client validation working in a locale-aware manner I decided to take it a step further. :-D Please find attached a patch towards 5.0.19-SNAPSHOT which adds support for both client- and server-side locale-aware number-validation. I have the number of decimals fixed to two in the translators since I need to use it for monetary input. This should be nice to be able to configure per field in some way. I have placed the regexp for the client-side validation in the ValidationMessages.properties-file which might be the wrong place to have it. There is probably also a need to look at the regular expressions that are currently setup to make sure that they are correct for the various locales. Best regards, Joakim - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Scala - Tapestry 5 : inject services, access properties
I updated my blog about T5 with a Scala back-end. This article shows a first service and how to access bean properties. The article is here: http://fanf42.blogspot.com/2009/01/t5-scala-first-injection-and-property.html And the code is available on Github: http://github.com/fanf/scala-t5-blog/tree/article2_20090111 Enjoy, Francois Armand - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Locale-aware decimal number validation
Aaah...Great. Didn't even consider searching the JIRA before diving into the tapestry-code. :-D I attached my patch to the JIRA as well. Regards, Joakim On Sun, 2009-01-11 at 14:36 +0100, Ulrich Stärk wrote: Joakim, there has been quite some discussion on this already and there also exists a JIRA issue for this. Maybe you want to contribute there: https://issues.apache.org/jira/browse/TAP5-211 Please also sign up for JIRA and vote for it. Cheers, Uli Joakim Olsson schrieb: Hi, I have a need for locale-aware number validation in my app (since Sweden use comma as decimal-separator instead of dot) and therefor I created my own DoubleTranslator and FloatTranslator that I contributed to the TranslatorSource from my module. Since it would have been nice to also have client validation working in a locale-aware manner I decided to take it a step further. :-D Please find attached a patch towards 5.0.19-SNAPSHOT which adds support for both client- and server-side locale-aware number-validation. I have the number of decimals fixed to two in the translators since I need to use it for monetary input. This should be nice to be able to configure per field in some way. I have placed the regexp for the client-side validation in the ValidationMessages.properties-file which might be the wrong place to have it. There is probably also a need to look at the regular expressions that are currently setup to make sure that they are correct for the various locales. Best regards, Joakim - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: when running tomcat behind Apache
Hi Angelo, I think you need to take a look at the X-Forwarded-For header. Please see: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers -- Kevin On Sun, Jan 11, 2009 at 7:53 AM, Angelo Chen angelochen...@yahoo.com.hk wrote: Hi, When running Tomcat behind a Apache Http server using proxy/reverseproxy, following code returns 127.0.0.1 always, any solution to this? Thanks. @Inject private RequestGlobals requestGlobals; void setupRender() { String remoteIP = requestGlobals.getHTTPServletRequest().getRemoteAddr(); } -- View this message in context: http://www.nabble.com/t5%3A-when-running-tomcat-behind-Apache-tp21398829p21398829.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Connection Problem
Hi, there was a post before in this forum that solves this problem for me, but I can't remember the link, basically, here are the things I added and it's running with any problem: !-- pool via c3p0 which knows how to reconnect to server and does it nicely-- property name=connection.provider_classorg.hibernate.connection.C3P0ConnectionProvider/property property name=hibernate.c3p0.acquire_increment3/property property name=hibernate.c3p0.idle_test_period100/property !-- seconds -- property name=hibernate.c3p0.max_size20/property property name=hibernate.c3p0.max_statements0/property property name=hibernate.c3p0.min_size1/property property name=hibernate.c3p0.timeout1000/property I put this in hibernate.cfg.xml, that's the only file I have for tapestry-hibernate. Angelo abangkis wrote: Hello, I have an application that deployed with this kind of architecture : Apache httpd server - Glassfishv2 - Tapestry - Tapestry-Hibernate - Mysql. And every 8 Hour or So, i've got a broken pipe error message. I've tried following this guide http://www.codefin.net/2007/05/hibernate-and-mysql-connection-timeouts.html, but it didn't seems to work. Any other idea what kind of configuration i should tweak in order for this not to happened ? the software versions are : Apache 2.2.8 Sun Java System Application Server 9.1 (build b58g-fcs) Tapestry 5.0.15 Mysql 5.0.51a-3ubuntu5.4 Cheers , Abangkis - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- View this message in context: http://www.nabble.com/Connection-Problem-tp21393799p21407688.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
RE: Connection Problem
I configure connection pooling on my app server, so I have no hands-on experience with c3p0. Certainly it looks like this would work well. If it doesn't, then one more paranoid thing Abangkis can do is add hibernate.c3p0.validate=true to force checking of every connection on checkout from the pool. -Original Message- From: Angelo Chen [mailto:angelochen...@yahoo.com.hk] Sent: Sunday, January 11, 2009 22:10 To: users@tapestry.apache.org Subject: Re: Connection Problem Hi, there was a post before in this forum that solves this problem for me, but I can't remember the link, basically, here are the things I added and it's running with any problem: !-- pool via c3p0 which knows how to reconnect to server and does it nicely-- property name=connection.provider_classorg.hibernate.connection.C3P0ConnectionPr ovider/property property name=hibernate.c3p0.acquire_increment3/property property name=hibernate.c3p0.idle_test_period100/property !-- seconds -- property name=hibernate.c3p0.max_size20/property property name=hibernate.c3p0.max_statements0/property property name=hibernate.c3p0.min_size1/property property name=hibernate.c3p0.timeout1000/property I put this in hibernate.cfg.xml, that's the only file I have for tapestry-hibernate. Angelo abangkis wrote: Hello, I have an application that deployed with this kind of architecture : Apache httpd server - Glassfishv2 - Tapestry - Tapestry-Hibernate - Mysql. And every 8 Hour or So, i've got a broken pipe error message. I've tried following this guide http://www.codefin.net/2007/05/hibernate-and-mysql-connection- timeouts.html, but it didn't seems to work. Any other idea what kind of configuration i should tweak in order for this not to happened ? the software versions are : Apache 2.2.8 Sun Java System Application Server 9.1 (build b58g-fcs) Tapestry 5.0.15 Mysql 5.0.51a-3ubuntu5.4 Cheers , Abangkis - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- View this message in context: http://www.nabble.com/Connection-Problem- tp21393799p21407688.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: t5: when running tomcat behind Apache
Should Tapestry assume it is running behind Apache and correctly operate on those special headers? On Sun, Jan 11, 2009 at 2:57 PM, Kevin Menard nirvd...@gmail.com wrote: Hi Angelo, I think you need to take a look at the X-Forwarded-For header. Please see: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers -- Kevin On Sun, Jan 11, 2009 at 7:53 AM, Angelo Chen angelochen...@yahoo.com.hk wrote: Hi, When running Tomcat behind a Apache Http server using proxy/reverseproxy, following code returns 127.0.0.1 always, any solution to this? Thanks. @Inject private RequestGlobals requestGlobals; void setupRender() { String remoteIP = requestGlobals.getHTTPServletRequest().getRemoteAddr(); } -- View this message in context: http://www.nabble.com/t5%3A-when-running-tomcat-behind-Apache-tp21398829p21398829.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org