views:

734

answers:

1

I'm pretty new to JSF and the many many related technologies out there.

I'm trying to make a website that has a header which includes a logo, navigation links, and a login box, such that this header can easily be included in all of the site's pages unless the user logs in, in which case a different header will appear. Something similar to livejournal.

I've looked into a few solutions like creating a custom JSF component to handle login and combining that with JSP fragments and/or Facelets. But after a lot of Google searching, I haven't really found anyone who has tried to make a custom login component and information about creating a header like this is sparse. So is this really the right way to go about solving my problem? Is there a better solution?

Thanks in advance.

+1  A: 

I would definitely use Facelets as that will basically let you include the same header on each page.

In terms of a custom login component - it depends on how you're handling your login. If you're using JAAS or Spring Security you will need to integrate with them (it can be done).

However a login header needn't be difficult. For example, you could just do something like:

<h:form id="loginForm" rendered="#{! loginBean.loggedIn}">
    Username: <h:inputText id="username" value="#{loginBean.username}" />
    Password: <h:inputPassword id="password" value="#{loginBean.password}" />
    <h:commandButton value="Login" action="#{loginBean.login}" />
</h:form>
<h:outputText rendered="#{loginBean.loggedIn}" value="You are logged in as #{loginBean.username}" />
Phill Sacre
Thanks for the help. That works nicely :)
spadequack