Announcement Announcement Module
Collapse
No announcement yet.
UTF8 conversion using form tags Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • UTF8 conversion using form tags

    Hi All,

    Currently I am using the spring form tags to capture and bind data automatically....

    ie
    Code:
    <form:input path="fooName" maxlength="..."/>
    ... but since I need to able to store other than english I am having to convert each of these values within 'onSubmit' before saving them to the db. It works ok , but it seems to defeat the purpose of automatic binding since I recall each value and convert before resaving.

    ie
    Code:
    fooObject.setFooName(FooUtils.toUTF8(fooObject.getFooName()));
    I need to somehow modify the settings so the form tags automatically bind WITH the UTF8 already in place, rather than me having to convert within the controllers every time.

    I would appreciate being pointed in the right direction.

    regards...
    Last edited by ibnaziz; Feb 20th, 2008, 09:36 PM.

  • #2
    Apologies if that sounded muffled. Essentially what I am trying to ask about is a way to ensure that while the values are automatically bound the UTF-8 factor is already taken care of...

    much appreciated

    Comment


    • #3
      If your HTML page is declared as using UTF-8 encoding, the client's browser should send the answers as UTF-8, so you should not need to recode them. The problem might be that most browser dont tell the server which encoding they used to send data and the server falls back to ISO 8859. You can use a filter to set the encoding right : http://static.springframework.org/sp...ingFilter.html

      Comment


      • #4
        I have just tried your suggestion, with the following configuration in the web.xml...

        Code:
        	<filter>
        		<filter-name>encodingFilter</filter-name>
        		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        		<init-param>
        			<param-name>encoding</param-name>
        			<param-value>UTF-8</param-value>
        		</init-param>
        		<init-param>
        			<param-name>forceEncoding</param-name>
        			<param-value>true</param-value>
        		</init-param>
        	</filter>
        ... but it still doesn't work. Have I missed something ?

        Comment


        • #5
          Turns out, I WAS missing something. Anyway, it's solved now.. and for those who are interested it is explained here..

          http://ibnaziz.wordpress.com/2008/06...ncodingfilter/

          regards.

          Comment

          Working...
          X