2

Strange one this. I have a tag in my JSF page which contains a parameter that contains a + sign. When the resulting hyperlink is clicked the URL converts the + sign to a space, as this is how spaces in URLs are represented.

Is there any way of encoding this parameter to display "%2b" (which is the urlencoded string) instead of +? I am using JSF 1.2

<hx:requestLink styleClass="requestLink" id="link31"
    action="#{sellingMarginBean.changeView}">
    <h:outputText styleClass="outputText" id="text81"
        value="#{varsummaryDataList.tier.description}"></h:outputText>  
    <f:param
        value="#{varsummaryDataList.tier.tierCode}"
        name="tierCode" id="param51"></f:param>
</hx:requestLink>

If I change the value of tierCode to replace any '+' with '%2b' before putting out to the screen this works, but it's a hack at best as it means creating a custom method on my Tier domain object or cycling through summaryDataList and performing the replace.

Thanks in advance

Steve

Aritz
  • 30,971
  • 16
  • 136
  • 217
Steve W
  • 97
  • 7

1 Answers1

2

According to this post by BalusC:

JSP/Servlet request: during request processing an average application server will by default use the ISO 8859-1 character encoding to URL-decode the request parameters. You need to force the character encoding to UTF-8 yourself. First this: "URL encoding" must not to be confused with "character encoding". URL encoding is merely a conversion of characters to their numeral representations in the %xx format, so that special characters can be passed through URL without any problems. The client will URL-encode the characters before sending them to the server. The server should URL-decode the characters using the same character encoding.

So probably your client and server are not using the same URL(URI)-encoding. Your best bet is to force the server itself to use UTF-8 encoding. That depends on what server you're using.

You could also use JSTL's fn:replace for your parameter, as an alternative but more "hacky" solution. Remember to define the JSTL taglib in your namespace set (xmlns:fn="http://java.sun.com/jsp/jstl/functions").

<f:param
    value="#{fn:replace(varsummaryDataList.tier.tierCode, '+', '%2b'}"
    name="tierCode" id="param51" />

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Are + signs encoded differently though? They're basic ASCII. – Evan Knowles May 21 '14 at 09:06
  • @EvanKnowles, in fact, there are, but they remain in conflict with HTTP request keywords. That's why they should be encoded in a different way. – Aritz May 21 '14 at 09:09