开发者

Google App Engine: f:setPropertyActionListener with p:ajax

开发者 https://www.devze.com 2023-04-03 23:58 出处:网络
once again the combination of PrimeFaces and GAE drives me crazy. Inside a p:dataTable I want to click a image, call a bean method and set a parameter. The method is called, but the parameter does not

once again the combination of PrimeFaces and GAE drives me crazy. Inside a p:dataTable I want to click a image, call a bean method and set a parameter. The method is called, but the parameter does not work. Here is a simplified example (without the table):

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

My TestBean looks like this:

@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);}
}

In the Logs I see one @PostConstruct and after clicking the image always Index: 0

Update The value update problem may be discussed here JSF GAE: Value Update Problem i开发者_如何学Gon managed bean method


I don't know much about GAE, so I can't assume that it isn't somehow interfering with your code. I don't necessarily think that the <f:setPropertyActionListener> is the appropriate tag to use for a <p:ajax> tag however. I don't believe it accepts that.

Here is an example of how I implemented an ajax call to a viewscoped bean property using <p:commandLink> and an HTML <span> tag.

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

I just set a CSS class to be a static image icon of my choosing, and then clicking on it would invoke a dialog.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号