Allow List<X> or X[] as type for @Param, link, outputLink, viewParam... #223

Closed
kalgon opened this Issue Mar 16, 2016 · 8 comments

Projects

None yet

3 participants

@kalgon
kalgon commented Mar 16, 2016

It seems that multivalue parameters are not supported in JSF (like in /compare.xhtml?id=11&id=22&id=33) so maybe omnifaces could fill the gap there.

I would like to have something like this in my bean (given that I already have a UUIDConverter somewhere):

@Inject @Param(name = "uuid") List<UUID> uuids; // or UUID[]

And be able to declare the following viewParam when not using @Param:

<o:viewParam name="uuid" value="#{myBean.uuids}" />

And also be able to use those values for links:

<h:link outcome="compare.xhtml" value="compare">
    <o:param name="uuid" value="#{myBean.uuids}" />
</h:link>

Is it possible?

@BalusC
Member
BalusC commented Mar 16, 2016

I once looked at it for <f|o:viewParam>, but it really isn't trivial. It basically requires a whole new <o:viewParams> component. For @Param, it looks like it should work, certainly since it has a dynamic producer.

@arjantijms
Member

We indeed looked at the viewParam one before. If I'm not mistaken very early EG discussions when viewParam was just introduced already asked for this as well, but the discussion was delayed for (back then) JSF 2.1.

@kalgon
kalgon commented Mar 17, 2016

That's interesting. I find it rather strange that this was not implemented yet as ExternalContext.getRequestParameterValuesMap(), ViewHandler.getBookmarkableURL and ViewHandler.getRedirectURL all make use of a Map<String, List<String>|String[]> for parameters. I hope I won't have to wait until JSF 2.4 to be able to use multiple parameters.

What would be the correct way to generate links with multi-valued parameters? I guess something like that would not work:

<h:link ...>
    <ui:repeat var="uuid" values="#{myBean.uuids}">
        <f:param name="uuid" value="#{uuid}" />
    </ui:repeat>
</h:link>

So I suppose, like <f|o:viewParams>, some sort of <f|o:params> would be needed.

Alternatively, instead of creating new tags, the current ones could get a new cardinality attribute single|multiple.

@BalusC
Member
BalusC commented Mar 17, 2016

With <c:forEach> it should work. Those have to be created during view build time as the renderer of <h:link> basically inspects the component's children and this won't work with <ui:repeat> as it's basically also a component.

@arjantijms
Member

I hope I won't have to wait until JSF 2.4 to be able to use multiple parameters.

I agree, this is something that's at least conceptually quite basic. As BalusC said, technically it's a different story.

The problem is that JSF (and the whole of Java EE specs) has a really serious resource issue at the moment, meaning there are very few people available who all have very few hours to do anything. I'd love to look at this, but I've also got a mountain of work to do for JSR 375 (I'll be happy if I succeed in getting only a quarter of that done).

That said, definitely keeping this one in mind. Thanks for remembering us.

@BalusC BalusC referenced this issue May 23, 2016
@BalusC BalusC #233: add support for multi-valued params in @Param via typed arrays
(and refactored RequestParameterProducer ParamValue a bit)
fa1232d
@BalusC
Member
BalusC commented May 23, 2016 edited

As per today's latest 2.4-SNAPSHOT, @Param now supports multi-valued params via typed arrays.

@Inject @Param(name="foo")
private String[] foos;

Generic collections like List<String> are not trivial to implement (qualifiers needed), perhaps later. Conversion/validation is also supported on multi-valued params, so you can use UUID[] with a converter. For bean validation, the entire array value will be passed as argument for validation. For JSF native validation, every individual value will be validated.

I will look at <o:param> later.

@BalusC BalusC added a commit that referenced this issue May 26, 2016
@BalusC BalusC #223: fix NPE 11db77c
@BalusC
Member
BalusC commented Jun 8, 2016

<o:param> case is not trivial. Technically, you'd need during preRenderView programmatically create new Param components in the view when the value type turns out to be an array. This is tricky with postbacks and state saving and a mutable model (and also JSF incompatibility to support arrays/collections in UIParameter). I'll leave it for now. In the meanwhile, just use <c:forEach><f|o:param>.

@BalusC BalusC closed this Jun 8, 2016
@BalusC
Member
BalusC commented Jun 8, 2016 edited

As of now, List<T> is also supported instead of only T[].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment