Search code examples
javajsfjakarta-eeprettyfaces

JSF bean URLAction gets called everytime


@Named
@RequestScoped
@URLMapping(id = "unblock", pattern = "/unblock", viewId = "/unblock.xhtml")
public class Unblock {

@URLAction
public void load(){
    //initialize some values..
}

public void sendRequest(){

}

and in xhtml file;

 <h:commandButton id="submit action="#{unblockAccount.sendRequest}"

Now when the first time page loads my load method gets called correctly, but when I click a submit button on the page and call "sendRequest" method, the load method gets called again.

How can I stop this? I tried to also use @ViewScope but didnt help


Solution

  • Add onPostBack=false to the @URLAction to stop the action from being called on a postback.

    A post back is any request initiated on a JSF view after a fresh request for the view

        @URLAction(onPostback=false)
        public void load(){
          //initialize some values..
        }