Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:37:35+00:00 2026-06-15T15:37:35+00:00

Is it possible to use <c:if> inside <a4j:repeat> ? I need to render a

  • 0

Is it possible to use <c:if> inside <a4j:repeat>?

I need to render a <br /> each 4 elements. I tried the following approach:

<a4j:repeat value="#{MBean.sucursal.events}" var="item" rowKeyVar="idx" >   
   <h:outputText value="#{item.eventDescription}" id="item1" />
   <c: if test=#{idx % 4 == 0}>
       <br />
   </c:if>
</a4j:repeat>

However, it does not render the <br /> elements at all.

How can I achieve the requirement anyway?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:37:35+00:00Added an answer on June 15, 2026 at 3:37 pm

    Note: I’ll ignore the careless formulation of the code which causes that it wouldn’t compile/run properly at all. There’s a space in <c :if> and the quotes are missing from the <c:if test> attribute. In future questions please pay a bit more attention to the properness of the code snippets you post, otherwise you’ll only get invalid answers due to those red herrings.


    Coming back to your concrete problem, this construct will indeed fail. The <c:if> runs during view build time (when the JSF component tree is about to be populated based on Facelets/JSP files), while the <a4j:repeat> runs during view render time (when the HTML code is about to be generated based on the JSF component tree). So, at the moment the <c:if> runs, #{idx} does not exist in the scope at all and always evaluates to null.

    There are basically 2 solutions:

    1. Use <c:forEach> instead of <a4j:repeat> to iterate over the items. It runs during view build time, so it’ll run “in sync” with <c:if>.

      <c:forEach items="#{MBean.sucursal.events}" var="item" varStatus="loop">   
         <h:outputText value="#{item.eventDescription}" id="item#{loop.index}" />
         <c:if test="#{loop.index % 4 == 0}">
             <br />
         </c:if>
      </c:forEach>
      

      (note that I changed the <h:outputText id> as well, otherwise you end up with duplicate component ID errors or malformed HTML; feel free to omit the id attribute altogether, JSF will autogenerate proper one)

    2. Use JSF component’s rendered attribute instead of <c:if> to conditionally render HTML. It runs during view render time, so it’ll run “in sync” with <a4j:repeat>.

      <a4j:repeat value="#{MBean.sucursal.events}" var="item" rowKeyVar="idx">   
         <h:outputText value="#{item.eventDescription}" id="item1" />
         <h:panelGroup rendered="#{idx % 4 == 0}">
             <br />
         </h:panelGroup>
      </a4j:repeat>
      

    See also:

    • JSTL in JSF2 Facelets… makes sense?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is possible to use JavaScript inside a view of a Eclipse Plugin?
Is is possible to use a CASE statement inside an IN clause? This is
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
I am trying to use a ViewPager inside a custom Dialog... is it possible
Possible Duplicate: Can we use any other TAG inside <ul> along with <li>? Or
Now I was use NSLog() for debugging inside IDE, Is it possible to styling
I need a control having these features: It should be possible use it in
Is it possible to use spring inside war bundle on felix? I use spring
is it possible to use getitem inside a method, ie Class MyClass: @property def
Is it at all possible to use Pygments inside of wxPython to provide syntax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.