Difference between jsf actionListener(param) and propertyListener when using back button on keyboard

半世苍凉 提交于 2020-01-05 20:21:46

问题


I encountered a problem that I fixed but I can't understand why the fix works and the original code doesn't work. It's the easiest to explain it with code:

I've got the following method in my entityBackingBean (entityBB):

public void standardLetterInit(Letter entity) {
    setEntity(entity);
}

And the following in my xhtml page:

<h:commandLink actionListener="#{entityBB.standardLetterInit(varEntity)}"/>

This commandLink is situated in a datatable that contains varEntity as var.

The above code works, but does something strange when using the "back button" on the keyboard. If you click on the commandlink, the entity has the selected value in the backingBean. If you then press "back" and click on another commandlink, then the entity still has got the value from the previous click. How can that be?

I used the following as solution, but can't understand the difference between the 2 approaches:

 <h:commandLink actionListener="#{entityBB.standardLetterInit()}">
    <f:setPropertyActionListener target="#{entityBB.entity}" value="#{varEntity}" />
 </h:commandLink>

and in my entityBackingBean (entityBB):

public void standardLetterInit() {
    //without setEntity
    //rest of method
}

EDIT:

I have just noticed the following: If I add any parameter to the standardLetterInit() method, even a boolean.. Then the entity does not change. I'm even more confused now.

来源:https://stackoverflow.com/questions/21306045/difference-between-jsf-actionlistenerparam-and-propertylistener-when-using-bac

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