JSF - Why setter is not called this time?

青春壹個敷衍的年華 提交于 2019-12-13 01:28:30

问题


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


回答1:


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 :)




回答2:


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"


来源:https://stackoverflow.com/questions/4334424/jsf-why-setter-is-not-called-this-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!