Results 1 to 5 of 5

Thread: UTF8 conversion using form tags

  1. #1

    Default 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 at 08:36 PM.

  2. #2

    Default

    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

  3. #3
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    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

  4. #4

    Default

    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 ?

  5. #5

    Default

    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.

Posting Permissions

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