【问题标题】:haw can I do to get username proprite of my bean我该怎么做才能获得我的 bean 的用户名
【发布时间】:2013-04-18 08:17:25
【问题描述】:

你好 Stackoverflow 社区 :)

我有一点时间在一个小的 jsf 应用程序上工作。 现在我在我的 jsf 上集成了 spring security ...我用 spring 安全标签“j_username”更改了我的登录页面

<h:outputLabel for="j_username" value="User: * " />  
    <h:inputText id="j_username" required="true" label="username" ***value="#{loginBean.username}"***/>  
    <h:message for="j_username" display="text" style="color:red"/>

    <h:outputLabel for="j_password" value="Password: * " />  
    <h:inputSecret id="j_password" label="password" required="true" />  
    <h:message for="j_password" display="text" style="color:red"/>

    <p:commandButton type="submit" id="login" value="Login" ajax="false"
        action="#{loginBean.doLogin()}" />

我试图在 jsf 页面上恢复用户名 loginbean,其值为 # {} loginbean.username ..

因为我必须使用它在需要用户了解的页面中显示它

@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean {

    private String username;  

    private String password; 

public String getUsername() {  
        return username;  
    }  

    public void setUsername(String username) {  
        this.username = username;  
    }  

    public String getPassword() {  
        return password;  
    }  

    public void setPassword(String password) {  
        this.password = password;  
    }  
public String doLogin() throws ServletException, IOException {
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

        RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
                .getRequestDispatcher("/j_spring_security_check");

        dispatcher.forward((ServletRequest) context.getRequest(),
                (ServletResponse) context.getResponse());

        FacesContext.getCurrentInstance().responseComplete();

        return null;
    }


    public String dologout() {
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        return "/login.jsf";

    }

我的问题是填写时不满足用户名属性 页面..当我没有使用弹簧认证时它已经满了 与这些 j-usernme 和 j_password 接口

我必须得到这个用户的名字!请帮帮我

【问题讨论】:

  • 所以您在提交登录表单后没有在页面上获取用户名属性,对吧?
  • 是的,但我现在解决了问题

标签: jsf-2 spring-security


【解决方案1】:
<h:panelGrid columns="3">
    <h:outputLabel for="j_username" value="User: * " />  
    <h:inputText id="j_username" required="true" label="username" value="#{loginBean.username}"/>  
    <h:message for="j_username" display="text" style="color:red"/>

    <h:outputLabel for="j_password" value="Password: * " />  
    <h:inputSecret id="j_password" label="password" required="true"  value="#{loginBean.password}"/>  
    <h:message for="j_password" display="text" style="color:red"/>

    <h:outputLabel for="_spring_security_remember_me" value="Remember me: " />
    <h:selectBooleanCheckbox    id="_spring_security_remember_me" />        
    </h:panelGrid>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2014-11-03
    • 1970-01-01
    相关资源
    最近更新 更多