1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
GregD
  • 1,884
  • 2
  • 28
  • 55
  • I'd bet on the combination of browser cache and coincidence. This answer may be helpful: http://stackoverflow.com/questions/14101380/force-jsf-to-refresh-page-view-form-when-back-button-is-pressed – BalusC Jan 23 '14 at 11:55
  • I could indeed dissable the caching, but that doens't explain me why the propertyActionListener does work, if I don't use any parameters in the method call from the actionListener and the actionListener doesn't work at all. It seems to me that both wouldn't work if it's a caching thing. But I might be wrong there..! – GregD Jan 23 '14 at 12:25
  • What type of managed bean you have? ViewScoped? – Yamada Jan 23 '14 at 12:27
  • It is ViewScoped indeed. – GregD Jan 23 '14 at 12:31
  • Yes, that's the coincidence part. Next time, prune browser cache to be sure. – BalusC Jan 23 '14 at 12:44
  • Hmm.. ok! Though I don't really believe in coincidence in IT, I'll settle with it ^^! – GregD Jan 23 '14 at 12:51

0 Answers0