How to define form action in JSF?

前端 未结 4 640
终归单人心
终归单人心 2020-12-14 12:55

In order to replace the default Spring security login form I came up with this solution:

相关标签:
4条回答
  • 2020-12-14 13:26

    The best solution for me is to use the default <button> tag instead. Since typical button styling is not being applied (in my case I am using Primefaces), I set it manually. Here's the whole result:

        <h:outputStylesheet library="primefaces" name="jquery/ui/jquery-ui.css" />
        <h:outputStylesheet library="css" name="login.css" />
    
        <div class="message">
            <c:if test="#{param.error == 1 and SPRING_SECURITY_LAST_EXCEPTION != null}">
                <span class="error">#{SPRING_SECURITY_LAST_EXCEPTION.message}</span>
            </c:if>
        </div>
    
    
    
        <div class="login">
            <form action="../j_spring_security_check" method="post">
                <h:panelGrid columns="2">
                    <h:outputText value="Username" />
                    <h:inputText id="j_username" />
                    <h:outputText value="Password" />
                    <h:inputSecret id="j_password" />
                </h:panelGrid>
    
                <div class="submit">
                    <button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
                        <span class="ui-button-text">Login</span>
                    </button>
                </div>
            </form>
        </div>
    
    0 讨论(0)
  • Your action attribute should be an EL expression like follows:

    action="#{managedBean.method}"
    
    0 讨论(0)
  • 2020-12-14 13:45

    Your best chance is to use the onclick property of the button. This is an example with a primefaces commandButton, but it will also work for jsf components because it uses the (native) javascript onclick function.

    <h:form>
    <p:commandButton value="Submit" onclick="alert('JS!')" actionListener="#{tweetBean.addTweet()}" update=":tabView,:trends,:tweetsnr" /> 
    </h:form>
    
    0 讨论(0)
  • 2020-12-14 13:47
    <h:form id="login" prependId="false"              onsubmit="document.getElementById('login').action='j_security_check';">
    
    0 讨论(0)
提交回复
热议问题