user1352643
user1352643

Reputation: 39

It is possible to redirect to two different pages in pages.xml?

mi question is based in redirecting to one page or another according to a value passed by URL in SEAM. For example: I have this link that passes some parameters in URL:

http://localhost:8080/Refund/home.seam?user=012012&name=john&auth_level=4

in the seam pages.xml file, i have this configuration:

<page view-id="/home.xhtml" >
    <action if="#{authenticator.limpiar}" execute="#{identity.login}"  />
                <param name="user" value="#{user.number}" />
                <param name="name" value="#{user.name}" />
                <param name="auth_level" value="#{user.authLevel}" />

    <navigation from-action="#{identity.login}" >
            <rule if="#{identity.loggedIn}" >
                    <redirect view-id="/pages/page1.xhtml" />
            </rule>
            <rule if="#{not identity.loggedIn}">
                    <redirect view-id="/errorLogin.xhtml"/>
            </rule>
    </navigation>
</page>

but now i have another parameter to add to this URL. this parameter is "emp_id" and could take the value 1 or 15. so the url now is:

http://localhost:8080/Refund/home.seam?user=012012&name=john&auth_level=4&emp_id=X where X can take 1 or 15.

depending on what number takes, it must redirect to a one page or another (page1.xhtml or page2.xhtml), but i cant figure out how to do this in the pages.xml file.

please can anyone give some trick to do this? or another solution?

THANKS!!!!!

Upvotes: 1

Views: 1294

Answers (2)

Dario Pedol
Dario Pedol

Reputation: 2110

This should be possible if you assign the parameter to a param first. Try this:

<page view-id="/home.xhtml" >
    <action if="#{authenticator.limpiar}" execute="#{identity.login}"  />
                <param name="user" value="#{user.number}" />
                <param name="name" value="#{user.name}" />
                <param name="auth_level" value="#{user.authLevel}" />
    <param name="emp_id" value="#{somebean.emp_id}"/>
    <navigation from-action="#{identity.login}" >
            <rule if="#{identity.loggedIn}" >
                    <redirect view-id="/pages/page1.xhtml" />
            </rule>
            <rule if="#{not identity.loggedIn}">
                    <redirect view-id="/errorLogin.xhtml"/>
            </rule>
            <rule if="#{somebean.emp_id eq '1'}"><!-- use eq if emp_id is a string -->
                    <redirect view-id="/yourview.xhtml"/>
            </rule>
    </navigation>
</page>

I think I used something similiar once, but don't have a setup now to test it. I do, however, think that you should consider something else, like redirecting to a view, passing emp_id as a parameter and then using rewrite rules to make a nice url.

Upvotes: 2

Luca
Luca

Reputation: 4273

You can always execute a custom action (es. execute="#{redirectAction.go}") and manually redirect users. In seam way:

 Redirect redirect = Redirect.getInstance();
 redirect.setViewId("...")

In standard way:

FacesContext.getCurrentInstance().getExternalContext().redirect("...");

Upvotes: 2

Related Questions