You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rogerio Pereira <ro...@gmail.com> on 2005/06/16 16:26:25 UTC

How forward from an actionListener

Hi,

How can i forward from an actionListener? I have an actionListener
where i get a values from selected row in dataTable and then put the
values of this row in a session variable, after this i need redirect
to another page where these values will be shown to the user.
This is possible?

Thanks for any help,

Rogério

Re: How forward from an actionListener

Posted by Bruno Aranda <br...@gmail.com>.
Hi Rogerio, you can use the NavigationHandler, like this:

FacesContext facesContext = FacesContext.getCurrentInstance();

facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext,
null, outcome);

You put in 'outcome' a value you have already defined in a
navigation-rule in the faces-config.xml. For your interest, the
arguments for the method handleNavigation are:

void handleNavigation(FacesContext context,
                                          String fromAction,
                                          String outcome);

Regards,

Bruno

2005/6/16, Rogerio Pereira <ro...@gmail.com>:
> Hi,
> 
> How can i forward from an actionListener? I have an actionListener
> where i get a values from selected row in dataTable and then put the
> values of this row in a session variable, after this i need redirect
> to another page where these values will be shown to the user.
> This is possible?
> 
> Thanks for any help,
> 
> Rogério
>

Re: How forward from an actionListener

Posted by Bruno Aranda <br...@gmail.com>.
Buff, I was really puzzled as I had used that approach several times
successfully... :-) I thought that you were answering to me and not to
Rogerio's question. This is the kind of things that can happen when
your native language is not the english and you read mails in
diagonal....

Regards,

Bruno

2005/6/16, Martin Marinschek <ma...@gmail.com>:
> Well, Bruno, you don't have to apologize, your approach works as well,
> of course!
> 
> regards,
> 
> Martin
> 
> 
> On 6/16/05, alex <de...@yahoo.co.nz> wrote:
> > Martin Marinschek wrote:
> >
> > >No, it is not.
> > >
> > >there is no return string from an action-listener.
> > >
> > >
> > That's true, however there is a very simple way to do navigation from
> > the action-listener ;)
> >
> > Do it like that:
> >
> > FacesContext fc = FacesContext.getCurrentInstance();
> > fc.getApplication().getNavigationHandler().handleNavigation(fc,
> > fromAction, outCome);
> >
> > Rgds
> > Alex
> >
>

Re: How forward from an actionListener

Posted by Martin Marinschek <ma...@gmail.com>.
Well, Bruno, you don't have to apologize, your approach works as well,
of course!

regards,

Martin


On 6/16/05, alex <de...@yahoo.co.nz> wrote:
> Martin Marinschek wrote:
> 
> >No, it is not.
> >
> >there is no return string from an action-listener.
> >
> >
> That's true, however there is a very simple way to do navigation from
> the action-listener ;)
> 
> Do it like that:
> 
> FacesContext fc = FacesContext.getCurrentInstance();
> fc.getApplication().getNavigationHandler().handleNavigation(fc,
> fromAction, outCome);
> 
> Rgds
> Alex
>

Re: How forward from an actionListener

Posted by alex <de...@yahoo.co.nz>.
Martin Marinschek wrote:

>No, it is not.
>
>there is no return string from an action-listener.
>  
>
That's true, however there is a very simple way to do navigation from 
the action-listener ;)

Do it like that:

FacesContext fc = FacesContext.getCurrentInstance();
fc.getApplication().getNavigationHandler().handleNavigation(fc, 
fromAction, outCome);

Rgds
Alex

Re: How forward from an actionListener

Posted by Bruno Aranda <br...@gmail.com>.
Ups, sorry for pointing to the wrong direction then :-/

Regards,

Bruno

2005/6/16, Martin Marinschek <ma...@gmail.com>:
> No, it is not.
> 
> there is no return string from an action-listener.
> 
> what you can do is set both the action-listener and the action
> parameters, and knowing that the action method is called after the
> action-listener, you can do something with your backing bean to ensure
> that in the action method you return the right string.
> 
> If it is always the same page you will be going to, you can just set a
> fixed string in the action-parameter.
> 
> regards,
> 
> Martin
> 
> On 6/16/05, Rogerio Pereira <ro...@gmail.com> wrote:
> > Hi,
> >
> > How can i forward from an actionListener? I have an actionListener
> > where i get a values from selected row in dataTable and then put the
> > values of this row in a session variable, after this i need redirect
> > to another page where these values will be shown to the user.
> > This is possible?
> >
> > Thanks for any help,
> >
> > Rogério
> >
>

Re: How forward from an actionListener

Posted by Martin Marinschek <ma...@gmail.com>.
No, it is not.

there is no return string from an action-listener.

what you can do is set both the action-listener and the action
parameters, and knowing that the action method is called after the
action-listener, you can do something with your backing bean to ensure
that in the action method you return the right string.

If it is always the same page you will be going to, you can just set a
fixed string in the action-parameter.

regards,

Martin

On 6/16/05, Rogerio Pereira <ro...@gmail.com> wrote:
> Hi,
> 
> How can i forward from an actionListener? I have an actionListener
> where i get a values from selected row in dataTable and then put the
> values of this row in a session variable, after this i need redirect
> to another page where these values will be shown to the user.
> This is possible?
> 
> Thanks for any help,
> 
> Rogério
>

Re: OT: How do you intergrate a Jasper Report into a MYFaces app?

Posted by Graham Stark <gr...@virtual-worlds.biz>.
Well, I'm sure there are dozens of people on this list better at this
than I am, but I did get this to work so here goes: 

In the jsp I have:

<af:commandButton 	
	rendered="#{model.annualReportAvailable}"
	actionListener="#{model.makeAccountsReport}"
	returnListener="#{model.makeAccountsReport}" 	
        text="Your annual report is available" />
                                                            
(this is an Oracle ADF button, but it should be almost the same using
Myfaces). 

Model is my model, declared in the usual ways. It contains an
isAnnualReportAvailable method, various things to fill up the report,
and makeAccountsReport method which looks like:

        public void makeAccountsReport( ActionEvent event ){
             try{
                 Reporter reporter = new Reporter(); 
		 // fill in your report here... 
                 reporter.setStuff(....);

                 FacesContext context = 
                 FacesContext.getCurrentInstance();  
                 HttpServletResponse response =               
                      (HttpServletResponse)                             
                 context.getExternalContext().getResponse();    
                 response.setContentType(
                    "application/pdf");                         
                 
                 response.setHeader(
                   "Content-disposition", 
                   "attachment;filename=AnnualReport_"+
                   model.getYear()+".pdf" );
                        
                 OutputStream out = 
                    response.getOutputStream();
                 reporter.writeReport( out );
                 context.responseComplete();
             } catch ( Exception e ){
                   logger.error( "getAccountsReport(): failed to write"+
                       " pdf to output with exception " + e );
                }
        }

You can try it here, if you like:

http://www.mazegreenyachts.com 

(not quite finished, but getting there). The report should appear on the
main results page every fourth quarter. (Actually, the version here is
using Fop rather than Jasper Reports, but the principle is exactly the
same)

hope this helps 

Graham



> Graham, 
> This is great but would it be possible to see a bit more? I am
> completely in the dark about how the report is added to the web
> application. What must happen? what does the JSF page code look like?
> I can see how to generate the report but how to I transfer that to the
> client machine? I am afraid I am a bit of a newbie when it comes to
> report generation and printing.
>  
> Thanks
>  
> Glenn
>  
> 
> Graham Stark <gr...@virtual-worlds.biz> wrote:
>         Glenn,
>         
>         Don't know if this is any good to you, but here's an excerpt
>         from one
>         I've just finished:
>         ....
>         FacesContext context = FacesContext.getCurrentInstance(); 
>         HttpServletResponse response = (HttpServletResponse) 
>         context.getExternalContext().getResponse(); 
>         response.setContentType( "application/pdf" ); 
>         response.setHeader(
>         "Content-disposition",
>         "attachment;filename=AnnualReport_"+model.getYear()+".pdf");
>         
>         OutputStream out = response.getOutputStream();
>         reporter.writeReport( out );
>         FacesContext.getCurrentInstance().responseComplete();
>         ....
>         
>         where the reporter is a little class that wraps the Jasper
>         reports code.
>         
>         Graham
>         
>         > All,
>         > I am looking at Jasper reports but I am unsure the best way
>         to
>         > integrate Jasper Reports into a My Faces Application. Any
>         help would
>         > be greatly appreciated. If you are able to help and you come
>         to NYC at
>         > any time, the beer is on me!
>         > 
>         > Thanks
>         > 
>         > Glenn
>         > 
>         > 
>         > 
>         > 
>         > __________________________________________________
>         > Do You Yahoo!?
>         > Tired of spam? Yahoo! Mail has the best spam protection
>         around 
>         > http://mail.yahoo.com 
>         -- 
>         Graham Stark, Virtual Worlds
>         phone: (+044) 01908 618239 mobile: 07952 633185
>         Homepage http://www.virtual-worlds.biz/people/graham_s
>         Virtual Chancellor http://www.virtual-worlds.biz/vwc 
>         
> 
> 
> ______________________________________________________________________
> Discover Yahoo!
> Get on-the-go sports scores, stock quotes, news & more. Check it out!
-- 
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc     


RE: OT: How do you intergrate a Jasper Report into a MYFaces app?

Posted by Dani Kenan <da...@netvision.net.il>.
Glen,

 

Leaving MyFaces out, do you know how to show it using a simple servlet/jsp
application?

If not, could you describe the use case and user interaction you want to use
for generating a sample report?

 

Dani

  _____  

From: Glenn Davidson [mailto:gbadavidson@yahoo.com] 
Sent: Thursday, June 16, 2005 10:38 PM
To: MyFaces Discussion
Subject: Re: OT: How do you intergrate a Jasper Report into a MYFaces app?

 

Graham, 

This is great but would it be possible to see a bit more? I am completely in
the dark about how the report is added to the web application. What must
happen? what does the JSF page code look like? I can see how to generate the
report but how to I transfer that to the client machine? I am afraid I am a
bit of a newbie when it comes to report generation and printing.

 

Thanks

 

Glenn

 



Graham Stark <gr...@virtual-worlds.biz> wrote:

Glenn,

Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance(); 
HttpServletResponse response = (HttpServletResponse) 
context.getExternalContext().getResponse(); 
response.setContentType( "application/pdf" ); 
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+model.getYear()+".pdf");

OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....

where the reporter is a little class that wraps the Jasper reports code.

Graham

> All,
> I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
> 
> Thanks
> 
> Glenn
> 
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
-- 
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc 

  _____  

Discover Yahoo!
Get on-the-go sports scores, stock quotes, news & more. Check
<http://us.rd.yahoo.com/evt=32661/*http:/discover.yahoo.com/mobile.html>  it
out! 


Re: OT: How do you intergrate a Jasper Report into a MYFaces app?

Posted by Glenn Davidson <gb...@yahoo.com>.
Graham, 
This is great but would it be possible to see a bit more? I am completely in the dark about how the report is added to the web application. What must happen? what does the JSF page code look like? I can see how to generate the report but how to I transfer that to the client machine? I am afraid I am a bit of a newbie when it comes to report generation and printing.
 
Thanks
 
Glenn
 


Graham Stark <gr...@virtual-worlds.biz> wrote:
Glenn,

Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance(); 
HttpServletResponse response = (HttpServletResponse) 
context.getExternalContext().getResponse(); 
response.setContentType( "application/pdf" ); 
response.setHeader(
"Content-disposition",
"attachment;filename=AnnualReport_"+model.getYear()+".pdf");

OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....

where the reporter is a little class that wraps the Jasper reports code.

Graham

> All,
> I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
> 
> Thanks
> 
> Glenn
> 
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
-- 
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc 



		
---------------------------------
Discover Yahoo!
 Get on-the-go sports scores, stock quotes, news & more. Check it out!

Re: OT: How do you intergrate a Jasper Report into a MYFaces app?

Posted by Graham Stark <gr...@virtual-worlds.biz>.
Glenn,

Don't know if this is any good to you, but here's an excerpt from one
I've just finished:
....
FacesContext context = FacesContext.getCurrentInstance();  
HttpServletResponse response = (HttpServletResponse)    
         context.getExternalContext().getResponse();    
response.setContentType( "application/pdf" );                    
response.setHeader(
  "Content-disposition",
  "attachment;filename=AnnualReport_"+model.getYear()+".pdf");

OutputStream out = response.getOutputStream();
reporter.writeReport( out );
FacesContext.getCurrentInstance().responseComplete();
....

where the reporter is a little class that wraps the Jasper reports code.

Graham

> All,
>  I am looking at Jasper reports but I am unsure the best way to
> integrate Jasper Reports into a My Faces Application. Any help would
> be greatly appreciated. If you are able to help and you come to NYC at
> any time, the beer is on me!
>  
> Thanks
>  
> Glenn
> 
> 
>          
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
-- 
Graham Stark, Virtual Worlds
phone: (+044) 01908 618239 mobile: 07952 633185
Homepage http://www.virtual-worlds.biz/people/graham_s
Virtual Chancellor http://www.virtual-worlds.biz/vwc     


OT: How do you intergrate a Jasper Report into a MYFaces app?

Posted by Glenn Davidson <gb...@yahoo.com>.
All,
 I am looking at Jasper reports but I am unsure the best way to integrate Jasper Reports into a My Faces Application. Any help would be greatly appreciated. If you are able to help and you come to NYC at any time, the beer is on me!
 
Thanks
 
Glenn


 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com