j_security_check与Primefaces [英] j_security_check with Primefaces

查看:453
本文介绍了j_security_check与Primefaces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实施 j_security_check Primefaces ?通常,在 JSP 如果您想使用 JAAS 作为登录,登录表单一般是:

How to implement j_security_check with Primefaces? Normally in JSP if you want to use JAAS for login, the login form generally is:

<form action="j_security_check" method="POST">
   Username:<input type="text" name="j_username"><br>
   Password:<input type="password" name="j_password">
   <input type="submit" value="Login">
</form>

但是,我们如何在JSF或Primefaces实现它!

But how do we implement it in JSF or in Primefaces!


  • 会有什么动作

  • 我们如何摆脱ID或名字像 formId:COMPONENTID

  • 另外,号码:的commandButton 默认情况下Primefaces是Ajax化的,那么它是怎样
    提交表单在非AJAX方式

  • What will be the action
  • How do we get rid of id or name like formId:componentId
  • Also the p:commandButton is ajaxified in Primefaces by default, so how does it submit the form in non-ajax way

我不得不实施 JAAS 形式认证要求 Primefaces 我在这里分享的解决方案;它可能会来方便的人。

I had a requirement to implement the JAAS form authentication with Primefaces and I am sharing the solution here; it might come handy to someone.

推荐答案

解决方案是pretty简单。

The solution is pretty straightforward.


  • 您需要定义 H:形式 prependId =FALSE,以便它不会产生组件的ID或名字作为 formId:COMPONENTID

  • 您需要定义在小时行动=j_security_check:形式的onsubmit =的document.getElementById('登录')行动='j_security_check';

  • P的 AJAX 属性:的commandButton ,这样的形式没有得到提交的AJAX方法。

  • You need to define the h:form with prependId="false", so that it will not generate id or name of the component as formId:componentId.
  • You need to defined the action="j_security_check" in the h:form as onsubmit="document.getElementById('login').action='j_security_check';"
  • Set the ajax attribute of the p:commandButton to false, so that the form doesn't get submitted in ajax way.

就是这样。这里是可以通过上述的形式被替换的登录表单的完整code:

That's it. Here is the complete code of the login form which can be replaced by the aforesaid form:

<h:form id="login" onsubmit="document.getElementById('login').action='j_security_check';" prependId="false">
    <h:panelGrid columns="2">
        <p:outputLabel for="j_username" value="Username" />
        <p:inputText id="j_username" name="j_username" />            
        <p:outputLabel for="j_password" value="Password" />
        <p:password id="j_password" name="j_password"/>
        <p:commandButton id="submit" value="Login" ajax="false"/>
    </h:panelGrid>
</h:form>

感谢。

这篇关于j_security_check与Primefaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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