• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

how to obtain the response object in jsf

 
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ma trying to do the following in order to obtaine the response object

import javax.faces.bean.*;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

ExternalContext context =FacesContext.getCurrentInstance()
HttpServletResponse response =(HttpServletResponse)context getResponse();
(HttpServletResponse)context.getRresponse.sendRedirect(searchURL);

However which import statement would i need to to get HttpServletResponse.. ?? thanks
 
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Zedan wrote:However which import statement would i need to to get HttpServletResponse.. ?? thanks



Notice there's a link in your post? Follow it to the API docs for HttpServletResponse. (I just posted the same link.)
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Adam Zedan wrote:However which import statement would i need to to get HttpServletResponse.. ?? thanks



Notice there's a link in your post? Follow it to the API docs for HttpServletResponse. (I just posted the same link.)



I cant seem to add import javax.servlet.http maybe cause its a jsf project ... any hints ..

 
Paul Clapham
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Zedan wrote:I cant seem to add import javax.servlet.http maybe cause its a jsf project ... any hints ..



Hint: Explain the problem. Otherwise we don't know whether the "h" key on your keyboard is broken (so you can't type that) or what.
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Adam Zedan wrote:I cant seem to add import javax.servlet.http maybe cause its a jsf project ... any hints ..



Hint: Explain the problem. Otherwise we don't know whether the "h" key on your keyboard is broken (so you can't type that) or what.



I am trying to gain access to the response object in a jsf project Suppose The code i am using is something like this



in the above code the line



gets underlined since HttpServletResponse is not being found...
 
Paul Clapham
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you already seemed to understand that you had to import the HttpServletResponse class; you didn't do that. You implied that there was some reason you couldn't do that; I asked why not. Evidently I didn't ask clearly enough. Why haven't you imported that class?
 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But you already seemed to understand that you had to import the HttpServletResponse class; you didn't do that. You implied that there was some reason you couldn't do that; I asked why not. Evidently I didn't ask clearly enough. Why haven't you imported that class?



because when i try to do this
import javax.servlet.http ;
I get an error saying
import javax.servlet.http cannot be resolved..
This http is not present in the intellisense which only displays
import javax.servlet.jsp.*;
 
Paul Clapham
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come on, it's not that complicated. The name of the type is HttpServletResponse and it's in the javax.servlet.http package. So the fully qualified name of the type is javax.servlet.http.HttpServletResponse and that means the code to import the type is

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Come on, it's not that complicated. The name of the type is HttpServletResponse and it's in the javax.servlet.http package. So the fully qualified name of the type is javax.servlet.http.HttpServletResponse and that means the code to import the type is



I wish it was that simple , but it seems as if you don't totally understand my problem... Let me explain again , I am fully aware that in order to use the response object I need to use the javax.servlet.http.* import. but unfortunately when i type the following

import javax.servlet.http.*

The compiler automatically considers this as an error saying this import statement cannot be resolved!!!

The only option i have is to add in the servlet section

import javax.servlet.jsp.*;

let me remind you this is a dynamic project using java server faces 2.0 and I just added a POJO not a servlet!!


 
Paul Clapham
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Zedan wrote:I wish it was that simple , but it seems as if you don't totally understand my problem...


That's true.

let me remind you this is a dynamic project using java server faces 2.0 and I just added a POJO not a servlet!!


Well, that isn't really a reminder because you never said that before.

However that does make sense. If you have a POJO then it shouldn't be messing about with the servlet response. Your IDE (I assume you're using one because you mentioned a "project") is acting in good taste there.

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Adam Zedan wrote:I wish it was that simple , but it seems as if you don't totally understand my problem...


That's true.

let me remind you this is a dynamic project using java server faces 2.0 and I just added a POJO not a servlet!!


Well, that isn't really a reminder because you never said that before.

However that does make sense. If you have a POJO then it shouldn't be messing about with the servlet response. Your IDE (I assume you're using one because you mentioned a "project") is acting in good taste there.



so any idea on how i could access the response object in a pojo , after all in a JSF project arent all the objects(beans) pojos ??
 
Saloon Keeper
Posts: 28227
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam Zedan wrote:
so any idea on how i could access the response object in a pojo , after all in a JSF project arent all the objects(beans) pojos ??



Well, actually, one of the defining characteristics of a Plain Old Java Object is that it really has no business knowing about the innards of external esoterica such as HttpServletResponse. A POJO is something you can inject data into and that you can invoke methods on, and it more or less doesn't care about the framework that contains it.

The point that we've been trying to make, however, is that in JSF, you mess with the ServletResponse at your peril. JSF owns the ServletResponse, not you. It has its own ideas on how to manage the headers and response stream, and you can't just jam stuff into it willy-nilly.

JSF isn't like JSP where the page is a linear translation into logic. Instead, the JSF View is compiled into a 2-dimensional (tree) data structure that is used by the JSF rendering engines as a reference when it creates the output stream. You don't code logic in a JSF view (despite the fact that so many people here keep trying to!), you provide a template.

If you have a Java object that needs direct access to the Response object, you should seriously consider placing it under the control of a Servlet or traditional JSP (not to be confused with a JSF "JSP" View definition). It's perfectly legal to do so. You won't have access to JSF functionality there, but JSF does play nicely with non-JSF request/response handlers in the overall application.
 
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic