我正在创建一个着陆页,我想将检索到的提交数据传递给我的服务层。
我的服务层看起来像这样:
@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;
}
我的表格看起来像那样:
<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>
当我按提交时,我的表格不会被提起。我甚至看不到我的日志消息。任何想法,我必须改变什么?
答案 0 :(得分:1)
阅读tag documentation of <h:button>
。它呈现GET按钮,不支持action
属性。调查webbrowser开发人员工具集中的HTTP流量(按Chrome / IE / Firebug中的F12并检查网络标签)也会暗示<h:button>
没有执行回发。
改为使用<h:commandButton>
,就像演示表单提交的每个理智的JSF教程中所示。
<h:commandButton id="submit_form_new" value="Request Invitation"
action="#{landingPageService.persist}"
styleClass="btn btn-primary opal_btn" />