Change Update attribute dynamicaly in Primefaces

ε祈祈猫儿з 提交于 2019-12-24 09:39:57

问题


I am looking for a way to change the update attribute of a primefaces command button from the backing bean after the form submit. What i am trying to achieve is to update the component id's based on the results from backing bean method.

For example, i am trying to update the form and the growl message with a command button, now if some error has happened from the backing bean(not validation error), i need to update only the growl message and the form shouldn't be updated.

<p:commandButton value="Finish Editing"
        action="#{editBean.finish}" icon="ui-icon-check"
        style="width:200px;margin-left:60px;" update=":studentEditForm   :messageForm:applyMessages" />

回答1:


You can use the programmatic API via RequestContext#update().

public void finish() {
    // ...

    if (someCondition) {
         RequestContext.getCurrentInstance().update("someClientId");
    } else {
         RequestContext.getCurrentInstance().update("otherClientId");
    }
}             

Don't forget to remove the update attribute from the command button.




回答2:


Change this

<p:commandButton value="Finish Editing"
        action="#{editBean.finish}" icon="ui-icon-check"
        style="width:200px;margin-left:60px;" update=":studentEditForm   :messageForm:applyMessages" />

to

<p:commandButton value="Finish Editing"
        action="#{editBean.finish}" icon="ui-icon-check"
        style="width:200px;margin-left:60px;" update="#{editBean.updateString}" />

Now you will have to update this string in EditBean class as required.



来源:https://stackoverflow.com/questions/17209495/change-update-attribute-dynamicaly-in-primefaces

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