Results 1 to 8 of 8

Thread: spring:bind tag with virtual javabean properties

  1. #1
    Join Date
    Apr 2005
    Location
    Guildford, UK
    Posts
    15

    Default spring:bind tag with virtual javabean properties

    Hi
    I have a weird problem - I have a bean with a 'firstName' property backed by a String field. However, since I want to do some processing of the string both on input and display, I have mirrored the getters and setters to create a virtual 'firstNameDisplay' property:
    Code:
    public String getFirstName() {
    		return firstName;
    	}
        
        public String getFirstNameDisplay(){
            return replaceWildcardForDisplay(firstName);
        }
    
    public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
        
        public void setFirstNameDisplay(String firstNameDisplay){
            setFirstName(replaceWildcardForDB(firstNameDisplay));
        }
    However, when I try to use 'spring:bind path="item.firstNameDisplay"' I get the following error:
    Code:
    org.springframework.context.NoSuchMessageException: No message found under code 'methodInvocation.item.firstNameDisplay' for locale 'en_US'.
    	at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:73)
    	at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:68)
    	at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:594)
    	at org.springframework.web.servlet.support.RequestContext.getMessage(RequestContext.java:492)
    	at org.springframework.web.servlet.support.BindStatus.getErrorMessages(BindStatus.java:171)
    	at org.springframework.web.servlet.support.BindStatus.<init>&#40;BindStatus.java&#58;128&#41;
    	at org.springframework.web.servlet.tags.BindStatus.<init>&#40;BindStatus.java&#58;38&#41;
    	at org.springframework.web.servlet.tags.BindTag.doStartTagInternal&#40;BindTag.java&#58;105&#41;
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag&#40;RequestContextAwareTag.java&#58;70&#41;
    	at org.apache.jsp.WEB_002dINF.jsp.cma.searchUsers_jsp._jspService&#40;org.apache.jsp.WEB_002dINF.jsp.cma.searchUsers_jsp&#58;111&#41;
    Is this because it is a virtual field or is there some other problem I'm missing? I realise I could also do this with a PropertyEditor during binding, but this way seemed quicker to me initially...
    Neil Canham
    Know Sense Limited
    ...sense from KnowSense

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Looking at your stack tract, it appears that you have bind errors and rejecting a field with the message 'methodInvocation.item.firstNameDisplay'.

    Are you doing any validation? Can you post your jsp fragment.

  3. #3
    Join Date
    Apr 2005
    Location
    Guildford, UK
    Posts
    15

    Default

    Here's the jsp fragment:
    Code:
    <spring&#58;bind path="item.firstNameDisplay">
    			<input name="$&#123;status.expression&#125;" size="40" maxlength="60" value="$&#123;status.value&#125;" type="text">
    		</spring&#58;bind>

    There's no validation. The thing that makes me suspicous is that if I change the page to bind to the real property 'firstName' it works fine, changing it to the virtual property creates the exception. So I'm guessing that such virtual properties are not supported. Anyone want to comment?
    Neil Canham
    Know Sense Limited
    ...sense from KnowSense

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Hmmm, strange.

    There is no such thing as a "virtual property" from spring's point of view,it just uses the accessors (unless someone tells me differently ).

    What does replaceWildCard do?

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    And yes, I am just starting to see the beginnings of a red fish up ahead

  6. #6
    Join Date
    Apr 2005
    Location
    Guildford, UK
    Posts
    15

    Default

    I had hoped that there was no such thing as a virtual property for Spring and that the existence of the accessors would be enough....

    Cutting to the chase, replaceWildCard simply replaces all * with % or vice-versa as the user prefers to use * for their wildcard character. So I'm wondering if Spring is detecting that updating one property has caused another to change... but so what? I must be hard of herring as I can't see what's wrong... :?
    Neil Canham
    Know Sense Limited
    ...sense from KnowSense

  7. #7
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    And you are *sure* you have no validation, because your stack trace is from
    Code:
     at org.springframework.web.servlet.support.BindStatus.getErrorMessages&#40;BindStatus.java&#58;171&#41;
    Hmmm. puzzling. Maybe post your entire controller, form, and mapping.

  8. #8
    Join Date
    Apr 2005
    Location
    Guildford, UK
    Posts
    15

    Default

    Thanks for your continued interest...

    I'm convinced that there is no validation involved. We've happily used validation in other parts of the app and no validation is configured/inherited/abused in this very simple form/controller setup.. I'll post them tomorrow. But I spotted as you say that it is a binding error.. what concerns me is the first part of the error text identfier - methodInvocation.item.firstNameDisplay - where has 'methodInvocation' come from? I will bite the bullet and debug the source tomorrow.
    Neil Canham
    Know Sense Limited
    ...sense from KnowSense

Similar Threads

  1. FlowExecutionStorage in a DB
    By cacho in forum Web Flow
    Replies: 7
    Last Post: Oct 19th, 2009, 03:36 PM
  2. Replies: 6
    Last Post: Sep 16th, 2005, 04:17 AM
  3. Replies: 1
    Last Post: Apr 19th, 2005, 01:53 AM
  4. Shared properties within application context
    By milosh in forum Architecture
    Replies: 5
    Last Post: Nov 16th, 2004, 08:29 AM
  5. Replies: 19
    Last Post: Oct 20th, 2004, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •