Reputation: 97
I need a button that takes the user back to a certain page and for that purpose I've put a h:outputLink inside a h:commandButton as seen below:
<h:commandButton styleClass="richButtonLogout">
<h:outputLink value="/pages/somePage.xhtml">
SomePage
</h:outputLink>
I was expecting the button to get me to the specified page when clicked, but instead I see a separate button and a separate link in the browser. So, the link is outside of the button. The button won't do anything , while the link works normally. A similar approach works fine with html, so I thought it would be ok.
Upvotes: 0
Views: 751
Reputation: 2321
No, you cannot put an outputLink
inside a commandButton
. These are seperate components not associated with or dependant on each other.
If you want a button to function as a link you can use the h:button
JSF component in combination with the outcome
attribute like so,
<h:button outcome="..."/>
Note though that while it indeed works, the JSF button
component uses JavaScript to achieve this navigation - so it's not an ordinary link as you would expect. Because these are navigation outcomes (not links) - one advantage with this method is that you can use static outcomes and dynamically define your navigation rules in faces-config.xml
.
Obviously, to achieve a plain old link, you could also just use an ordinary <a href="...">
with appropriate button styling to achieve the same end result.
Upvotes: 3