2

我的 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>
4

1 回答 1

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>
于 2012-12-28T11:36:31.633 回答