New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Mar 16, 2016

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@arjantijms

arjantijms Mar 16, 2016

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.

Member

arjantijms commented Mar 16, 2016

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

This comment has been minimized.

Show comment
Hide comment
@kalgon

kalgon 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.

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Mar 17, 2016

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@arjantijms

arjantijms Mar 17, 2016

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.

Member

arjantijms commented Mar 17, 2016

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 referenced this issue May 23, 2016

#233: add support for multi-valued params in @param via typed arrays
(and refactored RequestParameterProducer ParamValue a bit)
@BalusC

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC May 23, 2016

Member

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.

Member

BalusC commented May 23, 2016

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jun 8, 2016

Member

<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>.

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

This comment has been minimized.

Show comment
Hide comment
@BalusC

BalusC Jun 8, 2016

Member

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

Member

BalusC commented Jun 8, 2016

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