How to send an inputText to a bean at the moment a post request is made in JSF?

笑着哭i 提交于 2020-01-06 03:13:05

问题


The constraint I have is that my JSF + Primefaces page must include a post request in straight html:

<form id="checkout" method="post" action="/checkout">
  <div id="payment-form"></div>
  <input type="submit" value="Pay $10">
</form>

And I can't touch that.

On the same page, I have an inputText where the user will put their email address: <p:inputText value="#{bean.emailAddress}"/>

When the button in the <form> is clicked for the post request, I'd like to have the inputText submitted as well and sent to a bean on my server. How could I achieve that? Just including <p:inputText value="#{bean.emailAddress}"/> inside the <form></form> tag seems not to work.


回答1:


Hook a JavaScript event listener to that form which triggers a <p:remoteCommand> processing at least the <p:inputText> of interest.

As you're using PrimeFaces, you'll have jQuery at hands. So, this should do:

<form id="checkout" ...>
    ...
</form>

<h:form>
    <p:inputText ... />
    <p:remoteCommand name="checkout" process="@form" action="#{bean.checkout}" />
</h:form>
$(document).on("submit", "#checkout", function() {
    checkout();
});


来源:https://stackoverflow.com/questions/34255920/how-to-send-an-inputtext-to-a-bean-at-the-moment-a-post-request-is-made-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!