为了替换默认的Spring安全登录表单,我提出了这个解决方案:
<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>
Run Code Online (Sandbox Code Playgroud)
但是<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="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>
Run Code Online (Sandbox Code Playgroud)
它会导致错误消息Unable to find matching navigation case with from-view-id '/login.xhtml' for action '../j_spring_security_check' with outcome '../j_spring_security_check'.
这是定义导航案例的唯一方法faces-config.xml吗?我想避免在这个简单的用例中使用bean.
对我来说最好的解决方案是使用默认<button>标签.由于没有应用典型的按钮样式(在我的情况下我使用的是Primefaces),我手动设置它.这是整个结果:
<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>
Run Code Online (Sandbox Code Playgroud)
小智 7
<h:form id="login" prependId="false" onsubmit="document.getElementById('login').action='j_security_check';">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45235 次 |
| 最近记录: |