The action and faces-config configuration problem

Splash Forums PrettyFaces Users The action and faces-config configuration problem

This topic contains 1 reply, has 2 voices, and was last updated by  Lincoln Baxter III 5 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18113

    hantsy
    Participant

    In my project, there is a requirement like this.

    There is a login page, when user have been logged in, and browsed the login page, it should redirect to the user home instead of the login page.

    I used a action in the login view like this.

    <url-mapping id=”login” >

    <pattern value=”/login”></pattern>

    <view-id>/login.xhtml</view-id>

    <action>#{homeAction.detectSession}</action>

    </url-mapping>

    And detect session in the HomeAction bean.

    @Named(“homeAction”)

    @Scope(ScopeType.VIEW)

    public class HomeAction implements Serializable {

    private static final Logger log = LoggerFactory.getLogger(HomeAction.class);

    String redirectTo = “/index.xhtml”;

    public String detectSession() {

    Object currentUser = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(Constants.CURRENT_USER_SESSION_KEY);

    log.info(“@@@@@@@@currentUser@” + (currentUser != null));

    if (currentUser != null) {

    this.redirectTo = “/user/home”;

    }

    return this.redirectTo;

    }

    This solution can forward to user/home if user was logged in.

    1 .But when I appended a faces-redirect=true to the return string, it will cause a redirect error in browser.

    2. If I changed the HomeAction to the following.

    boolean redirected=false;

    public void detectSession() {

    Object currentUser = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(Constants.CURRENT_USER_SESSION_KEY);

    log.info(“@@@@@@@@currentUser@” + (currentUser != null));

    if (currentUser != null) {

    this.redirected=true;

    }

    }

    if I used a void return type and defined redrecited variable to determine if it is needed to redirect, and defined the rule in faces-config.xml.

    <navigation-rule>

    <from-view-id>/index.xhtml</from-view-id>

    <navigation-case>

    <from-action>#{homeAction.detectSession}</from-action>

    <if>#{homeAction.redirected}</if>

    <to-view-id>/user/home.xhtml</to-view-id>

    <redirect />

    </navigation-case>

    </navigation-rule>

    But this did not work.

    I used Tomcat 7.0.22, Majarro 2.1.4, PrettyFaces 3.3.0, Spring 3.0.5 Spring Security 3.0x in my project.

    Any suggestion is appreciated.

    #21781

    What is the error you receive when navigating ?faces-redirect=true?

    Doesn’t give us much to go on to say, “I got an error,” without the error ;) hehe. I’m sure we can figure this out though. This is commonly used functionality.

    ~Lincoln

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.