This discussion is archived
7 Replies Latest reply: Nov 9, 2012 7:12 PM by 859967 RSS

expression language and backing bean invocation

859967 Newbie
Currently Being Moderated
Hi,

I have a bean method and it supposes to be called when a command link is clicked. But the fact , there is only a form submit and the method isn't called at all.
      <c:forEach var="i" begin="1" end="${myTree.currentCategorySize()}" >                   
            <h:commandLink value="#{bundle.LabelActionDelete}" action="#{myTree.handleDeleteCategory(i-1)}" />
      </c:forEach>
And if i change the value of "end" property to a numeric constant, it works (the method handleDeleteCategory() is called.
      <c:forEach var="i" begin="1" end="3" >                   
            <h:commandLink value="#{bundle.LabelActionDelete}" action="#{myTree.handleDeleteCategory(i-1)}" />
      </c:forEach>
myTree is a managed bean, view scope.
What is exactly the problem here?

thanks,

Edited by: CardM on Nov 9, 2012 12:34 AM
  • 1. Re: expression language and backing bean invocation
    gimbal2 Guru
    Currently Being Moderated
    Did you try just using a JSF type EL expression? Also it seems you're mixing a method invocation with a property reference in your c:forEach. It would be either 'getCurrentCategorySize()' or 'currentCategorySize'. When dealing with bean properties I'd just use the property notation.
    <c:forEach var="i" begin="1" end="#{myTree.currentCategorySize}" >                   
                <h:commandLink value="#{bundle.LabelActionDelete}" action="#{myTree.handleDeleteCategory(i-1)}" />
          </c:forEach>
    Assuming 'myTree' has a method getCurrentCategorySize().
  • 2. Re: expression language and backing bean invocation
    859967 Newbie
    Currently Being Moderated
    yeah, i have a bean method "getCurrentCategorySize()." as your assumption.

    So the problem must be from Expression language ?
  • 3. Re: expression language and backing bean invocation
    gimbal2 Guru
    Currently Being Moderated
    Not necessarily, did you try what I suggested, to simply change to the property notation?

    EL works and has worked for yonks, so you're simply making a mistake. Adding braces is a mistake as there is no method currentCategorySize().
  • 4. Re: expression language and backing bean invocation
    859967 Newbie
    Currently Being Moderated
    ahh,,,, if the method "getCurrentCategorySize()" return a constant, then it works.

    But i need to so some sort of computation with DB query, then it failed.

    Do you see a workaround for it?

    thanks,
  • 5. Re: expression language and backing bean invocation
    859967 Newbie
    Currently Being Moderated
    yeah, i did, remove the braces as you suggested.
  • 6. Re: expression language and backing bean invocation
    gimbal2 Guru
    Currently Being Moderated
    CardM wrote:
    ahh,,,, if the method "getCurrentCategorySize()" return a constant, then it works.

    But i need to so some sort of computation with DB query, then it failed.

    Do you see a workaround for it?
    That is really vague. But it reads like you simply have a bug in your code that is perhaps causing an exception. No workarounds needed, no problem in the technology - find out what YOU are doing wrong and fix it.
  • 7. Re: expression language and backing bean invocation
    859967 Newbie
    Currently Being Moderated
    I assure my code running well. Because before the command link, i have some outputText like this:
    <c:forEach var="i" begin="1" end="#{myTree.currentCategorySize}" >                   
        <h:outputText value="#{i}" />
        <h:outputText value="#{myTree.categoryList.get(i-1).value}" />
        <h:commandLink value="#{bundle.LabelActionDelete}" action="#myTree.handleDeleteCategory(i-1)}" />
    
      </c:forEach>
    and it shows up some values in "myTree.categoryList"; There is no exception at all. And if i have a break point in method "handleDeleteCategory(...)", i don't see program pointer get there after a click on command link.

    p/s: i saw the "myTree.currentCategorySize" invoked twice, and first time got zero, second call returned its true value. It seems that i figure out the solution.

    regards,

    Edited by: CardM on Nov 9, 2012 7:11 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points