2011-09-08 43 views
2

再次,PrimeFaces和GAE的組合讓我瘋狂。在p:dataTable的內部,我想單擊一個圖像,調用一個bean方法並設置一個參數。該方法被調用,但該參數不起作用。下面是一個簡單的例子(不帶表):Google App Engine:f:setPropertyActionListener with p:ajax

<h:form id="f1"> 
    <h:outputText id="text" value="#{testBean.index}"/> 
    <h:graphicImage url="/images/cut.png"> 
    <p:ajax event="click" process="@this" update="text" 
      actionListener="#{testBean.test}" > 
     <f:setPropertyActionListener target="#{testBean.index}" value="5" /> 
    </p:ajax> 
    </h:graphicImage> 
</h:form> 

TestBean看起來是這樣的:

@javax.faces.bean.ManagedBean @ViewScoped 
public class TestBean implements Serializable{ 
    private int index; // getter/setter 

    @PostConstruct public void init() { 
    index = 0;log.log(Level.WARNING, "@PostConstruct");} 

    public void test(ActionEvent ae){ 
    log.log(Level.WARNING, "Index: "+index);} 
} 

在我看到一個@PostConstruct的日誌和點擊圖像總是Index: 0

後更新值更新問題可能在這裏討論JSF GAE: Value Update Problem in managed bean method

回答

3

我對GAE瞭解不多,所以我不能認爲它不會干擾你的代碼。但我不一定認爲<f:setPropertyActionListener>是適用於<p:ajax>標籤的適當標籤。我不相信它接受。

以下是我如何使用<p:commandLink>和HTML <span>標記實現對aaax調用viewcoped bean屬性的示例。

<p:commandLink actionListener="#{listUsers.toModify}" oncomplete="userEditDlg.show()" 
    update="addEditForm:editGrid addEditGrid:passwordChange addEditGrid:passwordGrid"> 
    <f:param name="userId" value="#{user.userId}" /> 
    <span class="ui-icon icoCogEdit" style="padding-right: 1.5em;" /> 
</p:commandLink> 
<p:commandLink actionListener="#{listUsers.toDelete}" oncomplete="userDelDlg.show()" 
    update="listUsersForm:dialogText"> 
    <f:param name="userId" value="#{user.userId}"/> 
    <span class="ui-icon icoDelete" /> 
</p:commandLink> 

我只是將一個CSS類設置爲我選擇的靜態圖像圖標,然後單擊它就會調用一個對話框。

+4

說明:''僅在實現'ActionSource'的父組件支持。 ''沒有。然而,有趣的細節是,當你使用''而不是''時,拋出了一個異常,正是這個消息。 ''順便也可以用所需的'替換。 ''順便說一句,在'

'內部不會有''的效果。 – BalusC

+0

@BalusC,我沒有意識到這一點,並且學到了一些新東西,但是如果仔細觀察,會發現''實際上位於''標籤內部,縮進是棘手的。雖然這是很好的信息。 –

+0

''不能是另一個''的孩子。它將僅僅是父級「UIComponent」的子級。 – BalusC