Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent h:Commandbutton from submitting form

I have a form and two commandbuttons embedded in it as shown.

<h:commandButton label="Submit" type="button" 
    image="resources/images/Save4.jpg" 
    actionListener="#{userController.createNewUser()}" /> 

<h:commandButton label="Home" 
    image="resources/images/Save4.jpg" 
    action="/index.jsf?faces-redirect=true" /> 

Clicking on Home button should redirect to index.jsf but it causes form submission. I dont want to put the home command in another form tag as it will cause UI Distortion. Please suggest a way out.

like image 949
Manish Kumar Thakur Avatar asked Nov 21 '25 03:11

Manish Kumar Thakur


1 Answers

A command button submits the entire POST form. It's the wrong tool for plain page-to-page navigation. It's not SEO friendly either (searchbots don't index POST forms).

If the sole functional requirement is having a clickable image which should navigate to a different page, then just use <h:link><h:graphicImage>.

<h:link outcome="/index.jsf">
    <h:graphicImage name="images/Save4.jpg" />
</h:link>
like image 112
BalusC Avatar answered Nov 22 '25 18:11

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!