FacesContext redirect with POST parameters

前端 未结 1 905
梦如初夏
梦如初夏 2021-01-29 00:46

I need to redirect page into external site with POST parameters, but I cannot use vanilla HTML

like it is explained here:

JSF co

相关标签:
1条回答
  • 2021-01-29 01:39

    Try something like this:

    JAVASCRIPT:

    function redirect() {
        document.getElementById("mySubmitButton").submit();
    }
    

    XHTML:

    <h:form>
         <span onclick="javascript:redirect()" class="linkClass">REDIRECT</span>
    </h:form>
    
    <div style="display:none:"> <!-- If you want it hidden -->
        <form action="http://external/myplace.html" method="post"> 
            <input type="hidden" value="value1"></input>
            <input type="submit" id="mySubmitButton"</input>
        </form>
    </div>
    

    EDIT: Added another test.

    PASSING DYNAMIC PARAMETER:

    In this example we assume that we are always going to send a value.

    JAVASCRIPT:

    function redirect(dynamicValue) {
        document.getElementById("dynamicField").value = dynamicValue;
        document.getElementById("mySubmitButton").submit();
    }
    

    XHTML:

    <h:form>
         <span onclick="javascript:redirect('myValue')" class="linkClass">REDIRECT</span>
    </h:form>
    
    <div style="display:none:"> <!-- If you want it hidden -->
        <form action="http://external/myplace.html" method="post"> 
            <input id="dynamicField" type="hidden" value=""></input>
            <input type="hidden" value="value1"></input>
            <input type="submit" id="mySubmitButton"</input>
        </form>
    </div>
    
    0 讨论(0)
提交回复
热议问题