JSON Response from DirectLink Help
Hi All, Probably a simple answer to this but I'm lost; how do I get a JSON response from a link? And once I've got a response how does it get procesed; ie: User clicks a link, ajax call is made, a JSON object is created and returned, a method then fires to process the recieved JSON object. Ive had a look at the Autocompleter and its just confused me. I've got this far: public void jsonTest(IRequestCycle c){ // err now what? // c.getResponseBuilder().getWriter() returns NullWriter } providing a json object gets back to the browser how does the response get handled? Many thanks, Adam. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tap 4.1 Shell component Exceptions
Sorry, I'm a little lost, how can I deploy the Timetracker app? I tried: mvn deploy .. INFO] [site:attach-descriptor] [INFO] [install:install] [INFO] Installing /workspace/tapestry/pom.xml to /.m2/repository/org/ apache/tapestry/tapestry-project/4.1.0-SNAPSHOT/tapestry- project-4.1.0-SNAPSHOT.pom [INFO] [deploy:deploy] [INFO] Retrieving previous build number from tapestry-snapshot-repo The authenticity of host 'apache.org' can't be established. DSA key fingerprint is 79:7c:cb:6a:44:47:b2:ef:5c:66:28:d7:40:0d:b1:f9. Are you sure you want to continue connecting? (yes/no): yes Password:: (Sorry, I'm totally new to the Maven thing) On 15 Jul 2006, at 00:39, Jesse Kuhnert wrote: Ok, for sanity's sake, what happens when you deploy/run the TimeTracker example application? (Can be run via maven as well ) On 7/14/06, Adam Henderson Azudio <[EMAIL PROTECTED]> wrote: I've downloaded the 4.1.0 Jul 14 snapshot jars from http:// people.apache.org/maven-snapshot-repository and stuck them in my app and re-deployed/run it and it still gives the same exceptions: WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry/html.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry/html.js' does not exist. at org.apache.tapestry.asset.AssetService.service( AssetService.java: 241) at $IEngineService_10c6f5c05ef.service ($IEngineService_10c6f5c05ef.java) blah... and WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/__package__.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/__package__.js' does not exist. WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry.js' does not exist. jars tapestry-annotations-4.1.0-20060714.230652-14.jar tapestry-contrib-4.1.0-20060714.230652-15.jar tapestry-portlet-4.1.0-20060714.230652-14.jar tapestry-framework-4.1.0-20060714.230652-15.jar On 14 Jul 2006, at 23:49, Jesse Kuhnert wrote: > Hmmm...Sounds questionable. That particular exception is expected and > doesn't actually cause a failure (hence the Tests run: 8, Failures: 0, > Errors: 0, Skipped: 0, Time elapsed: 0.105 output). > > The same exact jars are kept up to date on the maven snapshot repo, > if you > can get it to blow up there I would be able to ensure I have a > baseline to > measure against. > > On 7/14/06, Adam Henderson Azudio <[EMAIL PROTECTED]> wrote: >> >> I downloaded maven from apache (Maven 2.0.4), downloaded the Tapestry >> source from svn & ran the package command: >> >> mvn package >> >> which did its stuff but failed during the mock tests, so I re ran >> skipping the tests: >> >> One of the tests threw this: >> >> Running org.apache.tapestry.web.TestServletWebContext >> ServletWebContext [ERROR] Error getting context resource '/ tapestry': >> Like this ever happens. >> java.net.MalformedURLException: Like this ever happens. >> at org.easymock.internal.MockInvocationHandler.invoke >> (MockInvocationHandler.java:31) >> at org.easymock.internal.ObjectMethodsFilter.invoke >> (ObjectMethodsFilter.java:45) >> at $Proxy72.getResource(Unknown Source) >> at org.apache.tapestry.web.ServletWebContext.getResource >> (ServletWebContext.java:78) >> at >> org.apache.tapestry.web.TestServletWebContext.testGetResourceFailure >> (TestServletWebContext.java:170) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >> Method) >> at sun.reflect.NativeMethodAccessorImpl.invoke >> (NativeMethodAccessorImpl.java:39) >> at sun.reflect.DelegatingMethodAccessorImpl.invoke >> (DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:585) >> at org.testng.internal.MethodHelper.invokeMethod >> (MethodHelper.java:552) >> at org.testng.internal.Invoker.invokeMethod(Invoker.java: >> 407) >> at org.testng.internal.Invoker.invokeTestMethods >> (Invoker.java:778) >> at org.testng.internal.TestMethodWorker.run >> (TestMethodWorker.java:105) >> at org.testng.TestRunner.privateRun(TestRunner.java:682) >> at org.testng.TestRunner.run(TestRunner.java:566) >> at org.testng.SuiteRunner.privateRun(SuiteRunner.java: 220) >> at org.testng.SuiteRunner.run(SuiteRunner.java:146) >>
Re: Tap 4.1 Shell component Exceptions
I've downloaded the 4.1.0 Jul 14 snapshot jars from http:// people.apache.org/maven-snapshot-repository and stuck them in my app and re-deployed/run it and it still gives the same exceptions: WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry/html.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry/html.js' does not exist. at org.apache.tapestry.asset.AssetService.service(AssetService.java: 241) at $IEngineService_10c6f5c05ef.service ($IEngineService_10c6f5c05ef.java) blah... and WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/__package__.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/__package__.js' does not exist. WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry.js' does not exist. jars tapestry-annotations-4.1.0-20060714.230652-14.jar tapestry-contrib-4.1.0-20060714.230652-15.jar tapestry-portlet-4.1.0-20060714.230652-14.jar tapestry-framework-4.1.0-20060714.230652-15.jar On 14 Jul 2006, at 23:49, Jesse Kuhnert wrote: Hmmm...Sounds questionable. That particular exception is expected and doesn't actually cause a failure (hence the Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.105 output). The same exact jars are kept up to date on the maven snapshot repo, if you can get it to blow up there I would be able to ensure I have a baseline to measure against. On 7/14/06, Adam Henderson Azudio <[EMAIL PROTECTED]> wrote: I downloaded maven from apache (Maven 2.0.4), downloaded the Tapestry source from svn & ran the package command: mvn package which did its stuff but failed during the mock tests, so I re ran skipping the tests: One of the tests threw this: Running org.apache.tapestry.web.TestServletWebContext ServletWebContext [ERROR] Error getting context resource '/tapestry': Like this ever happens. java.net.MalformedURLException: Like this ever happens. at org.easymock.internal.MockInvocationHandler.invoke (MockInvocationHandler.java:31) at org.easymock.internal.ObjectMethodsFilter.invoke (ObjectMethodsFilter.java:45) at $Proxy72.getResource(Unknown Source) at org.apache.tapestry.web.ServletWebContext.getResource (ServletWebContext.java:78) at org.apache.tapestry.web.TestServletWebContext.testGetResourceFailure (TestServletWebContext.java:170) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.testng.internal.MethodHelper.invokeMethod (MethodHelper.java:552) at org.testng.internal.Invoker.invokeMethod(Invoker.java: 407) at org.testng.internal.Invoker.invokeTestMethods (Invoker.java:778) at org.testng.internal.TestMethodWorker.run (TestMethodWorker.java:105) at org.testng.TestRunner.privateRun(TestRunner.java:682) at org.testng.TestRunner.run(TestRunner.java:566) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:220) at org.testng.SuiteRunner.run(SuiteRunner.java:146) at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java: 713) at org.testng.TestNG.runSuitesLocally(TestNG.java:676) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeTest NG( TestNGDirectoryTestSuite.java:195) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:145) at org.apache.maven.surefire.Surefire.run(Surefire.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess (SurefireBooter.java:261) at org.apache.maven.surefire.booter.SurefireBooter.main (SurefireBooter.java:781) Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.105 sec Running org.apache.tapestry.asset.TestAssetSource So i re-ran skipping the tests - which built the jars mvn -Dmaven.test.skip=true package On 14 Jul 2006, at 21:59, Jesse Kuhnert wrote: > I've not seen it before. What kind of servlet container is this > running in? > > On 7/14/06, Adam Henderson Azudio <[EMAIL PROTECTED]>
Re: Tap 4.1 Shell component Exceptions
I downloaded maven from apache (Maven 2.0.4), downloaded the Tapestry source from svn & ran the package command: mvn package which did its stuff but failed during the mock tests, so I re ran skipping the tests: One of the tests threw this: Running org.apache.tapestry.web.TestServletWebContext ServletWebContext [ERROR] Error getting context resource '/tapestry': Like this ever happens. java.net.MalformedURLException: Like this ever happens. at org.easymock.internal.MockInvocationHandler.invoke (MockInvocationHandler.java:31) at org.easymock.internal.ObjectMethodsFilter.invoke (ObjectMethodsFilter.java:45) at $Proxy72.getResource(Unknown Source) at org.apache.tapestry.web.ServletWebContext.getResource (ServletWebContext.java:78) at org.apache.tapestry.web.TestServletWebContext.testGetResourceFailure (TestServletWebContext.java:170) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.testng.internal.MethodHelper.invokeMethod (MethodHelper.java:552) at org.testng.internal.Invoker.invokeMethod(Invoker.java:407) at org.testng.internal.Invoker.invokeTestMethods (Invoker.java:778) at org.testng.internal.TestMethodWorker.run (TestMethodWorker.java:105) at org.testng.TestRunner.privateRun(TestRunner.java:682) at org.testng.TestRunner.run(TestRunner.java:566) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:220) at org.testng.SuiteRunner.run(SuiteRunner.java:146) at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:713) at org.testng.TestNG.runSuitesLocally(TestNG.java:676) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeTestNG( TestNGDirectoryTestSuite.java:195) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute (TestNGDirectoryTestSuite.java:145) at org.apache.maven.surefire.Surefire.run(Surefire.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess (SurefireBooter.java:261) at org.apache.maven.surefire.booter.SurefireBooter.main (SurefireBooter.java:781) Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.105 sec Running org.apache.tapestry.asset.TestAssetSource So i re-ran skipping the tests - which built the jars mvn -Dmaven.test.skip=true package On 14 Jul 2006, at 21:59, Jesse Kuhnert wrote: I've not seen it before. What kind of servlet container is this running in? On 7/14/06, Adam Henderson Azudio <[EMAIL PROTECTED]> wrote: Hi All, Just had a go at building from the 4.1 Snapshot and the Shell component seems to be throwing this list of exceptions related to dojo: Home.html http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> http://www.w3.org/1999/xhtml";> Hello World Hello Throws: WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry/html.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry/html.js' does not exist. at org.apache.tapestry.asset.AssetService.service( AssetService.java: 241) WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry.js' does not exist. WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/__package__.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/__package__.js' does not exist. The source HTML rendered out: http://www.w3.org/TR/html4/loose.dtd";> http://localhost:8080/BlankApp/"/> Test djConfig = { isDebug: true, debugContainerId:'debug', baseRelativePath:"<a rel="nofollow" href="http://localhost:8080/">http://localhost:8080/</a> BlankApp/app? digest=d41d8cd98f00b204e9800998ecf8427e&service=asset&path=%2Fdojo% 2F", preventBackButtonFix: false, parseWidgets: false }; http://localhost:8080/BlankApp/</a> </pre><tt>app?digest=9bf3abdc75fce5b0d2c4f330d5262a50&
Tap 4.1 Shell component Exceptions
Hi All, Just had a go at building from the 4.1 Snapshot and the Shell component seems to be throwing this list of exceptions related to dojo: Home.html "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> http://www.w3.org/1999/xhtml";> Hello World Hello Throws: WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry/html.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry/html.js' does not exist. at org.apache.tapestry.asset.AssetService.service(AssetService.java: 241) WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/../tapestry.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/../tapestry.js' does not exist. WARN - RequestExceptionReporterImpl.reportRequestException(45) | Failure to export classpath resource /dojo/__package__.js. org.apache.hivemind.ApplicationRuntimeException: Classpath resource '/ dojo/__package__.js' does not exist. The source HTML rendered out: "http://www.w3.org/TR/html4/loose.dtd";> http://localhost:8080/BlankApp/"/> Test djConfig = { isDebug: true, debugContainerId:'debug', baseRelativePath:"http://localhost:8080/ BlankApp/app? digest=d41d8cd98f00b204e9800998ecf8427e&service=asset&path=%2Fdojo% 2F", preventBackButtonFix: false, parseWidgets: false }; http://localhost:8080/BlankApp/ app?digest=9bf3abdc75fce5b0d2c4f330d5262a50&service=asset&path=%2Fdojo %2Fdojo.js"> dojo.require("dojo.logging.Logger"); dojo.log.setLevel(dojo.log.getLevel("WARNING")); Hello Is this just my cruddy build or is anyone else seeing this? Thanks, Adam - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checkbox required validation not working
OK, I've implemeted Scotts code but I'm still not getting any validation. Reg.page class="com.azudio.tapestry.validator.RequiredCheckbox"> I've put some debugging statements into the RequiredCheckbox class but it seems that when the page with the required checkbox is rendered the 'renderContribution' method never gets called, therefore no javascript gets output. Also when if the checkbox is left unchecked and the form submitted the 'validate' method also does not get called, only if its checked does 'validate' get called. Thanks, Adam On 25 Jun 2006, at 13:27, Adam Henderson Azudio wrote: Thanks Scott, I'll give your code a try. It might be worth sticking this up on the wiki as well. Thanks again, Adam On 24 Jun 2006, at 16:55, Maura Wilder wrote: no - Original Message - From: "Jesse Kuhnert" <[EMAIL PROTECTED]> To: "Tapestry users" Sent: Saturday, June 24, 2006 11:05 AM Subject: Re: Checkbox required validation not working Looks good Scott! I just wanted to say that in the upcoming 4.1 release the required generated client side javascript handles any/all form input types and so will produce meaningful results universally when applied. On 6/24/06, Scott Russell <[EMAIL PROTECTED]> wrote: Hi Adam, The required validator generates client-side javascript that calls the Tapestry.require_field function. This is the code of that function: Tapestry.require_field = function(event, fieldId, message) { var field = this.find(fieldId); if (field.value.length == 0) event.invalid_field(field, message); } Problem is, for a Checkbox field, the value of the checkbox is either true or false, so is thus never empty. Hence it always passes the require_field test. I wrote my own RequiredCheckbox validator as follows: RequiredCheckbox.java public class RequiredCheckbox extends Required { public void validate(IFormComponent field, ValidationMessages messages, Object object) throws ValidatorException { super.validate(field, messages, object); if ((object == null) || (Boolean.class.isInstance(object) && !((Boolean) object).booleanValue())) { String message = buildMessage(messages, field); throw new ValidatorException(message, ValidationConstraint.REQUIRED); } } private String buildMessage(ValidationMessages messages, IFormComponent field) { return messages.formatValidationMessage( getMessage(), ValidationStrings.REQUIRED_FIELD, new Object[] { field.getDisplayName() }); } public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { context.registerForFocus (ValidationConstants.REQUIRED_FIELD); context.includeClasspathScript ("/com/myapp/validator/BooleanValidator.js"); StringBuffer buffer = new StringBuffer("function(event) { Tapestry.require_boolean_field(event, '"); buffer.append(field.getClientId()); buffer.append("', "); buffer.append(TapestryUtils.enquote(buildMessage(context, field))); buffer.append("); }"); context.addSubmitHandler(buffer.toString()); } } BooleanValidator.js Tapestry.require_boolean_field = function(event, fieldId, message) { var field = this.find(fieldId); if (!field.checked) event.invalid_field(field, message); } Then you use it in your page file like this: Home.page class="com.myapp.validator.RequiredCheckbox"> Hope this helps. regards, Scott On Saturday 24 June 2006 22:22, Adam Henderson wrote: > Hi All, > > I'm doing a simple form that has a checkbox which must be checked in > order to submit the form: > > > T&C:value="ognl:readTC" > validators="validators:required"/> > type="submit" > name="Submit" value="Confirm"/> > > > but if I can still submit my form without the checkbox being checked, > so it looks like no validation is taking place. > > When the page renders the js generated at the base of the html is: > <!-- > Tapestry.register_form('myForm'); > Tapestry.set_focus('tandcCheckbox'); > > // --> > > I'm obviously missing a trick but I can't see what it is? > > Thanks, > Adam. -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. - To unsubscrib
Re: Checkbox required validation not working
Thanks Scott, I'll give your code a try. It might be worth sticking this up on the wiki as well. Thanks again, Adam On 24 Jun 2006, at 16:55, Maura Wilder wrote: no - Original Message - From: "Jesse Kuhnert" <[EMAIL PROTECTED]> To: "Tapestry users" Sent: Saturday, June 24, 2006 11:05 AM Subject: Re: Checkbox required validation not working Looks good Scott! I just wanted to say that in the upcoming 4.1 release the required generated client side javascript handles any/all form input types and so will produce meaningful results universally when applied. On 6/24/06, Scott Russell <[EMAIL PROTECTED]> wrote: Hi Adam, The required validator generates client-side javascript that calls the Tapestry.require_field function. This is the code of that function: Tapestry.require_field = function(event, fieldId, message) { var field = this.find(fieldId); if (field.value.length == 0) event.invalid_field(field, message); } Problem is, for a Checkbox field, the value of the checkbox is either true or false, so is thus never empty. Hence it always passes the require_field test. I wrote my own RequiredCheckbox validator as follows: RequiredCheckbox.java public class RequiredCheckbox extends Required { public void validate(IFormComponent field, ValidationMessages messages, Object object) throws ValidatorException { super.validate(field, messages, object); if ((object == null) || (Boolean.class.isInstance(object) && !((Boolean) object).booleanValue())) { String message = buildMessage(messages, field); throw new ValidatorException(message, ValidationConstraint.REQUIRED); } } private String buildMessage(ValidationMessages messages, IFormComponent field) { return messages.formatValidationMessage( getMessage(), ValidationStrings.REQUIRED_FIELD, new Object[] { field.getDisplayName() }); } public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { context.registerForFocus (ValidationConstants.REQUIRED_FIELD); context.includeClasspathScript ("/com/myapp/validator/BooleanValidator.js"); StringBuffer buffer = new StringBuffer("function(event) { Tapestry.require_boolean_field(event, '"); buffer.append(field.getClientId()); buffer.append("', "); buffer.append(TapestryUtils.enquote(buildMessage(context, field))); buffer.append("); }"); context.addSubmitHandler(buffer.toString()); } } BooleanValidator.js Tapestry.require_boolean_field = function(event, fieldId, message) { var field = this.find(fieldId); if (!field.checked) event.invalid_field(field, message); } Then you use it in your page file like this: Home.page class="com.myapp.validator.RequiredCheckbox"> Hope this helps. regards, Scott On Saturday 24 June 2006 22:22, Adam Henderson wrote: > Hi All, > > I'm doing a simple form that has a checkbox which must be checked in > order to submit the form: > > > T&C:value="ognl:readTC" > validators="validators:required"/> > type="submit" > name="Submit" value="Confirm"/> > > > but if I can still submit my form without the checkbox being checked, > so it looks like no validation is taking place. > > When the page renders the js generated at the base of the html is: > > > I'm obviously missing a trick but I can't see what it is? > > Thanks, > Adam. -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checkbox required validation not working
Thanks Scott, I'll give your code a try. It might be worth sticking this up on the wiki as well. Thanks again, Adam On 24 Jun 2006, at 16:55, Maura Wilder wrote: no - Original Message - From: "Jesse Kuhnert" <[EMAIL PROTECTED]> To: "Tapestry users" Sent: Saturday, June 24, 2006 11:05 AM Subject: Re: Checkbox required validation not working Looks good Scott! I just wanted to say that in the upcoming 4.1 release the required generated client side javascript handles any/all form input types and so will produce meaningful results universally when applied. On 6/24/06, Scott Russell <[EMAIL PROTECTED]> wrote: Hi Adam, The required validator generates client-side javascript that calls the Tapestry.require_field function. This is the code of that function: Tapestry.require_field = function(event, fieldId, message) { var field = this.find(fieldId); if (field.value.length == 0) event.invalid_field(field, message); } Problem is, for a Checkbox field, the value of the checkbox is either true or false, so is thus never empty. Hence it always passes the require_field test. I wrote my own RequiredCheckbox validator as follows: RequiredCheckbox.java public class RequiredCheckbox extends Required { public void validate(IFormComponent field, ValidationMessages messages, Object object) throws ValidatorException { super.validate(field, messages, object); if ((object == null) || (Boolean.class.isInstance(object) && !((Boolean) object).booleanValue())) { String message = buildMessage(messages, field); throw new ValidatorException(message, ValidationConstraint.REQUIRED); } } private String buildMessage(ValidationMessages messages, IFormComponent field) { return messages.formatValidationMessage( getMessage(), ValidationStrings.REQUIRED_FIELD, new Object[] { field.getDisplayName() }); } public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { context.registerForFocus (ValidationConstants.REQUIRED_FIELD); context.includeClasspathScript ("/com/myapp/validator/BooleanValidator.js"); StringBuffer buffer = new StringBuffer("function(event) { Tapestry.require_boolean_field(event, '"); buffer.append(field.getClientId()); buffer.append("', "); buffer.append(TapestryUtils.enquote(buildMessage(context, field))); buffer.append("); }"); context.addSubmitHandler(buffer.toString()); } } BooleanValidator.js Tapestry.require_boolean_field = function(event, fieldId, message) { var field = this.find(fieldId); if (!field.checked) event.invalid_field(field, message); } Then you use it in your page file like this: Home.page class="com.myapp.validator.RequiredCheckbox"> Hope this helps. regards, Scott On Saturday 24 June 2006 22:22, Adam Henderson wrote: > Hi All, > > I'm doing a simple form that has a checkbox which must be checked in > order to submit the form: > > > T&C:value="ognl:readTC" > validators="validators:required"/> > type="submit" > name="Submit" value="Confirm"/> > > > but if I can still submit my form without the checkbox being checked, > so it looks like no validation is taking place. > > When the page renders the js generated at the base of the html is: > > > I'm obviously missing a trick but I can't see what it is? > > Thanks, > Adam. -- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checkbox required validation not working
No difference, I changed the form to: listener="listener:confirm"> T&C:validators="validators:required"/> On 24 Jun 2006, at 13:33, James Carman wrote: What happens if you take the listener off the button and put it on the form itself. -Original Message- From: Adam Henderson [mailto:[EMAIL PROTECTED] Sent: Saturday, June 24, 2006 8:23 AM To: Tapestry users Subject: Checkbox required validation not working Hi All, I'm doing a simple form that has a checkbox which must be checked in order to submit the form: clientValidationEnabled="ognl:true"> T&C: but if I can still submit my form without the checkbox being checked, so it looks like no validation is taking place. When the page renders the js generated at the base of the html is: I'm obviously missing a trick but I can't see what it is? Thanks, Adam. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]