0

I am creating a landing page and I want to pass my retrieved submited data to my service layer.

My Service layer looks like that:

@Component
@Scope("session")
public class LandingPageService implements Serializable{

    /**
     * landingPageDAO
     */
    @Autowired
    private LandingPageDAO landingPageDAO;

    /**
     * LandingPage Instance
     */
    private LandingPage instance = null;

    public LandingPage getInstance() {
        logger.trace("returning instance...");

        if(instance == null) {
            instance = new LandingPage();
        }

        return instance;
    }

    /**
     * writes the LandingPage Domain Object into the DB
     */
    public void persist() {
        logger.trace("persisting...");
        landingPageDAO.persist(instance);
        instance = null;
    }

and my form looks like that:

<h:form class="homepage_invitee_form" action="" method="POST">
                                    <h:inputText required="true" value="#{landingPageService.instance.userEmail}" name="email" placeholder="Email Address"
                                        id="email_address_new" type="text placeholder" />
                                    <p:watermark for="email_address_new" value="Email Address" />
                                    <br />
                                    <h:inputText required="true" value="#{landingPageService.instance.firstName}" name="firstName" placeholder="First Name"
                                        id="firstname_new" type="text placeholder" />
                                    <p:watermark for="firstname_new" value="First Name" />

                                    <h:button value="Request Invitation" type="submit"
                                        styleClass="btn btn-primary opal_btn" id="submit_form_new"
                                        action="#{landingPageService.persist()}"/>

                                </h:form>

When I press submit my form does not get handeled. I cannot even see my logging messages. Any ideas, what I have to change?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
maximus
  • 11,264
  • 30
  • 93
  • 124

1 Answers1

1

Read the tag documentation of <h:button>. It renders a GET button and doesn't support the action attribute. Investigating the HTTP traffic in webbrowser's developer toolset (press F12 in Chrome/IE/Firebug and check Network tab) would also have hinted that the <h:button> didn't perform a postback.

Use <h:commandButton> instead, like as shown in every sane JSF tutorial demonstrating a form submit.

<h:commandButton id="submit_form_new" value="Request Invitation"
    action="#{landingPageService.persist}"
    styleClass="btn btn-primary opal_btn" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555