Using multiple AJAX calls on the same element Bootsfaces

杀马特。学长 韩版系。学妹 提交于 2019-12-12 00:44:37

问题


Can I do something like this:

<b:navLink  ...    onclick="ajax:callBeanMethodA;ajax:callBeanMethodB" />

Like that doesn't work, is there any way to make it work ?

Thanks


回答1:


I guess your best bet it to combine these two or multiple method calls in a convenience method in your backing bean.

This way you can also make sure, that they're called in a consistent order:

public void combinedMethod() {
    callBeanMethodA();
    callBeanMethodB();
}

Then just call the single convenience method from your listener:

<b:navLink  ...    onclick="ajax:beanName.combinedMethod" />

Other advantages of this approach would be better readability and reusability and maintainability, as you defined the combined logic centrally.




回答2:


Actually, it does work. It's just a bit simpler than you thought. Omit the second ajax: prefix, and things work fine:

JSF markup:

<b:messages id="messages" />
<b:commandButton value="Click me!" 
                 onclick="ajax:menuView.save();menuView.reload()" 
                 update="@form">
</b:commandButton>

Java bean:

@ManagedBean
public class MenuView {
  public void save() {
    addMessage("Success", "Data saved");
  }
  public void reload() {
    addMessage("Success", "reloaded");
  }
}



来源:https://stackoverflow.com/questions/37379272/using-multiple-ajax-calls-on-the-same-element-bootsfaces

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