我的JSF页面上有以下表格,该表格发布到外部信用卡处理器。 我想使用JSF操作方法,所以我可以编写一些业务逻辑。如何通过操作方法发布帖子并包含以下字段?
<form action="#{checkoutBean.sagepayURL}" method="post"
id="SagePayForm" name="SagePayForm">
<input type="hidden" name="VPSProtocol"
value="#{checkoutBean.sagepayMessage.vpsProtocol}" /> <input
type="hidden" name="TxType"
value="#{checkoutBean.sagepayMessage.transactionType}" /> <input
type="hidden" name="Vendor"
value="#{checkoutBean.sagepayMessage.vendor}" /> <input
type="hidden" name="Crypt" class="crypt"
value="#{checkoutBean.sagepayMessage.crypt}" /> <input
type="submit"
value="Proceed to Checkout" />
</form>
答案 0 :(得分:2)
您可以使用JavaScript提交隐藏的JSF ajax表单,该表单又会呈现一个提交付款表单的脚本。
<form action="#{checkoutBean.sagepayURL}" method="post"
id="SagePayForm" name="SagePayForm">
...
<input type="button" value="Proceed to Checkout"
onclick="document.getElementById('hiddenForm:link').click()" />
</form>
<h:form id="hiddenForm" style="display:none">
<h:commandLink id="link" action="#{checkoutBean.preprocess}">
<f:ajax render="@form" />
</h:commandLink>
<h:outputScript rendered="#{checkoutBean.preprocessed}">
document.getElementById("SagePayForm").submit();
</h:outputScript>
</h:form>
与
private boolean preprocessed; // +getter
public void preprocess() {
// ...
preprocessed = true;
}
根据您的问题历史记录,您似乎正在使用OmniFaces,在这种情况下,您还可以使用<o:commandScript>
进行简化,如下所示:
<form action="#{checkoutBean.sagepayURL}" method="post"
id="SagePayForm" name="SagePayForm">
...
<input type="button" value="Proceed to Checkout" onclick="preprocess()" />
</form>
<h:form>
<o:commandScript name="preprocess" action="#{checkoutBean.preprocess}"
oncomplete="document.getElementById('SagePayForm').submit()" />
</h:form>