如何获得我的bean的用户名propriete

时间:2013-04-24 16:51:55

标签: jsf-2 spring-security

Hello Stackoverflow社区:)

我有一点时间在一个小型的jsf应用程序上工作。 现在我将spring security安全集成到我的jsf上...我用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.username的用户名loginbean。

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

@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接口

我必须要获取此用户的名字!请帮帮我

1 个答案:

答案 0 :(得分:0)

<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>