2010-12-02 13 views
1

像往常一樣,我對請求的scoped bean使用了一些ajax調用有些麻煩。JSF - 這次爲什麼沒有調用setter?

我有這個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); 

     ... 
    } 
} 

當我做這個調用:

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

順序值始終1。似乎沒有調用setter方法。此時不是渲染錯誤,因爲該動作呈現在應用請求更新模型階段(實際上,System.out.println("ORDER = "+this.order);麻煩#{articlesSelector.articleList}它每次我點擊圖像時都會被調用)。那麼,這次呢?

請求範圍讓我有點緊張:)

感謝

回答

2

f:ajaxevent="action"被解僱,不event="click"

是的,我知道我曾經在你的問題的評論中建議使用click,但我顯然是錯誤™。對不起:)

0

的「:」在你的F中的ID開始:AJAX渲染屬性指的是完全合格的,或絕對的ID,但你放在那裏的價值並不是絕對的。

更改渲染屬性值是相對的:

render="articlesContent" 

或絕對的:

render=":articlesContent:formArticles:articlesContent" 
+0

不知道這可以工作。我試過了。但`commandbutton`進入`articlesContentList`,我需要呈現`articlesContent`。這就是爲什麼我把`:` – markzzz 2010-12-02 16:01:12

+0

是的,其實我只能寫`render =「articlesContentList」`,但問題仍然發生:) – markzzz 2010-12-02 16:07:39

相關問題