JSF - pass parameter to ajax call - what's wrong with this code?

I need to pass the bean parameter when calling ajax.

My bean:

@ManagedBean
@RequestScoped
public class Selector {
    @ManagedProperty(value="#{param.page}")
    private String page;

    @PostConstruct
    public void init() {
        if(page==null || page.trim().isEmpty()) {
            this.page="homepage";
        }

        System.out.println(this.page);
    }

    public String getPage() { return page; }
    public void setPage(String page) { this.page=page; }
}

And, when I make an ajax call, I need (due to the fact that I want to display a different context) the page parameter. So, I did this:

// in this moment selector.page = articles
<h:inputHidden value="#{selector.page}" id="page" />

<h:commandLink>
    <f:setPropertyActionListener target="#{articlesSelector.order}" value="1" />
    <f:ajax event="click" render=":articlesContent"/>
    <h:graphicImage value="img/arrow_up.png" alt="Arrow Up"/>
</h:commandLink>

But at the stage of the Apply request, the page still has the "home page". It should get the page parameter from the query, apply it to the component tree and display the context of the "articles". Why isnโ€™t happening?

Greetings

+5
source share
1 answer

<h:inputHidden> . , JSF. - , " ".

, . <f:param> <h:inputHidden>:

<h:commandLink>
    <f:param name="page" value="#{selector.page}" />
    <f:setPropertyActionListener target="#{articlesSelector.order}" value="1" />
    <f:ajax event="click" render=":articlesContent"/>
    <h:graphicImage value="img/arrow_up.png" alt="Arrow Up"/>
</h:commandLink>

#{param.page}, bean @ManagedProperty.

+5

All Articles