如何在JSF中定义表单动作? [英] How to define form action in JSF?

查看:144
本文介绍了如何在JSF中定义表单动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form name =

为了替换默认的Spring安全登录表单, faction =../ j_spring_security_checkmethod =POST>
< h:panelGrid columns =2>
< h:outputText value =用户名/>
< h:inputText id =j_username/>
< h:outputText value =Password/>
< h:inputText id =j_password/>
< / h:panelGrid>
< h:commandButton value =Login/>
< / form>

但不是简单的< form> 标签我希望使用< h:form> ,因为Primefaces组件只能在< h:form> 。使用< h:form> 表单动作将由JSF自动设置到当前页面,而不是上面示例中由我设置的值。我现在必须在哪里编写行动../ j_spring_security_check>?我试着把它放到< h:commandButton> 中,但是不起作用:

 < h:form name =f> 
< h:panelGrid columns =2>
< h:outputText value =用户名/>
< h:inputText id =j_username/>
< h:outputText value =Password/>
< h:inputText id =j_password/>
< / h:panelGrid>

< h:commandButton value =点击此处action =../ j_spring_security_check/>
< / form>

导致错误消息 无法找到匹配的导航案例with from view-id'/login.xhtml'for action'../j_spring_security_check'with outcome'../ j_spring_security_check'

它是在 faces-config.xml 中定义导航案例的唯一方法吗?我想避免使用这个简单用例的bean。

解决方案

对我来说最好的解决方案是使用默认的<按钮> 标记。由于没有应用典型的按钮样式(在我的情况下,我正在使用Primefaces),所以我手动设置它。以下是整个结果:

 < h:outputStylesheet library =primefacesname =jquery / ui / jquery-ui。 css/> 
< h:outputStylesheet library =cssname =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_checkmethod =post>
< h:panelGrid columns =2>
< h:outputText value =用户名/>
< h:inputText id =j_username/>
< h:outputText value =Password/>
< h:inputSecret id =j_password/>
< / h:panelGrid>

< div class =submit>
< button type =submitclass =ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only>
< span class =ui-button-text>登入< / span>
< / button>
< / div>
< / form>
< / div>


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

<form name="f" 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:inputText id="j_password" />
    </h:panelGrid>
    <h:commandButton value="Login" />
</form>

But instead of plain <form> tag I would like to use <h:form> since Primefaces components only work within <h:form>. Using <h:form> the form action will be set automatically by JSF to the current page, not to the value set by me in the example above. Where to I have to code the action "../j_spring_security_check" now? I tried putting it into the <h:commandButton> as follows but that doesn't work:

<h:form name="f">
    <h:panelGrid columns="2">
        <h:outputText value="Username" />
        <h:inputText id="j_username" />
        <h:outputText value="Password" />
        <h:inputText id="j_password" />
    </h:panelGrid>

    <h:commandButton value="Click here" action="../j_spring_security_check" />
</form>

It leads to the error message Unable to find matching navigation case with from-view-id '/login.xhtml' for action '../j_spring_security_check' with outcome '../j_spring_security_check'.

Is it the only way to define a navigation case in faces-config.xml? I want to avoid using a bean for this simple use case.

解决方案

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>

这篇关于如何在JSF中定义表单动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆