• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL to retrieve and pass request objects - second attempt  RSS feed

 
John Killman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The original question was posted under:
http://www.coderanch.com/t/512580/JSP/java/JSTL-retrieve-pass-request-objects

I took a great deal of time for this response and found the topic locked - not sure why.


To rephrase and update the question:

I have two JSP/JSF/JSTL pages in the same web application
Each has a backing bean

Overall package: chartPackage

First page:

JSP file: MyChart.jsp
Backing Bean: MyChartBackingBean.java
Method: public void myFilterButton() {...}
Button: A button on the page ("Filter") which is tied to method myFilterButton


Second page:

JSP file: MyFilter.jsp
Backing Bean: MyFilterBackingBean.java
Method: public void myRetrieveMethod() {...}
Button: A button on the page ("Return") which is supposed to return to MyChart.jsp


What is supposed to happen (as much as possible in the backing beans, little in the JSPs):

1) MyChart.jsp is displayed
2) The "Filter" button is pushed
3) myFilterButton() method is called.
a. A request object is filled with data: request.setAttribute("ChartData", chartobject);
b. myFilterButtion() method starts the Filter.jsp page with the request object being passed
4) MyFilter.jsp is started (MyChart.jsp does not close, and MyFilter.jsp is assumed modal)
5) myRetrieveMethod() is triggered
6) myRetrieveMethod() reads the request object and does stuff
7) The "Return" button is pushed
8) MyFilter.jsp goes away


I can get to 3b.
At this point I try to go to the other JSP page and nothing but errors.

public void myFilterButton() {

FilterData myFilterData = ...:

try {

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
HttpServletResponse response = (HttpServletResponse)externalContext.getResponse();

String uri = "/faces/filter.jsp"; //****** not sure if this is right *****

request.setAttribute("FilterAttribute", myFilterData);


*** First attempt ***
request.getRequestDispatcher(uri).forward(request, response);
*** Error
org.apache.jasper.JasperException: java.lang.RuntimeException: Cannot find FacesContext
*** Then what is the uri supposed to be???


*** Second attempt ***
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.setRequest(request);
context.dispatch(uri);
*** Error
javax.servlet.ServletException: Cannot forward after response has been committed
javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
*** But I don't send a forward anywhere else.


}
catch (Exception e) {
System.out.println("Filter the data - exception");
}

System.out.println("Filter the data");
}




I assume if I ever get the first part working I would retrieve it with:

public void myRetrieveMethod() {

try {

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();

FilterData filterData = (FilterData) request.getAttribute("FilterAttribute");
... do stuff with the filterData


}
catch (Exception e) {
System.out.println("Retrieve the data - exception");
}

System.out.println("Retrieve the data");
}



Notes:

1) I have posted a variation of this question at:
http://stackoverflow.com/questions/3859344/data-transfer-between-servlet-and-jsp
I have since removed all the sevlets and only use JSP/JSF.

2) Hany - JSTL and Java backing beans are a management requerement. Also, all the proprietary 3rd party code in this uses them.

3) Bear - Above is clarification as best I can do at this point.


Thanks all for the previous responses.



Thanks,
John
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Killman wrote:
The original question waI took a great deal of time for this response and found the topic locked - not sure why.

I explained the closing in the post.
This is a repeat of a previous question in an attempt to make it clearer.

It wastes people's time when multiple redundant conversations take place. Please click this link ⇒ CarefullyChooseOneForum ⇐ for more information. It also applies to posting the same question more than once, or spreading a conversation across multiple topics.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!