Announcement Announcement Module
Collapse
No announcement yet.
Input Text and spring:bind, space pb ! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Input Text and spring:bind, space pb !

    hi,

    i 've got a space pb :

    [historiqueCarte.id has 10385 for value]

    Case 1:

    Code:
    <spring&#58;bind path="historiqueCarte.id">
    	<input type="text" name="id" value="$&#123;status.value&#125;"/>
    </spring&#58;bind>
    Résult : 10 385 (with a space between 10 and 385)

    Case 2 :

    Code:
    <spring&#58;bind path="historiqueCarte.id">
    	<input type="text" name="id" value="$&#123;historiqueCarte.id&#125;"/>
    </spring&#58;bind>
    Résult : 10385 (with no space between 10 and 385)

    When the bind occur : in the case one it take an incorrect value : 10 for id instead of 10385.

    Maybe i make a mistake ...

    Thanks,

    Fabien.

  • #2
    Case 1:
    BindStatus object internally delegates to BeanWrapperImpl to return the object property value. It seems like you have a registered PropertyEditor that formats number into String "99 999".
    Case 2:
    You are using JSTL. No value formatting happens.

    Comment


    • #3
      Hi and thanks for your answer.

      You're right, i have register this CustumNumberEditor :

      Code:
      NumberFormat nf = NumberFormat.getNumberInstance&#40;&#41;;
      binder.registerCustomEditor&#40;Long.class, null, new CustomNumberEditor&#40;Long.class, nf, true&#41;&#41;;
      But in my case, what other binder editor should i use ?

      Thanks,

      Fabien.

      Comment


      • #4
        CustomNumberEditor seems to work fine.

        e.g.

        calling cne.setValue(new Long(10385)) then calling cne.getAsText() returns "10,385" (I'm in Sydney so I get a comma).

        then calling cne.getValue() returns a Long 10385

        My guess is that you're not registering the property editor *both* when you are handling a POST and also when you are showing a page. You probably get the value of 10 for a POST since no propertyeditor is configured.

        Where do you call the code sample that you include in your original post?

        Comment


        • #5
          I ran into a similar problem when converting from regular <c:out> tags to <spring:bind> tags... before the switch, my jsp worked fine, but afterwards, it would concatenate all my numeric fields with the same "name=" attribute into a string, and I would get number format exceptions from the CustomNumberEditor :?:

          I found that when using <spring:bind>, you have to convert some of your other fields to ${status.______} format.

          In my case, I switched from
          Code:
          name="quantity"
          to
          Code:
          name="<c&#58;out value="$&#123;status.expression&#125;"/>"
          and all of my problems disappeared.

          Try checking out the spring tag library documentation, and see if you find anything that might help: http://www.springframework.org/docs/taglib/

          Comment


          • #6
            Similar Problem solved with status.expression

            I had a String[] in my command object named values.

            JSP had <spring:bind path="metric.values"> tags around multiple input text fields. Each of the input text fields had the same name, all had different ids. Each input field had name="values".

            Seemed to work fine, until I entered a comma into my text field. Spring split my single text entry into two entries in the array.

            I replaced name="values" with name="<c:out value="${status.expression}" /> and all seems to work fine now. Commas do not cause multiple entries in the array.

            Just an FYI for anyone else who encounters this. I am curious why this occurs though?

            Comment

            Working...
            X