JSF - Why setter is not called this time?

2019-08-01 05:41发布

As usual, i've some trouble by using some ajax call on a requested scoped bean.

I've this Bean :

@ManagedBean
@RequestScoped
public class ArticlesSelector implements Serializable {
    @ManagedProperty(value="#{param.type}")
    private String type;
    private String zone;
    private String order;

    @PostConstruct
    public void init() {
        if(type==null || type.trim().isEmpty()) { this.type="1"; }
        if(zone==null || zone.trim().isEmpty()) { this.zone="list"; }
        if(order==null || order.trim().isEmpty()) { this.order="1"; }
    }

    public String getType() { return type; }
    public void setType(String type) { this.type = type; }

    public String getZone() { return zone; }
    public void setZone(String zone) { this.zone=zone; }

    public String getOrder() { return order; }
    public void setOrder(String order) { this.order = order; }

    public ArrayList<String[]> getArticleList() {

        ...

        System.out.println("ORDER = "+this.order);

        ...
    }
}

When i do this call :

<h:panelGroup layout="block" id="articlesContent">
    <h:form id="formArticles">
        <h:outputScript name="jsf.js" library="javax.faces" target="head" />
        <h:panelGroup rendered="#{articlesSelector.zone=='list'}">
            <h:panelGroup layout="block" id="articlesContentList">
                <h:commandLink>
                        <f:setPropertyActionListener target="#{articlesSelector.order}" value="2" />
                        <f:ajax event="click" render=":articlesContent"/>
                        <h:graphicImage value="img/arrow_down.png" alt="Arrow Down"/>
                    </h:commandLink>
                <h:outputLabel value="#{articlesSelector.articleList}" />                
            </h:panelGroup>
        </h:panelGroup>
    </h:form>
</h:panelGroup>  

The order value is always 1. Seems that setter method is not called. This time is not a render fault, because that action is rendered on Apply request and Update model phases (in fact, System.out.println("ORDER = "+this.order); trougth #{articlesSelector.articleList} it's called every time i click on the image). So, what's up this time?

Request Scope make me a bit nervous :)

Thanks

2条回答
混吃等死
2楼-- · 2019-08-01 06:15

The f:ajax should be fired on event="action", not event="click".

Yes, I know that I ever suggested in a comment of your question to use click, but I was apparently Wrong™. Sorry for that :)

查看更多
欢心
3楼-- · 2019-08-01 06:20

The ":" at the start of the id in your f:ajax render attribute refers to a fully qualified, or absolute id, yet the value you put in there is not absolute.

Change the render attribute value to be relative:

render="articlesContent"

or to an absolute one:

render=":articlesContent:formArticles:articlesContent"
查看更多
登录 后发表回答