3

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.

mabi
  • 5,279
  • 2
  • 43
  • 78

2 Answers2

3

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

It's a bad idea to use POST for navigation, anyway. Instead, use something like this:

<h:button label="Home" image="..." outcome="/index" />
mabi
  • 5,279
  • 2
  • 43
  • 78
  • 1
    This is only not SEO-friendly either. Navigation takes here place by JavaScript instead of HTML. Searchbots usually doesn't chipher/follow JavaScript code. – BalusC Jan 20 '14 at 17:11