Reputation: 697
I want to check if someone has permission or not so they can view my link, but I don't understand why when I click in the 'View' link, it will disappear that link and does not process my prepareView(). What's wrong with it ?
<c:if test="#{controller.viewMode == 'OK'}">
<h:commandLink action="#{controller.prepareView()}" value="View"/>
</c:if>
<h:commandLink action="#{controller.prepareEdit()}" value="Edit"/>
<h:commandLink action="#{controller.destroy()}" value="Delete"/>
Upvotes: 0
Views: 748
Reputation: 1108642
That can happen when the value behind #{controller.viewMode}
depends on a request scoped condition which has incompatibly changed in the request of the form submit as compared to the request of the form display.
During the restore view phase of processing of the form submit, the <c:if>
is re-evaluated again. If the #{controller.viewMode}
returns at that moment not "OK" (even though it did that during the initial request of the form display) then the command link disappears in the component tree. Its action would then never be decoded nor invoked.
To fix this, you need to make sure that the #{controller.viewMode}
returns exactly the same value during the postback request as it did during the initial request. If your bean is request scoped, you'd basically need to make sure that that property is properly initialized in the (post)constructor of the request scoped bean.
Alternatively, you could also put the bean in the view scope instead, so that the bean instance will live as long as you're interacting with the same view, but that has in turn another problem when used in taghandlers. So when you want to use the view scope, then you'd definitely have to replace the JSTL test by the rendered
attribute of the JSF component.
@ManagedBean
@ViewScoped
public class Controller {
// ...
}
with
<h:commandLink value="View" action="#{controller.prepareView}" rendered="#{controller.viewMode == 'OK'}" />
Upvotes: 2