You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Harish Krishnaswamy <hk...@comcast.net> on 2004/01/01 00:11:54 UTC

Re: Strange BindingException that this beginner can't figure out

NumberValidator can only be used to validate and convert numbers. I would normally render 
enumerations as PropertySelections and so wouldn't need any validation. But if for some reason a 
select list is not an appropriate widget for the enumeration, I would create a generic EnumValidator 
that can be used with any enumeration based on the org.apache.commons.lang.enum.Enum

-Harish

Philip wrote:
> Harish,
> 
> Thanks much.  Using a NumberValidator was exactly what I needed to do.  It
> worked.
> How would you suggest validating an enum, like M/F for mail and female?  Can
> I use NumberValidator and using some set-property, or would you recommend
> just implementing my own validator?
> 
> Anyway, thanks for the advice!
> 
> Regards,
> Philip
> __________________________
> 
> ----- Original Message -----
> From: "Harish Krishnaswamy" <hk...@comcast.net>
> To: "Tapestry users" <ta...@jakarta.apache.org>
> Sent: Wednesday, December 31, 2003 2:13 PM
> Subject: Re: Strange BindingException that this beginner can't figure out
> 
> 
> 
>>*char*s are represented as short integers in Java/C. And TextField
> 
> component requires a string
> 
>>property to be bound to the "value" parameter. There are a few things you
> 
> can do...
> 
>>1. Create a synthetic String property and convert the string returned from
> 
> the TextField to char and
> 
>>update Cat.
>>2. Change the property sex in Cat to String
>>3. Use a ValidField property in place of TextField and use a
> 
> NumberValidator
> 
>>-Harish
>>
>>Philip wrote:
>>
>>
>>>Hi there,
>>>
>>>I'm fairly new to the Tapestry framework, so please forgive me if there
> 
> is an obvious answer to this question -- believe me, I've looked for it. :-)
> 
>>>I hope that this message doesn't include too much info, so just so you
> 
> know what to expect.  I provide:
> 
>>>1. What I'm doing.
>>>2. Tapestry screen exception
>>>3. Jboss log excerpt showing exception and a few lines before
>>>4. Snip from form html page.
>>>5. Snip from corresponding .page file
>>>6. Snip from corresponding BasePage class
>>>7. Cat object, which is why I have my setters and getters
>>>
>>>
>>>1. What I'm doing.
>>>I'm just playing with the framework with a Cat object with two
> 
> attributes; name and sex, and their setters and getters.  The Cat object is
> used by the BasePage class and it's methods are called using ognl.
> 
>>>When I submit the Add Cat form with Name (String) and Sex (char), I get:
>>>
>>>org.apache.tapestry.BindingException
>>>Unable to update expression 'cat.sex' for
> 
> myapps.mytapapp.Cats@1cfd41a[SubmitSomeShit] to M.
> 
>>>binding:ExpressionBinding[SubmitSomeShit cat.sex]
>>>location:context:/WEB-INF/SubmitSomeShit.html, line 5
>>>
>>>ognl.OgnlException
>>>sex
>>>
>>>java.lang.NumberFormatException
>>>For input string: "M"
>>>Stack Trace:
>>>
> 
> java.lang.NumberFormatException.forInputString(NumberFormatException.java:48
> )
> 
>>>java.lang.Long.parseLong(Long.java:323)
>>>java.lang.Long.parseLong(Long.java:381)
>>>ognl.OgnlOps.longValue(OgnlOps.java:87)
>>>ognl.OgnlOps.convertValue(OgnlOps.java:199)
>>>ognl.DefaultTypeConverter.convertValue(DefaultTypeConverter.java:50)
>>>ognl.DefaultTypeConverter.convertValue(DefaultTypeConverter.java:55)
>>>ognl.OgnlRuntime.getConvertedType(OgnlRuntime.java:428)
>>>ognl.OgnlRuntime.getConvertedTypes(OgnlRuntime.java:447)
>>>ognl.OgnlRuntime.getConvertedMethodAndArgs(OgnlRuntime.java:473)
>>>...
>>>------snip-------
>>>
>>>The jboss server.log file shows:
>>>
>>>2003-12-31 11:52:58,680 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter disabled.
> 
>>>2003-12-31 11:52:58,681 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Not bound.
> 
>>>2003-12-31 11:52:58,681 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter hidden.
> 
>>>2003-12-31 11:52:58,681 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Not bound.
> 
>>>2003-12-31 11:52:58,681 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter
> templateTag.
> 
>>>2003-12-31 11:52:58,682 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Parameter is AUTO.
> 
>>>2003-12-31 11:52:58,682 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter value.
> 
>>>2003-12-31 11:52:58,682 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Parameter is CUSTOM.
> 
>>>2003-12-31 11:52:58,689 INFO  [STDOUT] Cat.setName(): setting the name
> 
> to 'Joe Schmo'
> 
>>>2003-12-31 11:52:58,690 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager]
> org.apache.tapestry.form.TextField$Enhance_320@f50154[SubmitSomeShit/$TextFi
> eld$0]: connecting parameters and properties
> 
>>>2003-12-31 11:52:58,690 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter disabled.
> 
>>>2003-12-31 11:52:58,690 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Not bound.
> 
>>>2003-12-31 11:52:58,691 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter hidden.
> 
>>>2003-12-31 11:52:58,691 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Not bound.
> 
>>>2003-12-31 11:52:58,691 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter
> templateTag.
> 
>>>2003-12-31 11:52:58,693 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Parameter is AUTO.
> 
>>>2003-12-31 11:52:58,693 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Connecting parameter value.
> 
>>>2003-12-31 11:52:58,694 DEBUG
> 
> [org.apache.tapestry.param.ParameterManager] Parameter is CUSTOM.
> 
>>>2003-12-31 11:52:58,696 DEBUG [org.apache.tapestry.engine.RequestCycle]
> 
> Removing attribute org.apache.tapestry.active.Form
> 
>>>2003-12-31 11:52:58,696 INFO
> 
> [org.apache.tapestry.engine.AbstractEngine] Uncaught exception
> 
>>>org.apache.tapestry.BindingException: Unable to update expression
> 
> 'cat.sex' for myapps.mytapapp.Cats@1cfd41a[SubmitSomeShit] to M.
> 
>>>        at
> 
> org.apache.tapestry.binding.ExpressionBinding.setObject(ExpressionBinding.ja
> va:565)
> 
>>>        at
> 
> org.apache.tapestry.binding.ExpressionBinding.setString(ExpressionBinding.ja
> va:300)
> 
>>>        at
> 
> org.apache.tapestry.form.TextField.updateValue(TextField.java:82)
> 
>>>        at
> 
> org.apache.tapestry.form.AbstractTextField.renderComponent(AbstractTextField
> .java:109)
> 
>>>        at
> 
> org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:880)
> 
>>>        at
> 
> org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:657)
> 
>>>        at org.apache.tapestry.form.Form.renderComponent(Form.java:396)
>>>        at
> 
> org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:880)
> 
>>>        at org.apache.tapestry.form.Form.rewind(Form.java:602)
>>>        at
> 
> org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:475)
> 
>>>        at org.apache.tapestry.form.Form.trigger(Form.java:616)
>>>...
>>>------snip----
>>>
>>>So, I can see that Cat.setName() works, but that something goes wrong
> 
> with the Cat.setSex() method.  It looks like a mapping issuse where it
> thinks that there's a number, but it's really a character.  I'm not really
> sure, so I'm posing the question to the list.
> 
>>>________snip from html page__________
>>><tr><td>Cat Name</td><td><input jwcid="@TextField"
> 
> value="ognl:cat.name"/></td></tr>
> 
>>><tr><td>Cat Sex</td><td><input jwcid="@TextField"
> 
> value="ognl:cat.sex"/></td></tr>
> 
>>><tr><td colspan="2" align="right"><input type="submit" jwcid="@Submit"
> 
> listener="ognl:listeners.addNewCat" value="Add New Cat"/></td></tr>
> 
>>>_____________________________________
>>>
>>>
>>>_______snip from .page file__________
>>><page-specification class="myapps.mytapapp.Cats">
>>>no components defined as I'm using ognl on the html page
>>></page-specification>
>>>_____________________________________
>>>
>>>
>>>_______snip from myapps.mytapapp.Cats_____
>>>import myapps.mytapapp.crap.Cat;
>>>public class Cats extends BasePage {
>>>    private Cat cat;
>>>    public Cat getCat() {
>>>        methodsRun.append(" getCat() ");
>>>        return this.cat;
>>>    }
>>>
>>>    public void addNewCat(IRequestCycle cycle) {
>>>                try {
>>>                    ////database stuff in here
>>>
>>>                } catch (HibernateException he) {
>>>                    System.out.println("Cats.addNewCat(): " +
> 
> he.getMessage());
> 
>>>                    he.printStackTrace();
>>>                }
>>>
>>>        }
>>>
>>>      // in this method, I initialize an empty this.cat object
>>>      protected void initialize() {
>>>            this.cat = new Cat();
>>>      }
>>>________________________________________
>>>
>>>____snip from myapps.mytapapp.crap.Cat__
>>>public class Cat {
>>>
>>>    private String id;
>>>    private String name;
>>>    private char sex;
>>>
>>>    public Cat() {
>>>        this.sex = 'x';
>>>        this.weight = 0;
>>>    }
>>>
>>>    public String getId() {
>>>        return id;
>>>    }
>>>
>>>    public void setId(String id) {
>>>        this.id = id;
>>>    }
>>>
>>>    public String getName() {
>>>        return name;
>>>    }
>>>
>>>    public void setName(String name) {
>>>        this.name = name;
>>>    }
>>>
>>>    public char getSex() {
>>>        return sex;
>>>    }
>>>
>>>    public void setSex(char sex) {
>>>        this.sex = sex;
>>>    }
>>>
>>>
>>>}
>>>_______________________________
>>>
>>>
>>>Thanks in advance for your help!!!!
>>>
>>>Philip
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org