You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by rs...@stoddardsoftware.com on 2008/07/31 17:35:12 UTC

jsf-comp Onload Question

Hello,

I have been looking for a solution that will allow me to check if a user
has been logged in before I load a page.  If the user is not logged in, or
the session has timed out, I want to send the user to the login page.   In
my searching if found the jsf-comp onload project.  From the outside this
looks exactly like what I want; however, I have been having problems
implementing it.

I'm running JSF 1.2, Tomcat 6, and Apache Trinidad 1.2.8.  I have created a
onload-config.xml and installed the jsfNet 0.9.0 jar.  I'm using the
Trinidad XMLMenu for my menuing, and in the top menu the destination
attribute is used instead of the action attribute.

I get the following logs from OnLoad when I start my webapp:
  18:53:20 INFO  GC   On Load configuration is being loaded from
/WEB-INF/onload-config.xml
  18:53:20 INFO  GC   2 rule(s) have been found
  18:53:20 DEBUG GC   Rule: view-id: /index.jspx, action:
#{scoreController.getScore1}, success-result: null
  18:53:20 DEBUG GC   Rule: view-id: /faces/page*, action:
#{scoreController.score99}, success-result: 9

Now when I go to index.jspx, I want to check if the user is logged in.  For
my test I am using the scoreController object returns "1" as a string from
getScore1.  I tried setting success-result to null, "1", and "9", but not
matter what I set it too the navigation always goes to index.jspx.   As a
test I tried extending OnLoadPhaseListener's  beforeHandleNavigation
function and returning false, but that didn't work either.

Here are the logs I get when I I click "index.jspx" menu.  (In this test
run I have success-result set to null).
  18:53:20 DEBUG GC   Processing on load of view /index.jspx
  18:53:20 DEBUG GC   Looking for rule for view /index.jspx
  18:53:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
  18:53:20 INFO  GC   Found rule with exact match
  18:53:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
  18:53:20 INFO  JSF  Using LifecycleProvider
org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider
  18:53:20 INFO  JSF  Creating instance of
com.stoddardsoftware.golfclap.web.score.ScoreController
  18:53:20 INFO  GC   NATE TEST:  processing beforeHandleNavigation now...
  18:53:20 DEBUG GC   Calling navigation handler with result: 1
  18:53:23 INFO  JSF  Creating instance of
org.apache.myfaces.trinidad.model.XMLMenuModel

At this point I'm out of ideas.  Can someone show me an example of how to
check if my user is logged in and then redirect to the login page if they
are not?  Can this be done completely from onload-config.xml or will I need
to extend OnLoadPhaseListener to redirect?

Thank you for taking the time to help.

-Nate


Re: jsf-comp Onload Question

Posted by Andrew Robinson <an...@gmail.com>.
What are your navigation rules in your faces-config for outcomes 1 and 9?

On Thu, Jul 31, 2008 at 9:35 AM,  <rs...@stoddardsoftware.com> wrote:
> Hello,
>
> I have been looking for a solution that will allow me to check if a user
> has been logged in before I load a page.  If the user is not logged in, or
> the session has timed out, I want to send the user to the login page.   In
> my searching if found the jsf-comp onload project.  From the outside this
> looks exactly like what I want; however, I have been having problems
> implementing it.
>
> I'm running JSF 1.2, Tomcat 6, and Apache Trinidad 1.2.8.  I have created a
> onload-config.xml and installed the jsfNet 0.9.0 jar.  I'm using the
> Trinidad XMLMenu for my menuing, and in the top menu the destination
> attribute is used instead of the action attribute.
>
> I get the following logs from OnLoad when I start my webapp:
>  18:53:20 INFO  GC   On Load configuration is being loaded from
> /WEB-INF/onload-config.xml
>  18:53:20 INFO  GC   2 rule(s) have been found
>  18:53:20 DEBUG GC   Rule: view-id: /index.jspx, action:
> #{scoreController.getScore1}, success-result: null
>  18:53:20 DEBUG GC   Rule: view-id: /faces/page*, action:
> #{scoreController.score99}, success-result: 9
>
> Now when I go to index.jspx, I want to check if the user is logged in.  For
> my test I am using the scoreController object returns "1" as a string from
> getScore1.  I tried setting success-result to null, "1", and "9", but not
> matter what I set it too the navigation always goes to index.jspx.   As a
> test I tried extending OnLoadPhaseListener's  beforeHandleNavigation
> function and returning false, but that didn't work either.
>
> Here are the logs I get when I I click "index.jspx" menu.  (In this test
> run I have success-result set to null).
>  18:53:20 DEBUG GC   Processing on load of view /index.jspx
>  18:53:20 DEBUG GC   Looking for rule for view /index.jspx
>  18:53:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
>  18:53:20 INFO  GC   Found rule with exact match
>  18:53:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
>  18:53:20 INFO  JSF  Using LifecycleProvider
> org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider
>  18:53:20 INFO  JSF  Creating instance of
> com.stoddardsoftware.golfclap.web.score.ScoreController
>  18:53:20 INFO  GC   NATE TEST:  processing beforeHandleNavigation now...
>  18:53:20 DEBUG GC   Calling navigation handler with result: 1
>  18:53:23 INFO  JSF  Creating instance of
> org.apache.myfaces.trinidad.model.XMLMenuModel
>
> At this point I'm out of ideas.  Can someone show me an example of how to
> check if my user is logged in and then redirect to the login page if they
> are not?  Can this be done completely from onload-config.xml or will I need
> to extend OnLoadPhaseListener to redirect?
>
> Thank you for taking the time to help.
>
> -Nate
>
>

Re: jsf-comp Onload Question

Posted by Richard Yee <ri...@gmail.com>.
Have you considered using a servlet filter? You have have it check for
a session variable or cookie.

-R

On 7/31/08, rsf@stoddardsoftware.com <rs...@stoddardsoftware.com> wrote:
> Hello,
>
> I have been looking for a solution that will allow me to check if a user
> has been logged in before I load a page.  If the user is not logged in, or
> the session has timed out, I want to send the user to the login page.   In
> my searching if found the jsf-comp onload project.  From the outside this
> looks exactly like what I want; however, I have been having problems
> implementing it.
>
> I'm running JSF 1.2, Tomcat 6, and Apache Trinidad 1.2.8.  I have created a
> onload-config.xml and installed the jsfNet 0.9.0 jar.  I'm using the
> Trinidad XMLMenu for my menuing, and in the top menu the destination
> attribute is used instead of the action attribute.
>
> I get the following logs from OnLoad when I start my webapp:
>  18:53:20 INFO  GC   On Load configuration is being loaded from
> /WEB-INF/onload-config.xml
>  18:53:20 INFO  GC   2 rule(s) have been found
>  18:53:20 DEBUG GC   Rule: view-id: /index.jspx, action:
> #{scoreController.getScore1}, success-result: null
>  18:53:20 DEBUG GC   Rule: view-id: /faces/page*, action:
> #{scoreController.score99}, success-result: 9
>
> Now when I go to index.jspx, I want to check if the user is logged in.  For
> my test I am using the scoreController object returns "1" as a string from
> getScore1.  I tried setting success-result to null, "1", and "9", but not
> matter what I set it too the navigation always goes to index.jspx.   As a
> test I tried extending OnLoadPhaseListener's  beforeHandleNavigation
> function and returning false, but that didn't work either.
>
> Here are the logs I get when I I click "index.jspx" menu.  (In this test
> run I have success-result set to null).
>  18:53:20 DEBUG GC   Processing on load of view /index.jspx
>  18:53:20 DEBUG GC   Looking for rule for view /index.jspx
>  18:53:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
>  18:53:20 INFO  GC   Found rule with exact match
>  18:53:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
>  18:53:20 INFO  JSF  Using LifecycleProvider
> org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider
>  18:53:20 INFO  JSF  Creating instance of
> com.stoddardsoftware.golfclap.web.score.ScoreController
>  18:53:20 INFO  GC   NATE TEST:  processing beforeHandleNavigation now...
>  18:53:20 DEBUG GC   Calling navigation handler with result: 1
>  18:53:23 INFO  JSF  Creating instance of
> org.apache.myfaces.trinidad.model.XMLMenuModel
>
> At this point I'm out of ideas.  Can someone show me an example of how to
> check if my user is logged in and then redirect to the login page if they
> are not?  Can this be done completely from onload-config.xml or will I need
> to extend OnLoadPhaseListener to redirect?
>
> Thank you for taking the time to help.
>
> -Nate
>
>