Hi everybody,


I tried to do a post about this issue in early august, but didn't get
any replies and I wonder if summer-vacation might have caused this. :)



I build up a form programmatically with different inputs, and the bean
behind it is in session scope. My problem is that after I submit the
form, and the view is restored, all the submitted values are displayed
with what seems to be UTF-8 encoding or url-encoding of some sort.



Let's say I have an input-text where the user should enter e-mail
address:
Before I submit the value is like '[EMAIL PROTECTED]". After submitting
and the page is reloaded the value displayed is 'myemail%40myisp.com'.
And a String like "Your item was successfully created" becomes
"Your+item+was+successfully+created".



I've been working with myfaces 1.1 for quite some time, and have never
experienced this. I started to dive into the problem, and I believe I
can conclude with the following:



If you use componentBindings and set the value of that component to a
"static" value, it works. But if you use componentBindings AND
valueExpression it doesn't.



To give a concrete example:



A java class Test which is in session scope, holds a property message of
type String public class Test {

                private String message = "My test for encoding issues.
Emails are written like [EMAIL PROTECTED] ";



                public String getMessage()

                {

                                return message;

                }

                public void setMessage(String message)

                {

                                this.message = message;

                }

}



If I have a jsp and use an h:outputText directly with a valueExpression,
it works - the message comes out just fine:

<h:panelGrid id="testPanel">



                <h:outputText value="#{test.message}"></h:outputText>



</h:panelGrid>



But if I create a componentBinding for this outputText instead, AND fill
it up with valueExpression, I get the problem:



<h:panelGrid id="testPanel">

                <h:outputText
binding="#{test.htmlOutputText}"></h:outputText>

</h:panelGrid>



public class Test

{

                public HtmlOutputText getHtmlOutputText()

                {

                                if(htmlOutputText == null)

                                {

                                                htmlOutputText = new
HtmlOutputText();


htmlOutputText.setId("testText");

                                                FacesContext context =

FacesContext.getCurrentInstance();

                                                ValueExpression vex =

context.getApplication().getExpressionFactory().createValueExpression(co

ntext.getELContext(),
"#{test.message}",

String[].class);


htmlOutputText.setValueExpression("value", vex);

                                }

                                return htmlOutputText;

                }

}



If I use a componentBinding, but set the value directly it the
htmlOutputText, it works:



                public HtmlOutputText getHtmlOutputText()

                {

                                if(htmlOutputText == null)

                                {

                                                htmlOutputText = new
HtmlOutputText();


htmlOutputText.setId("testText");


htmlOutputText.setValue("My test for encoding issues. Emails are written
like [EMAIL PROTECTED]");

                                }

                                return htmlOutputText;

                }



Can someone explain this? An hopefully provide a solution as well? :)



I use myfaces-1.2.3. In the web.xml I have the following

encoding-mapping:



                <locale-encoding-mapping-list>

                                <locale-encoding-mapping>

                                                <locale>en</locale>


<encoding>UTF-8</encoding>

                                </locale-encoding-mapping>

                                <locale-encoding-mapping>

                                                <locale>no</locale>


<encoding>UTF-8</encoding>

                                </locale-encoding-mapping>

                </locale-encoding-mapping-list>



Best regards,



Eivind Roennevik

Reply via email to