You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by JS Portal Support <su...@jsportal.com> on 2007/01/24 03:16:47 UTC

Starting A DialogContext Programmatically

Hi,

I have a ViewController which in it's prerender checks if the user in the
session is logged or not. If not, I want to start a subdialog logging the
user in.

On page http://shale.apache.org/shale-dialog/index.html at: "Starting A
DialogContext Programmatically" it is described how I can do this. I don't
understand it though. Do I need to build my own DialogContextManager and
DialogContext as they seem to be interfaces? Or are there implementations I
can use, and if so, where can I find them? An example would be great!

By the way, is this a good architecture approach, checking the logged status
on prerender and preprocess? Or are there other better ways to do this?

Thanks,
Joost Schouten



RE: Starting A DialogContext Programmatically

Posted by JS Portal Support <su...@jsportal.com>.
Hi, great help and making slow progress. I've been breaking my head all day
on this programmatic dialog though.

When I start my dialog though a commandLink, all goes fine, and this is what
my log shows (jsportal=debug and org.apache.shale=debug altered for email a
bit):

(Logon.java:144)Logon will return authenticated
(BasicDialogContext.java:363) - advance(id=1, name=AuthenticateUser,
outcome=authenticated)
(jsportal.PortalBaseViewController.java:146) - findStoredView() called. View
stored:
(jsportal.PortalBaseViewController.java:153)no_view_stored will be returned
as no STORED_VIEW is found
(BasicDialogContext.java:523) - stop(id=1, name=null)
(ViewViewHandler.java:282) - setupViewController(/jsp/dashboard.jsp,false)
.... all doing what it should do as defined in my below dialog[1]

When I start the AuthenticateUser programmatically the user gets nicely
redirected to the logon.jsf when not logged. Then after logon, no further
execution of the dialog seems to happen. My log shows of this situation:

(Logon.java:144) - Logon will return authenticated
(LifecycleListener.java:604) -
ServletRequestAttributeRemoved(org.apache.shale.view.PHASE_ID,INVOKE_APPLICA
TION(5))
(LifecycleListener.java:538) -
ServletRequestAttributeAdded(org.apache.shale.view.PHASE_ID,RENDER_RESPONSE(
6))
(PortalBaseViewController.java:92) - prerender() called on:
com.jsportal.projectportal.web.JSFaces.Logon
.... and just the logon will be shown again with that difference manual
navigation to the dashboard.jsf will now be permitted because I'm logged.

I'm lost and don't know what else to try after about 8 hours of banging my
head on the keyboard ;-)


Thanks
Joost

[1] dialog:
<dialog name="AuthenticateUser" start="CheckLogged">
  	<action name="CheckLogged" method="#{logon.isLogged}">
      <transition outcome="not_logged" target="LogonPage"/>
      <transition outcome="logged" target="FindStoredView"/>
    </action>
  	<view name="LogonPage" viewId="/logon.jsp">
		<transition outcome="authenticated"
target="FindStoredView"/>
      	<transition outcome="unauthenticated" target="LogonPage"/>
	  	<transition outcome="discontinued_account"
target="LogonPage"/>
	</view>
	<action name="FindStoredView" method="#{logon.findStoredView}">
		<!--if it holds the stored view, it will navigate there from
the holdsStoredView method-->
      <transition outcome="holds_stored_view" target="Exit"/>
      <transition outcome="no_view_stored" target="Enter"/>
    </action>
	<end name="Enter" viewId="/jsp/dashboard.jsp"/>
	<end name="Exit"/>
  </dialog>

-----Original Message-----
From: craigmcc@gmail.com [mailto:craigmcc@gmail.com] On Behalf Of Craig
McClanahan
Sent: Thursday, January 25, 2007 5:22 AM
To: user@shale.apache.org
Subject: Re: Starting A DialogContext Programmatically

On 1/24/07, JS Portal Support <su...@jsportal.com> wrote:
>
> Okay,
>
> For some reason my shale jar's didn't have the DialogContextManager and
> DialogContext interfaces in them. I downloaded the latest 1.0.4 ;-) and
> that
> solved it. Now I can't get to my data anymore without logging in. Jeee!
>
> Is there a problem with the .getVariableResolver() being depreciated by
> the
> way? What would be the new preferred way?


The issues with using the getVariableResolver() approach are:

* The application is getting involved with the internal "plumbing" of the
  implementation, including depending on the managed beans facility
  to create the manager if it does not exist.

* The application is required to be aware of the key under which the
  DialogContextManager is stored, and what scope it is in.

* Because the knowledge is scattered all over an application, it would
  be essentially impossible to modify the technique inside the framework.

In 1.0.4, the approach I described is the only one that works, and it will
continue to work in later versions.  In the nightly builds, last night I
checked in a helper class that makes life a lot easier:

    public class DialogHelper {

        // Return the active DialogContext (if any)
        public static DialogContext getDialogContext();
        public static DialogContext getDialogContext(FacesContext context);

        // Return the DialogContextManager, creating if needed
        public static DIalogContextManager getDialogContextManager();
        public static DialogContextManager
getDialogContextManager(FacesContext context);

    }

so you end up with very simple calls like:

    DialogContextManager manager = DialogHelper.getDialogContextManager();

with all the implementation details hidden away.

> I haven't personally tested whether you can successfully navigate (say, to
> >a login page) from the prerender() method.
> It works. When a user tries to access without being logged, the
> Authenticate
> dialog is started from the prerender. But now, how can I make my user
> return
> to the initial view which started up the Authenticate dialog. The user
> gets
> logged on but gets to see the logon.jsp once the Authenticate dialog is
> done. Is there a way to create a dialog programmatically, like you
> described, moving the user to the view on which prerender is called and
> then
> set the Authenticate as a child so that after authenticate, the user will
> be
> redirected back to the initial view?


Something along the following lines ought to work:

* In the view that starts the authentication dialog, save the view id in a
  session scope variable.

* At the end of the authentication dialog, execute an action method that
  looks up the saved view id (if any), and navigates programmatically
  instead of using a normal view state.

I hope I'm not too much of a burden using you as a climbing rope on my shale
> learning curve ;-)


Nah, it is fun to answer interesting questions :-)

Cheers,
> Joost


Craig


Re: Starting A DialogContext Programmatically

Posted by Craig McClanahan <cr...@apache.org>.
On 1/24/07, JS Portal Support <su...@jsportal.com> wrote:
>
> Okay,
>
> For some reason my shale jar's didn't have the DialogContextManager and
> DialogContext interfaces in them. I downloaded the latest 1.0.4 ;-) and
> that
> solved it. Now I can't get to my data anymore without logging in. Jeee!
>
> Is there a problem with the .getVariableResolver() being depreciated by
> the
> way? What would be the new preferred way?


The issues with using the getVariableResolver() approach are:

* The application is getting involved with the internal "plumbing" of the
  implementation, including depending on the managed beans facility
  to create the manager if it does not exist.

* The application is required to be aware of the key under which the
  DialogContextManager is stored, and what scope it is in.

* Because the knowledge is scattered all over an application, it would
  be essentially impossible to modify the technique inside the framework.

In 1.0.4, the approach I described is the only one that works, and it will
continue to work in later versions.  In the nightly builds, last night I
checked in a helper class that makes life a lot easier:

    public class DialogHelper {

        // Return the active DialogContext (if any)
        public static DialogContext getDialogContext();
        public static DialogContext getDialogContext(FacesContext context);

        // Return the DialogContextManager, creating if needed
        public static DIalogContextManager getDialogContextManager();
        public static DialogContextManager
getDialogContextManager(FacesContext context);

    }

so you end up with very simple calls like:

    DialogContextManager manager = DialogHelper.getDialogContextManager();

with all the implementation details hidden away.

> I haven't personally tested whether you can successfully navigate (say, to
> >a login page) from the prerender() method.
> It works. When a user tries to access without being logged, the
> Authenticate
> dialog is started from the prerender. But now, how can I make my user
> return
> to the initial view which started up the Authenticate dialog. The user
> gets
> logged on but gets to see the logon.jsp once the Authenticate dialog is
> done. Is there a way to create a dialog programmatically, like you
> described, moving the user to the view on which prerender is called and
> then
> set the Authenticate as a child so that after authenticate, the user will
> be
> redirected back to the initial view?


Something along the following lines ought to work:

* In the view that starts the authentication dialog, save the view id in a
  session scope variable.

* At the end of the authentication dialog, execute an action method that
  looks up the saved view id (if any), and navigates programmatically
  instead of using a normal view state.

I hope I'm not too much of a burden using you as a climbing rope on my shale
> learning curve ;-)


Nah, it is fun to answer interesting questions :-)

Cheers,
> Joost


Craig

RE: Starting A DialogContext Programmatically

Posted by JS Portal Support <su...@jsportal.com>.
Okay,

For some reason my shale jar's didn't have the DialogContextManager and
DialogContext interfaces in them. I downloaded the latest 1.0.4 ;-) and that
solved it. Now I can't get to my data anymore without logging in. Jeee!

Is there a problem with the .getVariableResolver() being depreciated by the
way? What would be the new preferred way?

> I haven't personally tested whether you can successfully navigate (say, to
>a login page) from the prerender() method.
It works. When a user tries to access without being logged, the Authenticate
dialog is started from the prerender. But now, how can I make my user return
to the initial view which started up the Authenticate dialog. The user gets
logged on but gets to see the logon.jsp once the Authenticate dialog is
done. Is there a way to create a dialog programmatically, like you
described, moving the user to the view on which prerender is called and then
set the Authenticate as a child so that after authenticate, the user will be
redirected back to the initial view?

I hope I'm not too much of a burden using you as a climbing rope on my shale
learning curve ;-)

Cheers,
Joost
JS Portal
Dasstraat 21
2623CB Delft
the Netherlands
W: www.jsportal.com
-----Original Message-----
From: craigmcc@gmail.com [mailto:craigmcc@gmail.com] On Behalf Of Craig
McClanahan
Sent: Wednesday, January 24, 2007 4:53 PM
To: user@shale.apache.org
Subject: Re: Starting A DialogContext Programmatically

On 1/23/07, JS Portal Support <su...@jsportal.com> wrote:
>
> Hi,
>
> I have a ViewController which in it's prerender checks if the user in the
> session is logged or not. If not, I want to start a subdialog logging the
> user in.
>
> On page http://shale.apache.org/shale-dialog/index.html at: "Starting A
> DialogContext Programmatically" it is described how I can do this. I don't
> understand it though. Do I need to build my own DialogContextManager and
> DialogContext as they seem to be interfaces? Or are there implementations
> I
> can use, and if so, where can I find them? An example would be great!


The "shale-test-dialog-basic" and "shale-test-dialog-scxml" test webapps
(they are built nightly along with the framework) have an example of this
use case.  One nice feature is that the application coding is the same no
matter which implementation you use.

The DialogContextManager instance is created for you by the framework, so
all you will need to do is acquire a reference to it, and then ask it to
create you a DialogContext instance like this:

    FacesContext context = FacesContext.getCurrentInstance();
    DialogContextManager manager = (DialogContextManager)
      context.getApplication().getVariableResolver().
      resolveVariable(context, Constants.MANAGER_BEAN);
    DialogContext dcontext = manager.create(context, "myDialogName");
    dcontext.start(context);

You do not have to do anything else about storing the DialogContext
instance, because the manager will have taken care of that for you.

By the way, the reason for using the variable resolver, in the code example
above, is because the dialog framework defines the manager as a managed
bean.  Doing things this way (instead of just checking the write scoped
attributes) causes the manager to be created if it does not already exist.


By the way, is this a good architecture approach, checking the logged status
> on prerender and preprocess? Or are there other better ways to do this?


The only thing I would be concerned about is navigation -- I haven't
personally tested whether you can successfully navigate (say, to a login
page) from the prerender() method.  If that works for you, then this seems
like a reasonable approach.

Thanks,
> Joost Schouten
>
>
>
Craig


Re: Starting A DialogContext Programmatically

Posted by Craig McClanahan <cr...@apache.org>.
On 1/23/07, JS Portal Support <su...@jsportal.com> wrote:
>
> Hi,
>
> I have a ViewController which in it's prerender checks if the user in the
> session is logged or not. If not, I want to start a subdialog logging the
> user in.
>
> On page http://shale.apache.org/shale-dialog/index.html at: "Starting A
> DialogContext Programmatically" it is described how I can do this. I don't
> understand it though. Do I need to build my own DialogContextManager and
> DialogContext as they seem to be interfaces? Or are there implementations
> I
> can use, and if so, where can I find them? An example would be great!


The "shale-test-dialog-basic" and "shale-test-dialog-scxml" test webapps
(they are built nightly along with the framework) have an example of this
use case.  One nice feature is that the application coding is the same no
matter which implementation you use.

The DialogContextManager instance is created for you by the framework, so
all you will need to do is acquire a reference to it, and then ask it to
create you a DialogContext instance like this:

    FacesContext context = FacesContext.getCurrentInstance();
    DialogContextManager manager = (DialogContextManager)
      context.getApplication().getVariableResolver().
      resolveVariable(context, Constants.MANAGER_BEAN);
    DialogContext dcontext = manager.create(context, "myDialogName");
    dcontext.start(context);

You do not have to do anything else about storing the DialogContext
instance, because the manager will have taken care of that for you.

By the way, the reason for using the variable resolver, in the code example
above, is because the dialog framework defines the manager as a managed
bean.  Doing things this way (instead of just checking the write scoped
attributes) causes the manager to be created if it does not already exist.


By the way, is this a good architecture approach, checking the logged status
> on prerender and preprocess? Or are there other better ways to do this?


The only thing I would be concerned about is navigation -- I haven't
personally tested whether you can successfully navigate (say, to a login
page) from the prerender() method.  If that works for you, then this seems
like a reasonable approach.

Thanks,
> Joost Schouten
>
>
>
Craig