You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Ingo Düppe <ma...@dueppe.com> on 2006/09/26 16:12:52 UTC
Remoting and Outcome
Hello,
I have defined a userActivate managed bean with a String perform() method.
This methods returns a faces outcome depending on the results during
execution.
Calling the method by /dynamic/userActivate/perform.jsf?code=XYZ works
fine, but what do I have to do that
shale evaluates the outcome of this method and displays the according views?
Regards
Ingo
Re: Remoting and Outcome
Posted by Matthias Wessendorf <ma...@apache.org>.
Ingo,
in Tobago there is a Servlet, called NonFacesRequestServlet, maybe
that helps you.
-M
[1]
http://myfaces.apache.org/tobago/tobago-core/apidocs/org/apache/myfaces/tobago/servlet/NonFacesRequestServlet.html
On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
> Hi Craig,
>
> guess you are right that the remoting is not the solution for my
> problem. What I like to realize is the following:
> - The user gets an email with a link to the webapp.
> - When the user click on this link an action method should decide
> whether the link is still valid or not.
> - If the link is still valid the user is redirected to the login page.
> - If not the user is redirected to a new request page.
>
> So what I need is a solution to trigger an action method by a get
> request that returns an outcome that is handled by jsf?
>
> My current solution is a configurable phaselistener that checks whether
> or not the requested link. If requested viewId is equal to a configured
> action the action method will be invoked and the outcome of the method
> will be analyzed by the navigation handler.
>
> Any simpler solution or maybe more jsf like solution is very welcomed.
>
> Regards
>
> Ingo
>
> Here is my action process method:
> ...
> final UIViewRoot view = facesContext.getViewRoot();
>
> final String viewId = view.getViewId();
> if (StringUtils.isNotBlank(viewId)) {
> for (PageAction action : actions) {
> if (action.matches(viewId)) {
> if (logger.isDebugEnabled()) {
> logger.debug("perform page action " +
> action.getAction());
> }
>
> final String outcome = action.perform(facesContext);
>
> if (outcome != null) {
> final Application application =
> facesContext.getApplication();
> NavigationHandler navigationHandler =
> application.getNavigationHandler();
> navigationHandler.handleNavigation(facesContext,
> action.getFromAction(), outcome);
> break;
> }
> }
> }
> }
>
>
> Craig McClanahan schrieb:
> > Sorry for the late response (I've been in an airplane a lot in the
> > last few
> > days). But I have a basic question for you.
> >
> > Why are you using Shale Remoting if you are expecting to navigate to a
> > new
> > page? The design purpose of these dynamic callbacks is to set up
> > handlers
> > for an asynchronous callback (such as from XmlHTTPRequest calls in an
> > AJAX
> > component). For that scenario, Shale Remoting expects your handler to:
> >
> > * Prepare the complete response (typically in XML or JSON or whatever).
> > The most convenient way is to get an appropriate ResponseWriter and
> > write all of the output.
> >
> > * Call FacesContext.responseComplete() to indicate to JSF that you have
> > already completed the response for this request, so Render Response
> > phase is skipped.
> >
> > On the other hand, a standard JSF request (i.e. the complete page
> > submit) is
> > passed through JSF navigation in the usual way, because the purpose of
> > the
> > response is to replace the *entire* page.
> >
> > So, based on this, it seems like you are trying to mix things that
> > were not
> > designed to be mixed.
> >
> > Craig
> >
>
>
--
Matthias Wessendorf
http://tinyurl.com/fmywh
further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com
Re: Remoting and Outcome
Posted by Ingo Düppe <ma...@dueppe.com>.
Hi Craig, Hi William,
William, I understood you that I could implement my feature by
implementing a new MethodBindingProcessor to extend the shale remoting
library.
That leads me into the discussion is it worst to extend the shale
remoting to general support this feature. Especially most of the needed
classes are already there.
As you mentioned one just need an additional MethodBindingProcessor (and
maybe an additional url prefix).
But I totally agree to Craig objection that adding this feature would
soften the original use case of shale remoting and it should be focused
on what it is aimed at.
Why I prefer an addition class is that I assume that the resulting pages
including the backing beans and the jsps in my scenario already exist.
And then I need an additional object to decide where the
none-jsf-request should be forward to. To keep up the separation of
concerns I divided my classes in ViewController and Actions.
ViewController aimed at controlling everything in a specific view (1:1
or 1:n). Actions aimed at processing external events like a
none-jsf-request.
As far as I understood I always need a jsp (or xhtml if using facelets
:-) to bind a ViewController to a url so that the lifecycle invokes the
ViewController methods.
So I like my solution with a PhaseListener and action classes because
I don't need any dummy jsps. I just configure the methods to be invoked
in a spring configuration file. Btw. I still can catch up the parameter
of request within my action classes.
To sum it up It would certainly be technically feasible to create
something like this. But Craig is right that extending the shale
remoting is the wrong place. Keeping things focused is always better.
But maybe we found another place to provide this feature to explicit
bind an url to a method of a backing bean that generates outcomes.
Regards
- Ingo
Craig McClanahan schrieb:
> On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
>>
>> Yes that would work too with the ViewController, but then I prefer my
>> solution.
>> Because you can write little action classes like this one.
>>
>> @bean(name="userActivate",scope=Scope.REQUEST)
>> class UserActivateAction {
>> // fill properties from param
>> public String activate() {
>> //do something
>> return "outcome"
>> }
>> }
>>
>> Why I would like to combine it with shale-remoting is the dynamic
>> interpretation of the request path like
>> /dynamic/userActivate/activate.faces. So I wouldn't need to define the
>> action path explicitly.
>>
>> To integrate such a solution in shale we need to define a new uri prefix
>> like "/dynamic" and a new Processor.
>
>
> It would certainly be technically feasible to create something like this,
> but I'm not convinced it will actually make your life easier :-).
>
> It sounds like you are proposing a scenario where you want to dynamically
> decide whether or not to forward to a particular page (based on
> expiration
> of "link validity" or on some other criteria). Your solution seems to
> require:
>
> * One Java class for the decision making logic
>
> * One Java class (backing bean) and a JSP (or whatever) for the actual
> content
> rendering, assuming that it has not expired yet.
>
> Whereas the solution I proposed embeds the "decision making logic" part
> *inside* the backing bean that you need to create anyway. Why make
> yourself
> write one more class?
>
> SIDE NOTE -- I am presuming that you would also want to map all
> requests for
> the same basic data to the same view identifier URL, instead of making
> up a
> unique one for each user). You can still customize the details of
> what gets
> returned by including request parameters in the emailed link ... those
> parameters can be used, for example, to select the correct data from the
> database, or implement whatever else you need to do to specialze the
> response for this particular user.
>
> So, you could end up with some URL like this:
>
> http://www.mycompany.com/myapp/dataQueryResults.faces?ticket=123456
>
> and, in the prerender() method, you'd grab the "ticket" parameter and
> use it
> to look up stuff from the database. You could even implement "you can
> only
> access this data once" type checks by updating the database data for this
> ticket identifier the first time it is accessed.
>
> But, the bottom line is, fewer classes makes for better, more
> maintainable,
> code. And, this keeps Shale Remoting focused on what it is aimed at --
> supporting asynchronous callbacks, not the entire JSF lifecycle
> (including
> navigation). The standard FacesServlet covers that need quite nicely
> already :-).
>
> Craig
>
> - Ingo
Re: Remoting and Outcome
Posted by Craig McClanahan <cr...@apache.org>.
On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
>
> Yes that would work too with the ViewController, but then I prefer my
> solution.
> Because you can write little action classes like this one.
>
> @bean(name="userActivate",scope=Scope.REQUEST)
> class UserActivateAction {
> // fill properties from param
> public String activate() {
> //do something
> return "outcome"
> }
> }
>
> Why I would like to combine it with shale-remoting is the dynamic
> interpretation of the request path like
> /dynamic/userActivate/activate.faces. So I wouldn't need to define the
> action path explicitly.
>
> To integrate such a solution in shale we need to define a new uri prefix
> like "/dynamic" and a new Processor.
It would certainly be technically feasible to create something like this,
but I'm not convinced it will actually make your life easier :-).
It sounds like you are proposing a scenario where you want to dynamically
decide whether or not to forward to a particular page (based on expiration
of "link validity" or on some other criteria). Your solution seems to
require:
* One Java class for the decision making logic
* One Java class (backing bean) and a JSP (or whatever) for the actual
content
rendering, assuming that it has not expired yet.
Whereas the solution I proposed embeds the "decision making logic" part
*inside* the backing bean that you need to create anyway. Why make yourself
write one more class?
SIDE NOTE -- I am presuming that you would also want to map all requests for
the same basic data to the same view identifier URL, instead of making up a
unique one for each user). You can still customize the details of what gets
returned by including request parameters in the emailed link ... those
parameters can be used, for example, to select the correct data from the
database, or implement whatever else you need to do to specialze the
response for this particular user.
So, you could end up with some URL like this:
http://www.mycompany.com/myapp/dataQueryResults.faces?ticket=123456
and, in the prerender() method, you'd grab the "ticket" parameter and use it
to look up stuff from the database. You could even implement "you can only
access this data once" type checks by updating the database data for this
ticket identifier the first time it is accessed.
But, the bottom line is, fewer classes makes for better, more maintainable,
code. And, this keeps Shale Remoting focused on what it is aimed at --
supporting asynchronous callbacks, not the entire JSF lifecycle (including
navigation). The standard FacesServlet covers that need quite nicely
already :-).
Craig
- Ingo
>
>
> Craig McClanahan schrieb:
> > On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
> >>
> >> Hi Craig,
> >>
> >> guess you are right that the remoting is not the solution for my
> >> problem. What I like to realize is the following:
> >> - The user gets an email with a link to the webapp.
> >> - When the user click on this link an action method should decide
> >> whether the link is still valid or not.
> >> - If the link is still valid the user is redirected to the login page.
> >> - If not the user is redirected to a new request page.
> >
> >
> > That seems like a reasonable use case.
> >
> >
> > So what I need is a solution to trigger an action method by a get
> >> request that returns an outcome that is handled by jsf?
> >
> >
> > JSF doesn't have any direct support for this, but here's an approach
> > to it
> > using Shale. An interesting fact is that the prerender() method of a
> > ViewController gets called before rendering, even on a GET request. The
> > return method here is void, so you can't just return a string and let
> the
> > standard NavigationHandler do its thing, but you *can* fake this out.
> > Consider the following:
> >
> > public class MyLinkChecker extends AbstractViewController {
> > ...
> > public void prerender() {
> > FacesContext context = FacesContext.getCurrentInstance();
> > boolean isValid = ...; // Examine current state, determine if
> > its valid
> > if (!isValid) {
> > // Force the user to see the logon page instead of the
> > requested one
> > ViewController vc = context.getApplication
> > ().getViewController();
> > vc.createView(context, "/logon.jsp");
> > } else {
> > ... prepare any data needed to render this page ...
> > }
> > ...
> > }
> >
> > You could put logic like this in the view controller of any page that
> > needs
> > this sort of check, or perhaps build a common superclass to
> > encapsulate it.
> > Then, just use a normal URL for the page in the email link that you send
> > out.
> >
> > Craig
> >
>
>
Re: Remoting and Outcome
Posted by William Huang <WH...@intralinks.com>.
I think I posted a reply to this before a few days ago, let me know if you
not sure what I meant
Bill
Ingo Düppe
<mailing-lists@du
eppe.com> To
user@shale.apache.org
09/28/2006 07:26 cc
PM
Subject
Re: Remoting and Outcome
Please respond to
user@shale.apache
.org
Yes that would work too with the ViewController, but then I prefer my
solution.
Because you can write little action classes like this one.
@bean(name="userActivate",scope=Scope.REQUEST)
class UserActivateAction {
// fill properties from param
public String activate() {
//do something
return "outcome"
}
}
Why I would like to combine it with shale-remoting is the dynamic
interpretation of the request path like
/dynamic/userActivate/activate.faces. So I wouldn't need to define the
action path explicitly.
To integrate such a solution in shale we need to define a new uri prefix
like "/dynamic" and a new Processor.
- Ingo
Craig McClanahan schrieb:
> On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
>>
>> Hi Craig,
>>
>> guess you are right that the remoting is not the solution for my
>> problem. What I like to realize is the following:
>> - The user gets an email with a link to the webapp.
>> - When the user click on this link an action method should decide
>> whether the link is still valid or not.
>> - If the link is still valid the user is redirected to the login page.
>> - If not the user is redirected to a new request page.
>
>
> That seems like a reasonable use case.
>
>
> So what I need is a solution to trigger an action method by a get
>> request that returns an outcome that is handled by jsf?
>
>
> JSF doesn't have any direct support for this, but here's an approach
> to it
> using Shale. An interesting fact is that the prerender() method of a
> ViewController gets called before rendering, even on a GET request. The
> return method here is void, so you can't just return a string and let the
> standard NavigationHandler do its thing, but you *can* fake this out.
> Consider the following:
>
> public class MyLinkChecker extends AbstractViewController {
> ...
> public void prerender() {
> FacesContext context = FacesContext.getCurrentInstance();
> boolean isValid = ...; // Examine current state, determine if
> its valid
> if (!isValid) {
> // Force the user to see the logon page instead of the
> requested one
> ViewController vc = context.getApplication
> ().getViewController();
> vc.createView(context, "/logon.jsp");
> } else {
> ... prepare any data needed to render this page ...
> }
> ...
> }
>
> You could put logic like this in the view controller of any page that
> needs
> this sort of check, or perhaps build a common superclass to
> encapsulate it.
> Then, just use a normal URL for the page in the email link that you send
> out.
>
> Craig
>
Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.
Re: Remoting and Outcome
Posted by Ingo Düppe <ma...@dueppe.com>.
Yes that would work too with the ViewController, but then I prefer my
solution.
Because you can write little action classes like this one.
@bean(name="userActivate",scope=Scope.REQUEST)
class UserActivateAction {
// fill properties from param
public String activate() {
//do something
return "outcome"
}
}
Why I would like to combine it with shale-remoting is the dynamic
interpretation of the request path like
/dynamic/userActivate/activate.faces. So I wouldn't need to define the
action path explicitly.
To integrate such a solution in shale we need to define a new uri prefix
like "/dynamic" and a new Processor.
- Ingo
Craig McClanahan schrieb:
> On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
>>
>> Hi Craig,
>>
>> guess you are right that the remoting is not the solution for my
>> problem. What I like to realize is the following:
>> - The user gets an email with a link to the webapp.
>> - When the user click on this link an action method should decide
>> whether the link is still valid or not.
>> - If the link is still valid the user is redirected to the login page.
>> - If not the user is redirected to a new request page.
>
>
> That seems like a reasonable use case.
>
>
> So what I need is a solution to trigger an action method by a get
>> request that returns an outcome that is handled by jsf?
>
>
> JSF doesn't have any direct support for this, but here's an approach
> to it
> using Shale. An interesting fact is that the prerender() method of a
> ViewController gets called before rendering, even on a GET request. The
> return method here is void, so you can't just return a string and let the
> standard NavigationHandler do its thing, but you *can* fake this out.
> Consider the following:
>
> public class MyLinkChecker extends AbstractViewController {
> ...
> public void prerender() {
> FacesContext context = FacesContext.getCurrentInstance();
> boolean isValid = ...; // Examine current state, determine if
> its valid
> if (!isValid) {
> // Force the user to see the logon page instead of the
> requested one
> ViewController vc = context.getApplication
> ().getViewController();
> vc.createView(context, "/logon.jsp");
> } else {
> ... prepare any data needed to render this page ...
> }
> ...
> }
>
> You could put logic like this in the view controller of any page that
> needs
> this sort of check, or perhaps build a common superclass to
> encapsulate it.
> Then, just use a normal URL for the page in the email link that you send
> out.
>
> Craig
>
Re: Remoting and Outcome
Posted by Craig McClanahan <cr...@apache.org>.
On 9/28/06, Ingo Düppe <ma...@dueppe.com> wrote:
>
> Hi Craig,
>
> guess you are right that the remoting is not the solution for my
> problem. What I like to realize is the following:
> - The user gets an email with a link to the webapp.
> - When the user click on this link an action method should decide
> whether the link is still valid or not.
> - If the link is still valid the user is redirected to the login page.
> - If not the user is redirected to a new request page.
That seems like a reasonable use case.
So what I need is a solution to trigger an action method by a get
> request that returns an outcome that is handled by jsf?
JSF doesn't have any direct support for this, but here's an approach to it
using Shale. An interesting fact is that the prerender() method of a
ViewController gets called before rendering, even on a GET request. The
return method here is void, so you can't just return a string and let the
standard NavigationHandler do its thing, but you *can* fake this out.
Consider the following:
public class MyLinkChecker extends AbstractViewController {
...
public void prerender() {
FacesContext context = FacesContext.getCurrentInstance();
boolean isValid = ...; // Examine current state, determine if
its valid
if (!isValid) {
// Force the user to see the logon page instead of the
requested one
ViewController vc = context.getApplication
().getViewController();
vc.createView(context, "/logon.jsp");
} else {
... prepare any data needed to render this page ...
}
...
}
You could put logic like this in the view controller of any page that needs
this sort of check, or perhaps build a common superclass to encapsulate it.
Then, just use a normal URL for the page in the email link that you send
out.
Craig
Re: Remoting and Outcome
Posted by Ingo Düppe <ma...@dueppe.com>.
Hi Craig,
guess you are right that the remoting is not the solution for my
problem. What I like to realize is the following:
- The user gets an email with a link to the webapp.
- When the user click on this link an action method should decide
whether the link is still valid or not.
- If the link is still valid the user is redirected to the login page.
- If not the user is redirected to a new request page.
So what I need is a solution to trigger an action method by a get
request that returns an outcome that is handled by jsf?
My current solution is a configurable phaselistener that checks whether
or not the requested link. If requested viewId is equal to a configured
action the action method will be invoked and the outcome of the method
will be analyzed by the navigation handler.
Any simpler solution or maybe more jsf like solution is very welcomed.
Regards
Ingo
Here is my action process method:
...
final UIViewRoot view = facesContext.getViewRoot();
final String viewId = view.getViewId();
if (StringUtils.isNotBlank(viewId)) {
for (PageAction action : actions) {
if (action.matches(viewId)) {
if (logger.isDebugEnabled()) {
logger.debug("perform page action " +
action.getAction());
}
final String outcome = action.perform(facesContext);
if (outcome != null) {
final Application application =
facesContext.getApplication();
NavigationHandler navigationHandler =
application.getNavigationHandler();
navigationHandler.handleNavigation(facesContext,
action.getFromAction(), outcome);
break;
}
}
}
}
Craig McClanahan schrieb:
> Sorry for the late response (I've been in an airplane a lot in the
> last few
> days). But I have a basic question for you.
>
> Why are you using Shale Remoting if you are expecting to navigate to a
> new
> page? The design purpose of these dynamic callbacks is to set up
> handlers
> for an asynchronous callback (such as from XmlHTTPRequest calls in an
> AJAX
> component). For that scenario, Shale Remoting expects your handler to:
>
> * Prepare the complete response (typically in XML or JSON or whatever).
> The most convenient way is to get an appropriate ResponseWriter and
> write all of the output.
>
> * Call FacesContext.responseComplete() to indicate to JSF that you have
> already completed the response for this request, so Render Response
> phase is skipped.
>
> On the other hand, a standard JSF request (i.e. the complete page
> submit) is
> passed through JSF navigation in the usual way, because the purpose of
> the
> response is to replace the *entire* page.
>
> So, based on this, it seems like you are trying to mix things that
> were not
> designed to be mixed.
>
> Craig
>
Re: Remoting and Outcome
Posted by Craig McClanahan <cr...@apache.org>.
On 9/26/06, Ingo Düppe <ma...@dueppe.com> wrote:
>
> Hello,
>
> I have defined a userActivate managed bean with a String perform() method.
> This methods returns a faces outcome depending on the results during
> execution.
>
> Calling the method by /dynamic/userActivate/perform.jsf?code=XYZ works
> fine, but what do I have to do that
> shale evaluates the outcome of this method and displays the according
> views?
Sorry for the late response (I've been in an airplane a lot in the last few
days). But I have a basic question for you.
Why are you using Shale Remoting if you are expecting to navigate to a new
page? The design purpose of these dynamic callbacks is to set up handlers
for an asynchronous callback (such as from XmlHTTPRequest calls in an AJAX
component). For that scenario, Shale Remoting expects your handler to:
* Prepare the complete response (typically in XML or JSON or whatever).
The most convenient way is to get an appropriate ResponseWriter and
write all of the output.
* Call FacesContext.responseComplete() to indicate to JSF that you have
already completed the response for this request, so Render Response
phase is skipped.
On the other hand, a standard JSF request (i.e. the complete page submit) is
passed through JSF navigation in the usual way, because the purpose of the
response is to replace the *entire* page.
So, based on this, it seems like you are trying to mix things that were not
designed to be mixed.
Craig
Regards
> Ingo
>
>
Re: Remoting and Outcome
Posted by Matthias Wessendorf <ma...@apache.org>.
When using PhaseListener's there can be a last piece of danger, since
the "chain" of PhaseListener's is not configurable. So if some
problems occur one day, it can be caused by an other PL.
-M
On 9/26/06, Ingo Düppe <ma...@dueppe.com> wrote:
> Hi William,
>
> no that easy, I just wanted to be sure that I didn't miss anything. At
> this point I have a solution based on my own phase listener. As soon I
> found some time to refactor it and based on shale remoting I will
> contribute it. Maybe I'm not the only one who could need it.
>
> Regards,
> Ingo
>
>
> William Huang schrieb:
> > You might need to implement/extend your own MethodBindingProcessor, then
> > you need to some how get the return value of userActivate.perform(..)
> > [probably the MethodBinding.invoke() returns that value]. Then use
> > NavigationHandler.handleNavigation(...). You need to look at the source
> > code of MethodBindingProcessor and javax.faces.el.MethodBinding.. It
> > shouldn't be too hard.
>
--
Matthias Wessendorf
http://tinyurl.com/fmywh
further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com
Re: Remoting and Outcome
Posted by Ingo Düppe <ma...@dueppe.com>.
Hi William,
no that easy, I just wanted to be sure that I didn't miss anything. At
this point I have a solution based on my own phase listener. As soon I
found some time to refactor it and based on shale remoting I will
contribute it. Maybe I'm not the only one who could need it.
Regards,
Ingo
William Huang schrieb:
> You might need to implement/extend your own MethodBindingProcessor, then
> you need to some how get the return value of userActivate.perform(..)
> [probably the MethodBinding.invoke() returns that value]. Then use
> NavigationHandler.handleNavigation(...). You need to look at the source
> code of MethodBindingProcessor and javax.faces.el.MethodBinding.. It
> shouldn't be too hard.
Re: Remoting and Outcome
Posted by William Huang <WH...@intralinks.com>.
You might need to implement/extend your own MethodBindingProcessor, then
you need to some how get the return value of userActivate.perform(..)
[probably the MethodBinding.invoke() returns that value]. Then use
NavigationHandler.handleNavigation(...). You need to look at the source
code of MethodBindingProcessor and javax.faces.el.MethodBinding.. It
shouldn't be too hard.
-Bill
Ingo Düppe
<mailing-lists@du
eppe.com> To
user@shale.apache.org
09/26/2006 10:12 cc
AM
Subject
Remoting and Outcome
Please respond to
user@shale.apache
.org
Hello,
I have defined a userActivate managed bean with a String perform() method.
This methods returns a faces outcome depending on the results during
execution.
Calling the method by /dynamic/userActivate/perform.jsf?code=XYZ works
fine, but what do I have to do that
shale evaluates the outcome of this method and displays the according
views?
Regards
Ingo
Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.