JSF - Can the @PostConstruct method of setting a block using an ajax call?

I think the question is clear from the title. This is my actual bean:

@ManagedBean(name="selector")
@RequestScoped
public class Selector {
    private String profilePage;

    @PostConstruct
    public void init() {
        System.out.println("I'm PostConstruct");
        if(profilePage==null || profilePage.trim().isEmpty()) {
            this.profilePage="main";
        }
    }

    public String getProfilePage() { 
        return profilePage;
    }

    public void setProfilePage(String profilePage) { 
        this.profilePage=profilePage;
        System.out.println("I'm setProfilePage");
    }
}

And I change its value (profilePage) with ajax call:

<h:commandButton value="Some Action">
    <f:setPropertyActionListener target="#{selector.profilePage}" value="some" />
    <f:ajax event="action" render=":profileContent"/>
</h:commandButton>

I notice that my output on the server is not the sequence I'm PostConstructthat follows I'm setProfilePage. Sometimes I'm setProfilePagecompletely absent.

I read that Methods marked with the @PostConstruct annotation will be called after the bean is created, any resources have been added and any managed properties have been set, but before the bean is actually introduced into the scope.

I would like to know if @PostConstructit can make some conflicts with the setter method.

Greetings

+2
2

I'm setProfilePage .

, UICommand / . rendered false .

@PostConstruct .

+1

BalusC, rendered, false , , . , false JSF (.. ) true.

true ( ) - SaveState Tomahawk .

, , PostConstruct AJAX .

+1

Source: https://habr.com/ru/post/1777192/


All Articles