0

In JSF2, is there a way to stop a method from being called automatically? For example, in my bean:

public String goToSearchResults() {
    // do all kinds of stuff
}

In my .xhtml file:

<p:commandLink id="srchbutton" action="#{home.goToSearchResults()}">
   <h:graphicImage.../>
</p:commandLink>

This method is called whenever the user arrives at my home page, before even specifying search terms. Obviously it's an unnecessary call. Is there a way to prevent it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Eddy
  • 3,533
  • 13
  • 59
  • 89
  • 2
    The given code doesn't do that. You can easily confirm it yourself by copypasting it into a completely blank page in a completely blank playground project with everything set to defaults and most recent versions unless otherwise mentioned in the question ([as anyone else reading this question would (theoretically) do](http://stackoverflow.com/tags/jsf/info)). Perhaps you've in your actual code somewhere a XML-outcommented block with therein the very same EL expression? – BalusC Jul 03 '15 at 12:17
  • Seems like you're right, it was in an commented out code. Why would it call commented out code? – Eddy Jul 03 '15 at 12:24
  • 2
    Because it only outcomments XML/HTML, not EL. By the way, as general practice, omit EL method parentheses as much as possible, unless you really need to explicitly pass method arguments. – BalusC Jul 03 '15 at 12:27
  • Thanks @BalusC. Will do. – Eddy Jul 03 '15 at 12:30

0 Answers0