1

I have a URL that looks like
http://server/context/page.jsf?param1=value1#state=statename::stateparam=value2

Is there anyway to the take this URL and encode the components (the two values) using h:outputLink?

I've tried

<h:outputLink value="page.jsf">
    <f:param name="param1" value="#{servervalue1}#state=statename::stateparam=#{servervalue2}"/>
    <h:outputText value="#{linkname}"/>
</h:outputLink>

But it encodes the the state section of the URL so it no longer works.

James McMahon
  • 48,506
  • 64
  • 207
  • 283

1 Answers1

2

That's not possible. Best what you can do is to create a custom EL function which invokes URLEncoder#encode() like follows:

public static String urlEncode(String value) {
    return URLEncoder.encode(value, "UTF-8");
}

and then use it as follows:

<h:outputLink value="page.jsf?param1=#{util:urlEncode(value1)}#state=statename::stateparam=#{util:urlEncode(value2)}">
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks, so there is no built in JSTL function to encoding URLs? – James McMahon Mar 04 '11 at 20:42
  • 1
    No, I would otherwise have suggested this :) There's however an ugly hack/workaround possible, see also [this answer](http://stackoverflow.com/questions/4952659/how-to-uri-encode-a-string-in-jsp/4952889#4952889). – BalusC Mar 04 '11 at 21:14