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