Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Encoding problem with text fields in multipart DynamicForm

    I am using SmartGWTPower 2.5 and Firefox 6.0.2, I have a form which contains text and binary fields as well. Values of text fields are expected to contain ISO 8859-2 (Latin 2) characters, which have encoding errors when I read them out on the server side. I have tried to comment out the binary field in the ds.xml and the characters appeared on the server side properly. Calling the DynamicForm.setEncoding method didn't help. Could you please help me to solve this problem?

    sample ds.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <DataSource ID="myDataSource">
      <fields>
        <field name="name" primaryKey="true" type="text" />
        <field name="fileData" type="binary" />
      </fields>
    </DataSource>
    sample client:
    Code:
      public MyUploadFormWidget() {
        super(15);
        final DynamicForm frmUpload = new DynamicForm();
        frmUpload.setDataSource(DataSource.get("myDataSource"));
        addMember(frmUpload);
        IButton btnSave = new IButton("Save");
        btnSave.addClickHandler(new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            frmUpload.saveData();
          }
        });
        addMember(btnSave);
      }

    server log:
    Code:
    INFO: ===  INFO 2011.09.27 17:53:19 (Logger.java:388) - URL: '/MyProject/myproject/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2': Moz (Gecko) with Accept-Encoding header
    
    
    INFO: === DEBUG 2011.09.27 17:53:19 (Logger.java:406) - Parsed XML from (in memory stream): 3ms
    
    INFO: === DEBUG 2011.09.27 17:53:19 (Logger.java:406) - Parsed XML from C:\glassfish3\glassfish\domains\domain1\eclipseApps\MyProject\myproject\sc\system\schema\List.ds.xml: 2ms
    
    INFO: === DEBUG 2011.09.27 17:53:19 (Logger.java:406) - Processing 1 requests.
    
    INFO: === DEBUG 2011.09.27 17:53:19 (Logger.java:406) - Request #1 (DSRequest) payload: {
        values:{
            fileData:"tmp.txt",
            name:"árvĂ*ztűrĹ‘tĂĽkörfĂşrĂłgĂ©p",
            fileData_filename:"tmp.txt",
            fileData_date_created:new Date(1317139629496),
            fileData_filesize:3
        },
        operationConfig:{
            dataSource:"myDataSource",
            operationType:"add"
        },
        componentId:"isc_DynamicForm_2",
        appID:"builtinApplication",
        operation:"myDataSource_add",
        oldValues:{
        },
        criteria:{
        }
    }
    FireBug:
    Code:
    POST:
    fileDatatmp_transaction<transaction xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object"><transactionNum xsi:type="xsd:long">0</transactionNum><operations xsi:type="xsd:List"><elem xsi:type="xsd:Object"><values xsi:type="xsd:Object"><fileData>tmp.txt</fileData><name>árvíztűrőtükörfúrógép</name></values><operationConfig xsi:type="xsd:Object"><dataSource>myDataSource</dataSource><operationType>add</operationType></operationConfig><componentId>isc_DynamicForm_2</componentId><appID>builtinApplication</appID><operation>myDataSource_add</operation><oldValues xsi:type="xsd:Object"></oldValues></elem></operations><jscallback>parent.isc.Comm.hiddenFrameReply(0,results)</jscallback></transaction>
    
    header:
    X-Powered-By	Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1 Java/Sun Microsystems Inc./1.6)
    Server	GlassFish Server Open Source Edition 3.1
    X-Included-Test2	true
    X-Included-Test	true
    Cache-Control	no-cache
    Pragma	no-cache
    Expires	Tue, 27 Sep 2011 16:07:09 GMT
    Content-Encoding	gzip
    Content-Type	text/html;charset=UTF-8
    Content-Length	297
    Date	Tue, 27 Sep 2011 16:07:08 GMT
    Kérés fejlécekforrás megtekintése
    Host	localhost:8080
    User-Agent	Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
    Accept	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language	hu-hu,hu;q=0.8,en-us;q=0.5,en;q=0.3
    Accept-Encoding	gzip, deflate
    Accept-Charset	UTF-8,*
    Connection	keep-alive
    Referer	http://localhost:8080/MyProject/
    Cookie	JSESSIONID=b74614f4cce7a472e72de86c367e; isc_cState=ready

    #2
    This thread is quite old, but we encounter something similar today.

    There are some workarounds, but I'd prefer to have a better solution then those:

    1. Split the form into two separate forms one without binary fields and one with all your binary fields, then you'll have two requests to server but the problem goes away.

    2. Be sure to force the values sent by the client to your encoding. Of course this will work only for these DataSources where binary fields are present. (see example below)

    Code:
    private void applyEncodingToStringFieldsInRecord(Map record) throws UnsupportedEncodingException {
            Set keySet = record.keySet();
            for (Object o : keySet) {
                if (record.get(o) instanceof String) {
                    record.put(o, new String(((String) record.get(o)).getBytes(), "ISO-8859-1"));
                }
            }
        }
    I'd prefer to have a better solution, maybe some way to specify the correct charset?

    Help please, we're using smartGWT pro 3.0, GWT 2.3.0.
    Any suggestion?

    Comment

    Working...
    X