The second one doesn't work because your managed property binding is resolved to null
, as there is most possibly no element for aktuelleVerteilerliste
key in any of the JSF-scoped maps.
To make the second one work you need to tell JSF to look within parameters of a given request, i.e. change to @ManagedProperty(value = "#{param['aktuelleVerteilerliste']}")
.
To make the distinction more clear, <f:setPropertyActionListener>
simply equates target
object to value
in invoke application phase of JSF lifecycle while the latter approach simply adds a particular parameter to a JSF component, which is command component in your case, and command component parameters can be accessed via EL object param
that is a map of current request parameters.
That said, your usage of command links is considered to be a bad practice. They are used to invoke some server-side logic when the form is submitted to perform some business job. In your case you are using them to perform plain navigation. For this you'd be better off using <h:link>
components to create simple a
elements. This way, if you attach a parameter you'll end up with a query parameter like editverteilerliste?aktuelleVerteilerliste=something
that you can get in the view via <f:viewParam>
. That way you'll end up with bookmarkable URLs and clear navigation in your application.