MyFaces Core
  1. MyFaces Core
  2. MYFACES-218

Javascript alert Should not display UnicodeEncoder dispose result

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0.9m9
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Tomcat 5.5.7,myfaces 1.0.9 rc3

      Description

      When use core-jsf validator component(a client validator tag based on commons-validator),I found output warn message is disposed by UnicodeEncoder,so,when validateForm occured,The prompt message is not what I want,but as sequence &#2598 and so on.Could MyFaces provide a choice for normal output as fmt:message or others jsp output?

        Activity

        Hide
        sean schofield added a comment -

        Closing this out since a javascript solution has been provided by the reporter.

        Show
        sean schofield added a comment - Closing this out since a javascript solution has been provided by the reporter.
        Hide
        wuhaixing added a comment -

        After all,the client validator alert UnicodeEncode character problem resolved with a client solution.I composite a UnicodeDecode javascript function,and add it to the validator-rules.xml,then embeded it in every alert function.
        The code is something like this:
        // Decode UnicodeEncoded character
        function UnicodeDecode(encoded)
        {
        // Replace &# with '%'
        // Replace 00000 with equivalent ffff character
        var ta=new Array();

        var DECCHARS = "0123456789";
        var i = 0;
        var j = 0;
        while (i < encoded.length) {
        var ch = encoded.charAt;
        if (ch == "&" || ch == ";")

        { i++; }

        else if (ch == "#") {
        i++;
        if (i < (encoded.length-5)
        && DECCHARS.indexOf(encoded.charAt(i+1)) != -1
        && DECCHARS.indexOf(encoded.charAt(i+2)) != -1
        && DECCHARS.indexOf(encoded.charAt(i+3)) != -1
        && DECCHARS.indexOf(encoded.charAt(i+4)) != -1 )

        { ta[j++] = encoded.substr(i,5); i += 5; }

        } else

        { ta[j++] = encoded.charCodeAt(i); i++; }

        } // while
        return ""eval("String.fromCharCode("+ta")");
        }

        and embeded it in validator* function like this:
        alert(UnicodeDecode(fields.join('\n')));

        Show
        wuhaixing added a comment - After all,the client validator alert UnicodeEncode character problem resolved with a client solution.I composite a UnicodeDecode javascript function,and add it to the validator-rules.xml,then embeded it in every alert function. The code is something like this: // Decode UnicodeEncoded character function UnicodeDecode(encoded) { // Replace &# with '%' // Replace 00000 with equivalent ffff character var ta=new Array(); var DECCHARS = "0123456789"; var i = 0; var j = 0; while (i < encoded.length) { var ch = encoded.charAt ; if (ch == "&" || ch == ";") { i++; } else if (ch == "#") { i++; if (i < (encoded.length-5) && DECCHARS.indexOf(encoded.charAt(i+1)) != -1 && DECCHARS.indexOf(encoded.charAt(i+2)) != -1 && DECCHARS.indexOf(encoded.charAt(i+3)) != -1 && DECCHARS.indexOf(encoded.charAt(i+4)) != -1 ) { ta[j++] = encoded.substr(i,5); i += 5; } } else { ta[j++] = encoded.charCodeAt(i); i++; } } // while return "" eval("String.fromCharCode("+ta ")"); } and embeded it in validator* function like this: alert(UnicodeDecode(fields.join('\n')));
        Hide
        Martin Kočí added a comment -

        I have same problem with custom messages renderer with optional layout "alert" which is rendering messages in javascript alert.

        Problem is in HtmlResponseWriterImpl.writeText(Object text, String componentPropertyName) where following is used:
        if (isScriptOrStyle())

        { _writer.write(UnicodeEncoder.encode(strValue, false, false)); }

        else

        { _writer.write(HTMLEncoder.encode(strValue, false, false)); }

        isScriptOrStyle() returns true when start tag is SCRIPT and so unicode escaping is used.

        Is there any way to use something like writer.write("some text", null, dontEscape) ?

        Show
        Martin Kočí added a comment - I have same problem with custom messages renderer with optional layout "alert" which is rendering messages in javascript alert. Problem is in HtmlResponseWriterImpl.writeText(Object text, String componentPropertyName) where following is used: if (isScriptOrStyle()) { _writer.write(UnicodeEncoder.encode(strValue, false, false)); } else { _writer.write(HTMLEncoder.encode(strValue, false, false)); } isScriptOrStyle() returns true when start tag is SCRIPT and so unicode escaping is used. Is there any way to use something like writer.write("some text", null, dontEscape) ?

          People

          • Assignee:
            Unassigned
            Reporter:
            wuhaixing
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development