我正在创建一个登陆页面,我想把我检索到的提交数据传递给我的服务层。
我的Service层是这样的:
@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>
当我按提交时,我的表单没有得到处理。我甚至看不到我的日志信息。有什么要改的吗?
阅读<h:button>
的标签文档。它呈现GET按钮,不支持action
属性。在webbrowser的开发者工具集中调查HTTP流量(在Chrome/IE/Firebug中按F12并检查Network选项卡)也会暗示<h:button>
没有执行回发。
使用<h:commandButton>
代替,就像每个演示表单提交的JSF教程中所示的那样。
<h:commandButton id="submit_form_new" value="Request Invitation"
action="#{landingPageService.persist}"
styleClass="btn btn-primary opal_btn" />
参见:
- h:button与h:commandButton的区别