Results 1 to 3 of 3

Thread: Setting property of type String question

  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Default Setting property of type String question

    Hello,
    Hopefully this is an easy question for the forum, but it's a problem I haven't been able to figure out, thus far.

    I am setting a property of type String in this fashion:

    <bean ....>
    <property name="timeFormat" value="%m/%d\n%l%P"/>
    ...
    </bean

    However, when the setFormat method is called by the framework, the String's charArray looks like this: (size: 11) [%, m, /, %, d, \, n, %, l, %, P]; Note that the "\n" have been split into two characters, instead of one.

    If I set the property manually in my class using a String literal or a String constructor, it does the right thing: size(10) [%, m, /, %, d, \n, %, l, %, P]

    Is there a way to tell Spring to behave the same way as a String's constructor?

    Thanks, in advance, for any tips you can provide.
    Last edited by bostond; Jul 25th, 2007 at 10:00 AM.

  2. #2
    Join Date
    Jul 2007
    Posts
    2

    Default Looks like an XML quirk, and not a Java type issue...

    Escaping the newline in the xml has fixed the issue:

    <property name="timeFormat" value=""%m/%d&#xa;%l%P/>

    where "\n" was replaced by "&#xa;"

  3. #3
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by bostond View Post
    However, when the setFormat method is called by the framework, the String's charArray looks like this: (size: 11) [%, m, /, %, d, \, n, %, l, %, P]; Note that the "\n" have been split into two characters, instead of one.
    That (and your fix) are quite obvious since it's an XML parser reading the string, not Java.

    Jörg

Posting Permissions

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