0

I am looping a list containing strings in foreach, so in every iteration the variable in foreach loop should be passed as a parameter to a bean method written inside the foreach loop. I searched many sites but everywhere I am finding solution that bean method cannot be executed without commandbutton or link. Is there any solution to execute bean method without any commandbutton or link.

<c:forEach var="name" items="#{bean.stringList}" 
 varStatus="loopCounter">

 <!--I have to execute the method here passing "name" as parameter-->

 </c:forEach>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

3

Since EL 2.2 you can invoke non-getter methods with arguments. So you could use:

<c:forEach var="name" items="#{bean.stringList}" 
           varStatus="loopCounter">
    <c:set var="dummy" value="#{bean.yourMethod(name)}" />
</c:forEach>

However, you are most likely are trying to solve something here that can be done in more elegant ways like a PhaseListener, a @PostConstruct method, a f:viewAction, etc.

See also

Community
  • 1
  • 1
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102