You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Andrew Robinson <an...@gmail.com> on 2008/08/01 01:19:57 UTC

Re: jsf-comp Onload Question

> 1.  Andrew:  Back in 2007 there was a posting between you and mraible about
> getting the OnLoad components built with maven so they would be available
> on the maven repo.  Did this occur?  I looked in the repo but only found
> http://repo1.maven.org/maven2/net/sourceforge/jsf-comp/acegi-jsf/.

I never maven'd the project. I have no idea if anyone ever uploaded
the jars to central. I may look into it, but it could be a while

> 1a. If it was built, are the components stored in another repo?

Not by me. I hadn't learned maven yet when I made this project, so it
is ANT based

> 2.  I ran a test where I extended the beforeHandleNavigation function and
> returned false; however, the navigation continued to the index.jspx page.
> What is the purpose of the boolean returned from beforeHandleNavigation?  I
> expected it to stay on the same page with false.

That is odd. Looking at line 204, I don't see how that could happen.
Did you debug into it to see it being called?

http://jsf-comp.svn.sourceforge.net/viewvc/jsf-comp/trunk/extensions/jsfExt/src/net/sf/jsfcomp/ext/onload/OnLoadPhaseListener.java?view=markup

> 3.  Is there an advantage of setting the "success-result" setting in
> onload-config.xml?

Better performance as the result doesn't have to be passed through the
navigation handler

> 3a. Does it bypass the face-config.xml navigation rule on the view-id check
> when success-result matches the outcome of action?

Yes, the navigation handler is never invoked (see line 201 of the PhaseListener)

> 4.  Is the "action" variable in onload-config.xml EL?

The action to execute (EL that points to an action method)

> 4a. If I set the action to the following: #{scoreController.score1} I get a
> javax.faces.el.MethodNotFoundException because it is trying to access:
> ScoreController@b03512.score1().  If I use the full function name
> getScore1(), this it works correctly.  Do I have something setup
> incorrectly?

It is an action method, not a property. So use the same syntax as you
would with <h:commandButton action="#{ some action method here }" />

> Thank you again for helping me get this going.

You're welcome, hope it works out for you.

>
> -Nate
>

Re: jsf-comp Onload Question

Posted by rs...@stoddardsoftware.com.
> For example:
> 
> 1) user visits page1.jspx
> 2) onload called
> 3) page1.jspx rendered
> 4) user clicks an action button
> 5) action on button triggers navigation to page2.jspx
> 6) onload called

Ah, I understand the page change sequencing now, and I see how returning
false can only bypass navigation rules and not redirect.  Sorry it took me
so long.  



Thanks again for all the help.

-Nate

Ps.  Let me know if you change your mind on the Maven 2 help.






Re: jsf-comp Onload Question

Posted by Andrew Robinson <an...@gmail.com>.
> Shouldn't the viewId be /index.jspx if that is the page I'm trying to load?
>  I thought OnLoad executed during the loading of the target page?  If I'm
> on page3.jspx, then I click the link to go to index.jspx shouldn't the
> onload rules for index.jspx be executed?

Yes, but you need to intercept *before* the view ID is changed. The
onload component is executed *after* the view ID has been changed.

For example:

1) user visits page1.jspx
2) onload called
3) page1.jspx rendered
4) user clicks an action button
5) action on button triggers navigation to page2.jspx
6) onload called

As you can see, the on-load is called when the new view ID is about to
be rendered, not when the code is attempting to change the view to
page2.jspx.

I have implemented this type of security in JSF using a custom view
handler. In the ViewHandler.createView method, you can check some
value (some type of authentication check) and if it fails, then change
the view. Pseudo code:

MyCustomViewHandler:
  createView:
    if view ID is not the login page then
      check if logged in
        if not, change the view ID to the login page
    call super create view

This way the security is applied when the view is created, not after.
The main use case of the on-load component is more for lazy loading
data. I personally used it to load data from the database. So for
example, the user goes to a page that was bookmarked that has a list
of records. Since there is no action method, you would have to load
the data in a getter method. I didn't like that as the loading of the
data could result in an exception, and you cannot redirect after the
rendering of the page has started. So instead, I would load the
records using the on-load phase listener and if an exception occurred,
I could redirect them to a "safe" page that would not fail.

I also used it to redirect from pages that should not be bookmarked.
Say you have a wizard, and the user bookmarked page 2. Then using
on-load I could redirect the user back to page 1 from page 2 when I
see that the backing bean for page 1 was not populated.

-Andrew

Re: jsf-comp Onload Question

Posted by rs...@stoddardsoftware.com.
>> Here are the log results if I return "false"....
>>  Starting page:   /page3.jspx
>>
>>   09:49:20 DEBUG GC   Processing on load of view /index.jspx
>>   09:49:20 DEBUG GC   Looking for rule for view /index.jspx
>>   09:49:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
>>   09:49:20 INFO  GC   Found rule with exact match
>>   09:49:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
>>   09:49:20 INFO  JSF  Creating instance of
>> com.stoddardsoftware.golfclap.web.score.ScoreController
>>   09:49:20 INFO  GC   NATE:   beforeHandleNavigation called....
> returning
>> false.
>>   09:49:20 INFO  GC   Before handle navigation has aborted the on load
>> navigation
>>   09:49:20 INFO  JSF  Creating instance of
>> org.apache.myfaces.trinidad.model.XMLMenuModel
>>
>>  End page:   /index.jspx      ( I expected to be on /page3.jspx )
> 
> According to the log, the viewId is index.jspx, not page3.jspx. So to
> me it looks like it worked. It looks like something has already
> changed the view to "/index.jspx".

Shouldn't the viewId be /index.jspx if that is the page I'm trying to load?
 I thought OnLoad executed during the loading of the target page?  If I'm
on page3.jspx, then I click the link to go to index.jspx shouldn't the
onload rules for index.jspx be executed?

-Nate


Re: jsf-comp Onload Question

Posted by Andrew Robinson <an...@gmail.com>.
On Fri, Aug 1, 2008 at 9:04 AM,  <rs...@stoddardsoftware.com> wrote:
>
>> I never maven'd the project. I have no idea if anyone ever uploaded
>> the jars to central. I may look into it, but it could be a while
>
> I'm not a Maven guru by any means, but I would be willing to help.  If you
> are interested, we can take that conversation offline.

I know maven now, just need to find time to do the conversion

>> That is odd. Looking at line 204, I don't see how that could happen.
>> Did you debug into it to see it being called?
>
> When I return "false", I see that debug message and the info message I put
> into my beforeHandleNavigation function; however, I'm still taken to the
> index.jspx page.  If I return "true" from the beforeHandleNavigation
> function, it am sent to the login.jspx page because the index.jspx
> navigation rules are processed.
>
> Here are the log results if I return "false"....
>  Starting page:   /page3.jspx
>
>   09:49:20 DEBUG GC   Processing on load of view /index.jspx
>   09:49:20 DEBUG GC   Looking for rule for view /index.jspx
>   09:49:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
>   09:49:20 INFO  GC   Found rule with exact match
>   09:49:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
>   09:49:20 INFO  JSF  Creating instance of
> com.stoddardsoftware.golfclap.web.score.ScoreController
>   09:49:20 INFO  GC   NATE:   beforeHandleNavigation called.... returning
> false.
>   09:49:20 INFO  GC   Before handle navigation has aborted the on load
> navigation
>   09:49:20 INFO  JSF  Creating instance of
> org.apache.myfaces.trinidad.model.XMLMenuModel
>
>  End page:   /index.jspx      ( I expected to be on /page3.jspx )

According to the log, the viewId is index.jspx, not page3.jspx. So to
me it looks like it worked. It looks like something has already
changed the view to "/index.jspx".

Re: jsf-comp Onload Question

Posted by rs...@stoddardsoftware.com.
> I never maven'd the project. I have no idea if anyone ever uploaded
> the jars to central. I may look into it, but it could be a while

I'm not a Maven guru by any means, but I would be willing to help.  If you
are interested, we can take that conversation offline.



> That is odd. Looking at line 204, I don't see how that could happen.
> Did you debug into it to see it being called?

When I return "false", I see that debug message and the info message I put
into my beforeHandleNavigation function; however, I'm still taken to the
index.jspx page.  If I return "true" from the beforeHandleNavigation
function, it am sent to the login.jspx page because the index.jspx
navigation rules are processed.

Here are the log results if I return "false"....
  Starting page:   /page3.jspx 

   09:49:20 DEBUG GC   Processing on load of view /index.jspx
   09:49:20 DEBUG GC   Looking for rule for view /index.jspx
   09:49:20 DEBUG GC   Checking for exact match. Rule view: /index.jspx
   09:49:20 INFO  GC   Found rule with exact match
   09:49:20 DEBUG GC   Invoking action: #{scoreController.getScore1}
   09:49:20 INFO  JSF  Creating instance of
com.stoddardsoftware.golfclap.web.score.ScoreController
   09:49:20 INFO  GC   NATE:   beforeHandleNavigation called.... returning
false.
   09:49:20 INFO  GC   Before handle navigation has aborted the on load
navigation
   09:49:20 INFO  JSF  Creating instance of
org.apache.myfaces.trinidad.model.XMLMenuModel

  End page:   /index.jspx      ( I expected to be on /page3.jspx )

Here are the log results if I return "true"....
  Starting page:   page3.jspx 

   09:53:57 DEBUG GC   Processing on load of view /index.jspx
   09:53:57 DEBUG GC   Looking for rule for view /index.jspx
   09:53:57 DEBUG GC   Checking for exact match. Rule view: /index.jspx
   09:53:57 INFO  GC   Found rule with exact match
   09:53:57 DEBUG GC   Invoking action: #{scoreController.getScore1}
   09:53:57 INFO  JSF  Creating instance of
com.stoddardsoftware.golfclap.web.score.ScoreController
   09:53:57 INFO  GC   NATE:   beforeHandleNavigation called.... returning
true
   09:53:57 DEBUG GC   Calling navigation handler with result:
userrequireslogin
   09:53:57 INFO  JSF  Creating instance of
org.apache.myfaces.trinidad.model.XMLMenuModel

  End page:   /login.jspx



> It is an action method, not a property. So use the same syntax as you
> would with <h:commandButton action="#{ some action method here }" />

I should have known that. :)


Thanks.

-Nate