You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by khush N <kb...@gmail.com> on 2015/07/01 09:42:32 UTC

c:forEach issue in JSF 2

Hi,

I am upgrading my application from JSF 1.2 to JSF 2.

I am trying a below simple forEach tag but it not showing anything inside
the loop.

<table
    id="tab${sectionId}"
  border="0"
  cellpadding="0"
  cellspacing="0"
  width="100%"
  class="listingTable"
>
<c:forEach
var="row"
rowStatus="index"
items="#{bean.department.userActivities}"
>
            <tr>
                <td>
                    test
                 </td>
             </tr>
</c:forEach>
</table>

The value test is not showing up. Has the c:forEach implementaion changed?

I tried replacing <c:forEach> with <t:dataList> but <t:dataList> has some
other issue. It is rendering the content inside it. But if I have a
component inside <t:dataList>, I am not able to assign a backing bean value
as ID of the component. Example is as below

<table
id="tab${sectionId}"
border="0"
cellpadding="0"
cellspacing="0"
width="100%"
class="listingTable"
>
<t:dataList
var="row"
rowIndexVar="index"
value="#{bean.department.userActivities}"
>
<h:column>
<h:outputText id="#{row.activityCode}">test1</h:outputText>
</h:column>
</t:dataList>
</table>

So, with <t:dataList>. I am not able to assign backing bean property as ID
of the component. I am receiving the error
"java.lang.IllegalArgumentException: component identifier must not be a
zero-length String "

Can anyone please help me in understanding as to why the c:forEach tag is
not working. I have huge code which is using forEach tag. With upgrade, I
will have to remove every forEach if it is no more supported in JSF2 :(

Thanks in advance!

Re: c:forEach issue in JSF 2

Posted by Felipe Jaekel <fk...@gmail.com>.
Hi khush,

I had issues with c:forEach when I migrated from Mojarra to MyFaces.

It was a plain html table similar to the example in your first message, and
it worked correctly changing to ui:repeat, so I suggest you to try it.

2015-07-01 5:23 GMT-03:00 khush N <kb...@gmail.com>:

> Yep. I do have <h:form> in my page.
>
> On Wed, Jul 1, 2015 at 1:22 AM, l.penet@senat.fr <l....@senat.fr> wrote:
>
> > On 01/07/2015 10:08, khush N wrote:
> >
> >> Hi,
> >>
> >> Thanks for the quick reply!
> >>
> >> Sorry, I do not have a sample project. But c:forEach aren't working on a
> >> simplest of page for me :(
> >>
> > Did you put your code inside a <h:form> ?
> >
> >
> > Ludovic
> >
> > |
> > | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> > |
> >
> >
>

Re: c:forEach issue in JSF 2

Posted by khush N <kb...@gmail.com>.
Yep. I do have <h:form> in my page.

On Wed, Jul 1, 2015 at 1:22 AM, l.penet@senat.fr <l....@senat.fr> wrote:

> On 01/07/2015 10:08, khush N wrote:
>
>> Hi,
>>
>> Thanks for the quick reply!
>>
>> Sorry, I do not have a sample project. But c:forEach aren't working on a
>> simplest of page for me :(
>>
> Did you put your code inside a <h:form> ?
>
>
> Ludovic
>
> |
> | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> |
>
>

Re: c:forEach issue in JSF 2

Posted by "l.penet@senat.fr" <l....@senat.fr>.
On 01/07/2015 10:08, khush N wrote:
> Hi,
>
> Thanks for the quick reply!
>
> Sorry, I do not have a sample project. But c:forEach aren't working on a
> simplest of page for me :(
Did you put your code inside a <h:form> ?

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: c:forEach issue in JSF 2

Posted by khush N <kb...@gmail.com>.
Hi,

Thanks for the quick reply!

Sorry, I do not have a sample project. But c:forEach aren't working on a
simplest of page for me :(

Thanks!

On Wed, Jul 1, 2015 at 12:58 AM, l.penet@senat.fr <l....@senat.fr> wrote:

> On 01/07/2015 09:42, khush N wrote:
> [...]
>
>> Can anyone please help me in understanding as to why the c:forEach tag is
>> not working. I have huge code which is using forEach tag. With upgrade, I
>> will have to remove every forEach if it is no more supported in JSF2 :(
>> Thanks in advance!
>>
> Do you have a test project I can clone ?
>
> Ludovic
>
> |
> | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> |
>
>

Re: c:forEach issue in JSF 2

Posted by "l.penet@senat.fr" <l....@senat.fr>.
On 01/07/2015 09:42, khush N wrote:
[...]
> Can anyone please help me in understanding as to why the c:forEach tag 
> is not working. I have huge code which is using forEach tag. With 
> upgrade, I will have to remove every forEach if it is no more 
> supported in JSF2 :( Thanks in advance! 
Do you have a test project I can clone ?

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: c:forEach issue in JSF 2

Posted by "l.penet@senat.fr" <l....@senat.fr>.
On 01/07/2015 10:01, khush N wrote:
> Hi Thomas,
>
> Thank you for the quick reply!
>
> I am using JSF 2.2. As mentioned in my previous email, I have huge code
> base which is using c:forEach tag. So, it would be really great if I can
> figure out the real issue with c:forEach.
>
> If there is not other way to make c:forEach work, I will have to switch to
> ui:repeat.
ui:repeat is not an equivalent of c:forEach.

c:forEach is evaluated when building the component tree.
ui:repeat is evaluated after the component tree is build.

So, code such as :

<p:dataTable ...>
<c:forEach ...>
<p:row>
...
</p:row>
</c:forEach>
</p:dataTable>

Will generate p:row  components according to your c:forEach, which will 
be taken in account by the p:dataTable component.
But this will not work with ui:repeat.

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: c:forEach issue in JSF 2

Posted by khush N <kb...@gmail.com>.
Hi Thomas,

Thank you for the quick reply!

I am using JSF 2.2. As mentioned in my previous email, I have huge code
base which is using c:forEach tag. So, it would be really great if I can
figure out the real issue with c:forEach.

If there is not other way to make c:forEach work, I will have to switch to
ui:repeat.

Thanks!

On Wed, Jul 1, 2015 at 12:56 AM, Thomas Andraschko <
andraschko.thomas@gmail.com> wrote:

> Which version are u using? MyFaces 2.2 fixed many c:forEach issues.
>
> Maybe you should try to use ui:repeat instead c:forEach, too. You can
> google about the differences.
>
> 2015-07-01 9:42 GMT+02:00 khush N <kb...@gmail.com>:
>
> > Hi,
> >
> > I am upgrading my application from JSF 1.2 to JSF 2.
> >
> > I am trying a below simple forEach tag but it not showing anything inside
> > the loop.
> >
> > <table
> >     id="tab${sectionId}"
> >   border="0"
> >   cellpadding="0"
> >   cellspacing="0"
> >   width="100%"
> >   class="listingTable"
> > >
> > <c:forEach
> > var="row"
> > rowStatus="index"
> > items="#{bean.department.userActivities}"
> > >
> >             <tr>
> >                 <td>
> >                     test
> >                  </td>
> >              </tr>
> > </c:forEach>
> > </table>
> >
> > The value test is not showing up. Has the c:forEach implementaion
> changed?
> >
> > I tried replacing <c:forEach> with <t:dataList> but <t:dataList> has some
> > other issue. It is rendering the content inside it. But if I have a
> > component inside <t:dataList>, I am not able to assign a backing bean
> value
> > as ID of the component. Example is as below
> >
> > <table
> > id="tab${sectionId}"
> > border="0"
> > cellpadding="0"
> > cellspacing="0"
> > width="100%"
> > class="listingTable"
> > >
> > <t:dataList
> > var="row"
> > rowIndexVar="index"
> > value="#{bean.department.userActivities}"
> > >
> > <h:column>
> > <h:outputText id="#{row.activityCode}">test1</h:outputText>
> > </h:column>
> > </t:dataList>
> > </table>
> >
> > So, with <t:dataList>. I am not able to assign backing bean property as
> ID
> > of the component. I am receiving the error
> > "java.lang.IllegalArgumentException: component identifier must not be a
> > zero-length String "
> >
> > Can anyone please help me in understanding as to why the c:forEach tag is
> > not working. I have huge code which is using forEach tag. With upgrade, I
> > will have to remove every forEach if it is no more supported in JSF2 :(
> >
> > Thanks in advance!
> >
>

Re: c:forEach issue in JSF 2

Posted by Thomas Andraschko <an...@gmail.com>.
Which version are u using? MyFaces 2.2 fixed many c:forEach issues.

Maybe you should try to use ui:repeat instead c:forEach, too. You can
google about the differences.

2015-07-01 9:42 GMT+02:00 khush N <kb...@gmail.com>:

> Hi,
>
> I am upgrading my application from JSF 1.2 to JSF 2.
>
> I am trying a below simple forEach tag but it not showing anything inside
> the loop.
>
> <table
>     id="tab${sectionId}"
>   border="0"
>   cellpadding="0"
>   cellspacing="0"
>   width="100%"
>   class="listingTable"
> >
> <c:forEach
> var="row"
> rowStatus="index"
> items="#{bean.department.userActivities}"
> >
>             <tr>
>                 <td>
>                     test
>                  </td>
>              </tr>
> </c:forEach>
> </table>
>
> The value test is not showing up. Has the c:forEach implementaion changed?
>
> I tried replacing <c:forEach> with <t:dataList> but <t:dataList> has some
> other issue. It is rendering the content inside it. But if I have a
> component inside <t:dataList>, I am not able to assign a backing bean value
> as ID of the component. Example is as below
>
> <table
> id="tab${sectionId}"
> border="0"
> cellpadding="0"
> cellspacing="0"
> width="100%"
> class="listingTable"
> >
> <t:dataList
> var="row"
> rowIndexVar="index"
> value="#{bean.department.userActivities}"
> >
> <h:column>
> <h:outputText id="#{row.activityCode}">test1</h:outputText>
> </h:column>
> </t:dataList>
> </table>
>
> So, with <t:dataList>. I am not able to assign backing bean property as ID
> of the component. I am receiving the error
> "java.lang.IllegalArgumentException: component identifier must not be a
> zero-length String "
>
> Can anyone please help me in understanding as to why the c:forEach tag is
> not working. I have huge code which is using forEach tag. With upgrade, I
> will have to remove every forEach if it is no more supported in JSF2 :(
>
> Thanks in advance!
>