JSF - Why setter is not called this time?
Asked Answered
C

2

1

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

Calvano answered 2/12, 2010 at 11:26 Comment(0)
L
2

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

Lambda answered 2/12, 2010 at 16:37 Comment(3)
OH! Hehe, don't worry!! So there's a differences between action an click!! What's? :)Calvano
Will investigate sooner or later and let you know.Lambda
This is actually nowhere documented (or I need new glasses), so I had to dig the JSF source code. The action event works on UICommand components only and will be evaluated as ActionEvent which will execute the component's action and actionListener -if any- and will take f:setPropertyActionListener with it. The other events are "just" BehaviorEvent which maps to the existing HTML DOM event and will only execute the method which is declared in listener attribute of f:ajax -if any- and it ignores the f:setPropertyActionListener, action and actionListener -if any.Lambda
S
0

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"
Savannahsavant answered 2/12, 2010 at 15:53 Comment(2)
Dunno this could work. I tried. But the commandbutton is into articlesContentList, and i need to render articlesContent. That's why i put :Calvano
Yeah, in fact i could write only render="articlesContentList", but the problem still happens :)Calvano

© 2022 - 2024 — McMap. All rights reserved.