9

I'm using dynamically created links:

          <h:link outcome="/page" value="#{name}">
            <f:param name="name" value="#{name}"/>
          </h:link>

I would like to attach custom converter for f:param to remove spaces from #{name} etc. But there is no converter property in f:param.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
karolkpl
  • 2,189
  • 10
  • 39
  • 60

2 Answers2

16

A Converter is intented to convert from submitted String request parameter values to complex objects and vice versa in input fields. However, the <f:param> is pure output only and it will always call toString() on the value. It doesn't support a Converter.

Your cleanest and best bet is to create a custom EL function, so that you ultimately end up like:

<f:param name="name" value="#{util:prettyUrl(name)}"/>

Update: the JSF utility library OmniFaces has since version 1.4 (March 2013) a <o:param> component which extends the <f:param> with support for a fullworthy JSF converter, exactly like as you'd use in <h:outputText converter>.

<h:link outcome="/page" value="#{name}">
    <o:param name="name" value="#{name}" converter="somePrettyURLConverter" />
</h:link>

See also the showcase.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    I had the same question and I am not really satisfied with such a solution. On the receiving site `f:viewParam` is used to retrieve the Object using a converter. So it would be straight forward to use a converter with `f:param` too. Since that logic is already implemented in the converter. Now that logic is also present in the view and if i change the param maybe from name to id I have to change the converter and the site. The custom el function would be a workaround, at least if the initial converter would also use it. – djmj Aug 24 '12 at 19:08
  • 2
    added the `o:param` tag to his omnifaces library and it works very well. – djmj Mar 05 '13 at 15:09
1

what if you do something like this?

<f:param name="name" value="#{name.replace(' ', '')}" />

Isn't this working?

Or you want for all < f:param ... ??

Regards

Alex
  • 2,126
  • 3
  • 25
  • 47
  • Actually, the conversion is more complex, so I need java function. For now I use managed bean functions `` – karolkpl Oct 14 '11 at 13:15
  • 1
    @mm1: I don't think you have another solution.. It doesn't make sense... what you want is to replace the return of #{name} when is accessed by – Alex Oct 14 '11 at 13:50