Valter Silva
Valter Silva

Reputation: 16656

How to create links relative to the right context?

I have this composition :

<!DOCTYPE html>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"> 


    <h:panelGroup rendered="#{empty userc.userb.user.id}">
        <h:panelGrid columns="2" >
            <h:outputLink value="system/register.xhtml">Register</h:outputLink>
            <h:outputLink value="system/login.xhtml">Login</h:outputLink>
        </h:panelGrid>
    </h:panelGroup>

</ui:composition>   

If the user click in Login the page is redirect to system/login.xhtml, which is correct, but if the user, click in Login again, it is redirect to system/system/login.xhtml. I know a solution for this, which BalusC help me out a long time ago:

<base href="#{fn:replace(request.requestURL, fn:substring(request.requestURI, 1, fn:length(request.requestURI)), request.contextPath)}/" />

It solve my problem, but if I have some ManageBean instancied when I click in some link the bean it's invalidate.

How mantain the url path in every link page and keep the session in the Managed beans ?

Upvotes: 3

Views: 4252

Answers (1)

BalusC
BalusC

Reputation: 1109874

Use <h:link> instead. JSF will append the right context path and FacesServlet mapping.

<h:link value="Register" outcome="/system/register" />
<h:link value="Login" outcome="/system/login" />

See also:

Upvotes: 6

Related Questions