如何根据相应控制器中的JSF页面初始化的查询参数导航到不同页面


@Factory("loginContext")
@Begin(join = true)
public LoginContext initLoginContext() {
    if (loginContext == null) {
      loginContext = new LoginContext();
    }
    loginContext.setLanguageCode(LocaleSelector.instance().getLanguage());
    checkEnvironment();
    Map<String,String> requestParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String prodCode=requestParams.get("prodCode");
    String token=requestParams.get("token");
    //token validation
    if (token.equals("admin")) {
        System.out.println("admin page");
    } else if (token.equals("user")) {
        System.out.println("user page");
    } else {
        return loginContext;
    }
}

在这里,我将在令牌(JWE字符串(中获取用户凭据,然后完成对用户的一些验证(直到这里代码很好,我很清楚如何执行此操作(。稍后,根据用户特权,我将直接导航到用户的相关页面(而不是加载与控制器相关的登录页面(

我被困在这里,请建议一些东西

在logincontroller中我添加了以下对我有用的代码。:

@Factory("loginContext")
@Begin(join = true)
public LoginContext initLoginContext() {
if (loginContext == null) {
  loginContext = new LoginContext();
}
loginContext.setLanguageCode(LocaleSelector.instance().getLanguage());    
Map<String,String> requestParams = 
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String prodCode=requestParams.get("prodCode");
String token=requestParams.get("token");
//token validation
loginContext.setToken(token);
loginContext.setProductCode(prodCode);
return loginContext; 
 }
@Factory(value = "redirectWelcome", autoCreate = true, scope = ScopeType.EVENT)
  public boolean isRedirectWelcome()
{
boolean welRet=false;
if(loginContext.isLoggedIn()==false)
{
String loginReturn=login();// login is customized method as per my requirement
if(loginReturn.equals("loggedIn"))
{
  FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(),
      null, "/myservice/auth/showWelcome/welcome.jspx?faces-redirect=true");
  loginContext.setLoggedIn(true);
  welRet=true;
}}
return welRet;
}

然后在JSP页面(login.jspx(中,我在身体中添加了以下内容。

<h:outputText value="Login  bypass..." rendered="#{loginController.redirectWelcome}" />

最新更新