How to pass method arguments to an ActionListener?

后端 未结 1 1052
耶瑟儿~
耶瑟儿~ 2020-12-20 22:42

I\'m creating a dynamically generated menu. In the database, I have stored the directory (String) of each submenu and stored in an ArrayList in the

相关标签:
1条回答
  • 2020-12-20 22:53

    Use action, not actionListener. The actionListener must be bound to a method which takes ActionEvent as the sole argument, no excuses. Also, an actionListener isn't intented to invoke actions, but to listen on actions (so that you can log it or do some preprocessing task or whatever).

    <c:forEach items="#{controlWeb.algorithms}" var="alg">
        <h:form>
            <h:commandLink action="#{controlWeb.setContent(alg.algorithm)}" value="About"/>
        </h:form>
    </c:forEach>
    

    Note that passing arguments in EL is only supported since EL 2.2 which is shipped along Servlet 3.0 / Java EE 6. You need to make sure that you're targeting a Servlet 3.0 compatible container with a Servlet 3.0 compatible web.xml.

    See also:

    • Differences between action and actionListener
    • How to call a method with a parameter in JSF
    0 讨论(0)
提交回复
热议问题