You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Andrew Robinson <an...@gmail.com> on 2007/06/15 01:05:44 UTC

[sandbox] new component idea

I am working on the code for a very simple component, but wanted to
see if there is feedback before finishing it up.

The component is inspired by the JSTL choose but is geared for JSF and
is more robust. I thought this would be helpful when a lot of facelets
developers complain about the facelets implementation of choose due to
render vs. compile time evaluation.

<s:choose type="string" value="object" />

type := index|count (default: count)
value := (type == index):  list of numbers that correspond to children
indexes (negatives allowed). Default: render all
  (type == count): integer representing max number of components to
render. Default: render first

Examples:
<s:choose>
  <h:outputText rendered="false" value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
</s:choose>
Renders: b

<s:choose value="2">
  <h:outputText rendered="false" value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
  <h:outputText value="d" />
</s:choose>
Renders: b c

<s:choose value="5">
  <h:outputText rendered="false" value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
  <h:outputText value="d" />
</s:choose>
Renders: b c d

<s:choose type="index" value="0,-1">
  <h:outputText value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
  <h:outputText value="d" />
</s:choose>
Renders: a d

<s:choose type="index" value="0,-1">
  <h:outputText value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
  <h:outputText value="d" />
</s:choose>
Renders: a d

<s:choose type="index" value="5">
  <h:outputText value="a" />
  <h:outputText value="b" />
  <h:outputText value="c" />
  <h:outputText value="d" />
</s:choose>
Throws index out of bounds exception

If index, value can be tied to one of:
Collection of Number or Object
int[]
Object[] of Number or Object
String or Object (comma-separated toString())

If Object and not a Number, Integer.parseInt(obj.toString()) is used.

The default setting is really the most useful (type=count, value=1),
which is simply render only the first child component that
isRendered() returns true.


Any feedback?
-Andrew

Re: [sandbox] new component idea

Posted by Mike Kienenberger <mk...@gmail.com>.
Martin,

I think the goal is to simplify page code when you have conditional rendering.

I know that I have areas on my page that look like this:

<component rendered="#{value eq a}">
<component rendered="#{value eq b}">
<component rendered="#{value eq c}">
<component rendered="#{value eq d}">
<component rendered="#{value ne a and value ne b and value ne c and
value ne d}">

And rarely is the conditional as easy as what you see above, so it
becomes very difficult to read and maintain.



On 6/15/07, Martin Marinschek <ma...@gmail.com> wrote:
> Hi Andrew,
>
> so this does the same as c:choose (sorry for my ignorance, but I don't
> know the JSTL too well)?
>
> Can you give us an example where this is useful in the wild?
>
> regards,
>
> Martin
>
> On 6/15/07, Andrew Robinson <an...@gmail.com> wrote:
> > I am working on the code for a very simple component, but wanted to
> > see if there is feedback before finishing it up.
> >
> > The component is inspired by the JSTL choose but is geared for JSF and
> > is more robust. I thought this would be helpful when a lot of facelets
> > developers complain about the facelets implementation of choose due to
> > render vs. compile time evaluation.
> >
> > <s:choose type="string" value="object" />
> >
> > type := index|count (default: count)
> > value := (type == index):  list of numbers that correspond to children
> > indexes (negatives allowed). Default: render all
> >   (type == count): integer representing max number of components to
> > render. Default: render first
> >
> > Examples:
> > <s:choose>
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> > </s:choose>
> > Renders: b
> >
> > <s:choose value="2">
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: b c
> >
> > <s:choose value="5">
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: b c d
> >
> > <s:choose type="index" value="0,-1">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: a d
> >
> > <s:choose type="index" value="0,-1">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: a d
> >
> > <s:choose type="index" value="5">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Throws index out of bounds exception
> >
> > If index, value can be tied to one of:
> > Collection of Number or Object
> > int[]
> > Object[] of Number or Object
> > String or Object (comma-separated toString())
> >
> > If Object and not a Number, Integer.parseInt(obj.toString()) is used.
> >
> > The default setting is really the most useful (type=count, value=1),
> > which is simply render only the first child component that
> > isRendered() returns true.
> >
> >
> > Any feedback?
> > -Andrew
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>

Re: [sandbox] new component idea

Posted by Martin Marinschek <ma...@gmail.com>.
Hi Andrew,

so this does the same as c:choose (sorry for my ignorance, but I don't
know the JSTL too well)?

Can you give us an example where this is useful in the wild?

regards,

Martin

On 6/15/07, Andrew Robinson <an...@gmail.com> wrote:
> I am working on the code for a very simple component, but wanted to
> see if there is feedback before finishing it up.
>
> The component is inspired by the JSTL choose but is geared for JSF and
> is more robust. I thought this would be helpful when a lot of facelets
> developers complain about the facelets implementation of choose due to
> render vs. compile time evaluation.
>
> <s:choose type="string" value="object" />
>
> type := index|count (default: count)
> value := (type == index):  list of numbers that correspond to children
> indexes (negatives allowed). Default: render all
>   (type == count): integer representing max number of components to
> render. Default: render first
>
> Examples:
> <s:choose>
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
> </s:choose>
> Renders: b
>
> <s:choose value="2">
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: b c
>
> <s:choose value="5">
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: b c d
>
> <s:choose type="index" value="0,-1">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: a d
>
> <s:choose type="index" value="0,-1">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: a d
>
> <s:choose type="index" value="5">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Throws index out of bounds exception
>
> If index, value can be tied to one of:
> Collection of Number or Object
> int[]
> Object[] of Number or Object
> String or Object (comma-separated toString())
>
> If Object and not a Number, Integer.parseInt(obj.toString()) is used.
>
> The default setting is really the most useful (type=count, value=1),
> which is simply render only the first child component that
> isRendered() returns true.
>
>
> Any feedback?
> -Andrew
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: [sandbox] new component idea

Posted by Mike Kienenberger <mk...@gmail.com>.
Here's an example of the c:choose syntax for comparison, from
http://www.awprofessional.com/articles/article.asp?p=102219&seqNum=9&rl=1

<c:choose>
  <c:when test="${param.whichPage == 'red'}">
    <jsp:forward page="red.jsp"/>
  </c:when>

  <c:when test="${param.whichPage == 'green'}">
    <jsp:forward page="blue.jsp"/>
  </c:when>

  <c:when test="${param.whichPage == 'blue'}">
    <jsp:forward page="blue.jsp"/>
  </c:when>

  <c:otherwise>
    <jsp:forward page="select_page.jsp"/>
  </c:otherwise>
</c:choose>


On 6/15/07, Mike Kienenberger <mk...@gmail.com> wrote:
> Andrew,
>
> I'm not an expert on c:choose, but from the one time I tried to use
> it, the syntax and functionality seemed quite different.
>
> If there's going to be a sandbox:choose component, I would hope that
> it would be the render-time equivalent of the c:choose build-time tag.
>
> Since I don't think that's the case, I'd recommend using a different
> name for this component.
>
> Otherwise, it's going to cause a great deal of unnecessary confusion.
>
> How about "chooseRendered"?
>
>
> On 6/14/07, Andrew Robinson <an...@gmail.com> wrote:
> > I am working on the code for a very simple component, but wanted to
> > see if there is feedback before finishing it up.
> >
> > The component is inspired by the JSTL choose but is geared for JSF and
> > is more robust. I thought this would be helpful when a lot of facelets
> > developers complain about the facelets implementation of choose due to
> > render vs. compile time evaluation.
> >
> > <s:choose type="string" value="object" />
> >
> > type := index|count (default: count)
> > value := (type == index):  list of numbers that correspond to children
> > indexes (negatives allowed). Default: render all
> >   (type == count): integer representing max number of components to
> > render. Default: render first
> >
> > Examples:
> > <s:choose>
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> > </s:choose>
> > Renders: b
> >
> > <s:choose value="2">
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: b c
> >
> > <s:choose value="5">
> >   <h:outputText rendered="false" value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: b c d
> >
> > <s:choose type="index" value="0,-1">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: a d
> >
> > <s:choose type="index" value="0,-1">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Renders: a d
> >
> > <s:choose type="index" value="5">
> >   <h:outputText value="a" />
> >   <h:outputText value="b" />
> >   <h:outputText value="c" />
> >   <h:outputText value="d" />
> > </s:choose>
> > Throws index out of bounds exception
> >
> > If index, value can be tied to one of:
> > Collection of Number or Object
> > int[]
> > Object[] of Number or Object
> > String or Object (comma-separated toString())
> >
> > If Object and not a Number, Integer.parseInt(obj.toString()) is used.
> >
> > The default setting is really the most useful (type=count, value=1),
> > which is simply render only the first child component that
> > isRendered() returns true.
> >
> >
> > Any feedback?
> > -Andrew
> >
>

Re: [sandbox] new component idea

Posted by Mike Kienenberger <mk...@gmail.com>.
Andrew,

I'm not an expert on c:choose, but from the one time I tried to use
it, the syntax and functionality seemed quite different.

If there's going to be a sandbox:choose component, I would hope that
it would be the render-time equivalent of the c:choose build-time tag.

Since I don't think that's the case, I'd recommend using a different
name for this component.

Otherwise, it's going to cause a great deal of unnecessary confusion.

How about "chooseRendered"?


On 6/14/07, Andrew Robinson <an...@gmail.com> wrote:
> I am working on the code for a very simple component, but wanted to
> see if there is feedback before finishing it up.
>
> The component is inspired by the JSTL choose but is geared for JSF and
> is more robust. I thought this would be helpful when a lot of facelets
> developers complain about the facelets implementation of choose due to
> render vs. compile time evaluation.
>
> <s:choose type="string" value="object" />
>
> type := index|count (default: count)
> value := (type == index):  list of numbers that correspond to children
> indexes (negatives allowed). Default: render all
>   (type == count): integer representing max number of components to
> render. Default: render first
>
> Examples:
> <s:choose>
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
> </s:choose>
> Renders: b
>
> <s:choose value="2">
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: b c
>
> <s:choose value="5">
>   <h:outputText rendered="false" value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: b c d
>
> <s:choose type="index" value="0,-1">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: a d
>
> <s:choose type="index" value="0,-1">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Renders: a d
>
> <s:choose type="index" value="5">
>   <h:outputText value="a" />
>   <h:outputText value="b" />
>   <h:outputText value="c" />
>   <h:outputText value="d" />
> </s:choose>
> Throws index out of bounds exception
>
> If index, value can be tied to one of:
> Collection of Number or Object
> int[]
> Object[] of Number or Object
> String or Object (comma-separated toString())
>
> If Object and not a Number, Integer.parseInt(obj.toString()) is used.
>
> The default setting is really the most useful (type=count, value=1),
> which is simply render only the first child component that
> isRendered() returns true.
>
>
> Any feedback?
> -Andrew
>