When i use
<h:button>
or
<h:link>
i can't make any business action in managed bean ? Do I have to use
<h:form>
and
<h:commandButton>
or
<h:commandLink>
with action param or there is another solution ?
Depends on the kind of request you'd like to fire.
If it needs to be a non-idempotent POST request, just use <h:form>
with <h:commandXxx action>
. Again depending on the concrete functional requirement, you can render the results conditionally in the same view, or send a redirect to the target view afterwards.
If it needs to be an idempotent GET request, use <h:link>
/<h:button>
and perform the action in @PostConstruct
method in the request/view scoped backing bean associated with the target page. If you need to pass parameters, use <f:param>
to set them on <h:link>
/<h:button>
and use <f:viewParam>
and <f:event type="preRenderView">
in target view to set and process them in backing bean associated with target view.
All in all, just use the right tool for the job as specified by concrete functional requirement (which you unfortunately didn't tell anything about in your question).
No, you can't do that with h:link
or h:button
, there are meant to be bookmarkable GET urls. So if you want to perform business action, you need to use either commandButton
or commandLink
. Note that it's also worth to use h:outputLink
for generating bookmarkable links between pages because is much more SEO friendly.