bad encoding for f:param value in pretty-config

Splash Forums PrettyFaces Users bad encoding for f:param value in pretty-config

This topic contains 23 replies, has 3 voices, and was last updated by  Lincoln Baxter III 6 years, 8 months ago.

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #17841

    xuzhike
    Participant

    Hello guy’s, I want to pass param by <f:param, and it is value is chinese, found it cannot be passed to backendBean correctly.

    1: xhtml file:

    <h:link outcome=”/ui/test/fileUpload.xhtml” value=”上传文件”>

    <f:param name=”query1″ value=”上传文件” /> <!– used by prettyFaces –>

    <f:param name=”jsfParam” value=”jsfParam-上传文件” />

    </h:link>

    2: pretty-config.xml

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload/#{query1:testView.query1}</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    </url-mapping>

    3: testView:

    @ManagedBean(name = “testView”)

    @RequestScoped

    public class TestView extends BaseView {

    private static final Logger log = Logger.getLogger(TestView.class);

    private String query1;

    @ManagedProperty(value=”#{param.jsfParam}”)

    private String jsfParam;

    public String getJsfParam() {

    log.info(“TestView.getJsfParam = “+jsfParam);

    return jsfParam;

    }

    public void setJsfParam(String jsfParam) {

    log.info(“TestView.setJsfParam = “+jsfParam);

    this.jsfParam = jsfParam;

    }

    public String getQuery1() {

    log.info(“TestView.getQuery1 = “+query1);

    return query1;

    }

    public void setQuery1(String query1) {

    log.info(“TestView.setQuery1 = “+query1);

    this.query1 = query1;

    }

    Test result:

    TestView.setJsfParam = jsfParam-????????????????????????

    TestView.setQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    questions:

    1) What should I do to pass non-english value for <f:param ?

    2) seems TestView.getQuery1 excution times is more than TestView.setJsfParam.

    my phaseListener log:

    22:21:15,093 INFO MyPhaseListener:26 –

    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Begin

    22:21:15,093 INFO MyPhaseListener:27 – Processing new Request!

    22:21:15,093 INFO MyPhaseListener:29 – before – RESTORE_VIEW 1

    22:21:15,109 INFO MyPhaseListener:15 – after – RESTORE_VIEW 1

    22:21:15,109 INFO TestView:32 – TestView.setJsfParam = jsfParam-????????????????????????

    22:21:15,109 INFO TestView:42 – TestView.setQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,109 INFO MyPhaseListener:29 – before – RENDER_RESPONSE 6

    22:21:15,187 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,187 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,203 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,203 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,203 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,203 INFO TestView:27 – TestView.getJsfParam = jsfParam-????????????????????????

    22:21:15,203 INFO TestView:27 – TestView.getJsfParam = jsfParam-????????????????????????

    22:21:15,218 INFO TestView:37 – TestView.getQuery1 = %25E4%25B8%258A%25E4%25BC%25A0%25E6%2596%2587%25E4%25BB%25B6

    22:21:15,218 INFO TestView:27 – TestView.getJsfParam = jsfParam-????????????????????????

    22:21:15,218 INFO TestView:27 – TestView.getJsfParam = jsfParam-????????????????????????

    22:21:15,218 INFO MyPhaseListener:15 – after – RENDER_RESPONSE 6

    22:21:15,218 INFO MyPhaseListener:18 – Done with Request!

    22:21:15,218 INFO MyPhaseListener:19 – <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<END

    TestView.getJsfParam: four times

    TestView.getQuery1: six times. why???

    thx for your help in advance

    #20529

    Thank you very much for reporting this. Actually we are currently working on the path and query parameter encoding as there are some things wrong in the current stable release. Could you perhaps try the latest snapshots and check if this fixes your problem?

    If you are using Maven, just set the version to 3.1.1-SNAPSHOT:

    <dependency>
    <groupId>com.ocpsoft</groupId>
    <artifactId>prettyfaces-jsf2</artifactId>
    <version>3.1.1-SNAPSHOT</version>
    </dependency>

    Please make also sure that you have the OcpSoft Maven Repository in your pom.xml:

    <repository>
    <id>ocpsoft</id>
    <name>OcpSoft</name>
    <url>http://ocpsoft.com/repository/</url>
    <releases>
    <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
    </repository>

    You can also directly download the latest snapshot from the repository here.

    It would also be very interesting for us to know which container you are using as some encoding issues see to be related to specific container implementations.

    Thanks!

    #20530

    xuzhike
    Participant

    Hi, Christian

    thanks for your reply.

    I use apache-tomcat-6.0.29 for my project.

    I downloaded the latest prettyFaces jar — prettyfaces-jsf2-3.1.1-20101213.211312-54.jar

    my testing result as following:

    1: java,

    @ManagedBean(name = “testView”)

    @RequestScoped

    public class TestView extends BaseView {

    private static final Logger log = Logger.getLogger(TestView.class);

    private String query1;

    @ManagedProperty(value=”#{param.jsfParam}”)

    private String jsfParam;

    public String getJsfParam() {

    log.info(“TestView.getJsfParam = “+jsfParam);

    return jsfParam;

    }

    public void setJsfParam(String jsfParam) {

    log.info(“TestView.setJsfParam = “+jsfParam);

    this.jsfParam = jsfParam;

    }

    public String getQuery1() {

    log.info(“TestView.getQuery1 = “+query1);

    return query1;

    }

    public void setQuery1(String query1) {

    log.info(“TestView.setQuery1 = “+query1);

    this.query1 = query1;

    }


    test 1


    1-1: pretty-config:

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload/#{query1:testView.query1}</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    </url-mapping>

    1-2: xhtml file:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    上传文件

    </pretty:link>

    === test result:

    URL: http://localhost:8080/echaoshi/fileUpload/%20%87%F6

    log: INFO TestView:42 – TestView.setQuery1 = //no value, strange.



    test 2

    condition:

    just update xhtml file:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    <f:param name=”jsfParam” value=”上传文件”/>

    上传文件

    </pretty:link>

    test result:

    Firefox/IE7: http://localhost:8080/echaoshi/fileUpload/%20%87%F6?jsfParam=%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6

    Chrome: seems correct, but if copy/past here, same as IE7.

    log:

    19:45:21,665 INFO TestView:32 – TestView.setJsfParam = ????????????????????????

    19:45:21,665 INFO TestView:42 – TestView.setQuery1 =


    test 3

    condition update xhtml: user h:link

    <h:link outcome=”/ui/test/fileUpload.xhtml” value=”上传文件1″>

    <f:param name=”query1″ value=”上传文件”/>

    </h:link>

    test result:

    URL: http://localhost:8080/echaoshi/fileUpload/%20%87%F6

    log:

    19:51:33,149 INFO TestView:32 – TestView.setJsfParam = null

    19:51:33,165 INFO TestView:42 – TestView.setQuery1 =


    test 4

    xhtml:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    上传文件

    </pretty:link>

    pretty-config: use query-param

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    <query-param name=”query1″> #{testView.query1} </query-param>

    </url-mapping>

    test result:

    URL: http://localhost:8080/echaoshi/fileUpload?query1=%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6

    log:

    19:55:40,508 INFO TestView:42 – TestView.setQuery1 = ????????????????????????


    conclusion:

    seems f:param cannot have non-english charactor?

    #20531

    Hi xuzhike,

    We believe that the problem is not with f:param, but is rather with part of the PrettyFaces parameter encoding/decoding system. Thanks for continuing to help us fix this – I’m hopeful we can find a solution soon, since this is also critical to many other users. Your testing is very valuable to us! Thank you.

    –Lincoln

    #20532

    Hey xuzhike,

    Here are a few ideas I have regarding this issue:

    1. Working on the encoding issues in PrettyFaces I figured out that Tomcat uses ISO-8859-1 as the default encoding for URIs. In my tests this broke German umlauts in query parameters. You can change the encoding by setting URIEncoding="UTF8" for the HTTP connector in your server.xml. This fixed the problems for me. See the Tomcat documentation for details:

    http://tomcat.apache.org/tomcat-6.0-doc/config/http.html

    2. I just committed some code to the PrettyFaces trunk that should fix the encoding issues for query parameters without the need to change the encoding for the connector. It would be great if you find some time to test the new snapshot in your application. Please not that my fix will only work if you let PrettyFaces inject the query parameter value by using the <query-param> element in your pretty-config.xml. I hope Hudson will deploy the new snapshot in the next minutes.

    BTW: There are two possible sources of error in all this. On the one hand the links in the HTML page could be generated incorrectly and on the other hand the injection of the values from the HTTP request into your bean may be not correct. So you could also try to manually enter an URL containing critical characters into the browser bar to isolate the problem.

    Thank you for all the testing! :-)

    #20533

    The new snapshot is now deployed to the Maven repository:

    prettyfaces-jsf2-3.1.1-20101216.064100-55.jar

    #20534

    xuzhike
    Participant

    Hey, Christian,

    I will get the latest snapshot for test.

    #20535

    xuzhike
    Participant

    setting: tomcat server.xml: URIEncoding=”UTF-8″;

    prettyfaces-jsf2-3.1.1-20101216.064100-55.jar


    test 1

    xhtml:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    <f:param name=”jsfParam” value=”上传文件2″ />上传文件

    </pretty:link>

    pretty-config.xml

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload/#{query1:testView.query1}</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    <query-param name=”jsfParam”> #{testView.jsfParam} </query-param>

    </url-mapping>

    test result:

    URL: IE/fireFox: http://localhost:8080/echaoshi/fileUpload/%20%87%F6?jsfParam=%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B62

    Bean log:

    09:40:40,656 INFO TestView:41 – TestView.setJsfParam = 上传文件2

    09:40:40,656 INFO TestView:51 – TestView.setQuery1 =

    ????

    URL incorrect, <query-param value correct for backendBean

    #20536

    xuzhike
    Participant


    test 2

    same config as test 1.

    I just manually enter an URL containing critical characters into the browser bar:

    http://localhost:8080/echaoshi/fileUpload/上传文件?jsfParam=上传文件2

    IE: the URL is not changed,

    but fireFox: http://localhost:8080/echaoshi/fileUpload/%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6?jsfParam=%C9%CF%B4%AB%CE%C4%BC%FE2

    2: backendBean

    09:51:26,218 INFO TestView:41 – TestView.setJsfParam = ????????????2

    09:51:26,218 INFO TestView:51 – TestView.setQuery1 = 上传文件

    <query-param is NOT correct

    #20537

    xuzhike
    Participant

    my purpose is to get correct value from param. not need to consider URL encoding in browser bar.

    #20538

    Very strange! In my test setup everything works now with and without changing the URIEncoding for Tomcat. I’ll prepare the test app and send you a link so you can also test it.

    By the way: Did you remove the @ManagedProperty(value="#{param.jsfParam}") annotation from you bean in the latest tests? You won’t need this if you are using <query-param> in you pretty-config.xml.

    #20539

    xuzhike
    Participant

    Hi, Christian,

    after removing @ManagedProperty(value=”#{param.jsfParam}”) and URIEncoding=”UTF-8″ in server.xml.

    pretty-config.xml

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload/#{query1:testView.query1}</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    <query-param name=”jsfParam”> #{testView.jsfParam} </query-param>

    </url-mapping>

    for english params in xhtml:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”param1″ />

    <f:param name=”jsfParam” value=”param2″ />上传文件

    </pretty:link>

    both really can be injected into Bean and URL is corret

    http://localhost:8080/echaoshi/fileUpload/param1?jsfParam=param2

    but if f:param is non-english, for my test, chinese:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    <f:param name=”jsfParam” value=”上传文件2″ />上传文件

    </pretty:link>

    both is NOT correct:

    http://localhost:8080/echaoshi/fileUpload/%20%87%F6?jsfParam=%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B62

    maybe something missing. I will try again.

    #20540

    xuzhike
    Participant

    my test conclusion:

    1:tomcat server.xml, add URIEncoding=”UTF-8″

    2:pretty-config.xml:

    <url-mapping id=”fileUpload”>

    <pattern>/fileUpload/#{query1:testView.query1}</pattern>

    <view-id>/ui/test/fileUpload.xhtml</view-id>

    <query-param name=”jsfParam”> #{testView.jsfParam} </query-param>

    </url-mapping>

    3: test file with chinese param:

    <pretty:link mappingId=”fileUpload”>

    <f:param value=”上传文件” />

    <f:param name=”jsfParam” value=”上传文件2″ />上传文件

    </pretty:link>

    result:

    URL: IE/FireFox: http://localhost:8080/echaoshi/fileUpload/%20%87%F6?jsfParam=%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B62

    backend Bean:

    15:01:08,140 INFO TestView:52 – TestView.setQuery1 = ????

    15:01:08,140 INFO TestView:42 – TestView.setJsfParam = 上传文件2

    #20541

    xuzhike
    Participant

    if something wrong in my testing or missing something/config, please tell me. I will try again.

    BTW, there is another question, hope to see your help.

    seems about JSF application, the JSF annotations(@SessionScoped, etc.) can only for BackendBean, for my test, it is TestView.

    and my TestView also contains an POJO — User.

    I hope the TestView is @RequestScoped, but its User property is @SessionScoped.

    is there other technology to achive my idea except putting user into HTTP Session?

    I remembered Seam seems to do that.

    but my application is Spring + JSF2 + Hibernate in Tomcat6.0.21.

    CDI or EJB can help?

    thx

    #20542

    Hey xuzhike,

    I can confirm that there are still problems with path parameter encoding. Just like you saw them in your conclusion.

    Here is my sample app which I used to reproduce this.

    https://github.com/chkal/prettyfaces-tests/archives/encoding

    I’ll take a look at the remaining issue at the weekend if I find some time.

    Please note that the % values in the URL are not a bug. They are just hex-encoded values of the characters from the URL. The question is if the hex characters are generated by using the correct encoding. If a browser bar shows the Unicode characters or the hex encoded characters is up to the browser. In fact the browser will ALWAYS hex-encode foreign characters when sending the request to the server, even if you manually enter them in the browser bar.

    Regarding your other question. Could you open a separate topic for this so we keep this thread on the encoding issues?

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic.

Comments are closed.