0

你好 Stackoverflow 社区 :)

我有一点时间在一个小的 jsf 应用程序上工作。现在我在我的jsf上集成了spring security ...我用spring security标签“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";

    }

我的问题是填充页面时没有满足username属性..当我没有使用带有这些j-usernme和j_password的spring认证接口时它已满

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

4

1 回答 1

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>
于 2013-04-25T15:44:15.300 回答