• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forward from a servlet to JSF page

 
Kacem Bel
Ranch Hand
Posts: 30
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I have an application developped with JEE6 (JSF2/EJB/JPA) under JBoss 6 AS, I'm trying to do a forward from a servlet to a JSF page, it works but it just dont bring the CSS and images files,
and when I try the Redirect instead it works fine and brings everything...
I have to do it with forward because I need to keep the address in the bar, so if you have any ideas or suggestions they will be welcome

thanks in advance :)
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure exactly what you mean when you say that.

CSS, JavaScript, and other stuff are not "brought". They are retrieved by the client in response to URLs embedded in the client's rendered web page using a separate HTTP Request/Response action for each one of them.

If you are attempting to call JSF from non-JSF code, however, that isn't likely to work very well. Normally when one servlet/JSP hands off to another servlet/JSP, you'd use the J2EE forwarding mechanism, which dispatches the new request via the proper channels (as defined in web.xml). The FacesServlet is no different from any other servlet that way, although the internal complexities of what it does are unique to JSF.
 
Kacem Bel
Ranch Hand
Posts: 30
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,


Thanks for reply, I found the problem, I have an image resource in my facelet template like that:



When I do a redirect and I look at the browser I see the image file is brought within the url : https://localhost:8443/contextAPP/module1/images/logo.png
And when I do a forward the url looks like this : https://localhost:8443/images/logo.png

Thats why the browser never finds the image and I dont know why in case of forward the contextApp/module1 isnt there ...?
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is clever and keeps track of the servlet context path for you. In regular J2EE, you don't get as much support in that regard.

If you use the JSF graphicImage tag for images on JSF Views instead of the HTML IMG tag, you will get the proper servlet context path in the generated URL link.
 
Kacem Bel
Ranch Hand
Posts: 30
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-


Thank you!! I see your point, now I've been using the <h:graphicImage library="images" name="logo.png" /> and it's working fine now,
however when my actual page X is loaded I have a menu that is using a primefaces commandLink :


The foo() function returns the name of a facelet page inside my application,
Now in case I did a forward from the servlet to that page X and I click on the "My Link" commandLink I got everytime a ViewExpiredException
I don't know what I'm missing exacly? :confused:
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is incorrect. The EL for an action method is a reference to that method, not a call. JSF does the calling. So the proper syntax is


Except that backing beans are Models not Controllers, so "controller" as a bean name is not meaningful. In JSF, the Controllers are almost always part of JSF itself, not user-written code. Action methods are business methods, and not actually part of the MVC paradigm. A Controller is something whose sole responsibility is to synchronize the UI with the model, and that's not what action methods do.

Despite all that, I'm not sure that's the cause of the ViewExpiredException. You usually get that when you're attempting to retrieve a View whose component tree has been flushed from the View cache because it's relatively old.
 
Kacem Bel
Ranch Hand
Posts: 30
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your clarifications I will definitely take them in consideration!


Still I can't understand how the view could be expired in a matter of few secondes... and only when I use the forward action :/
I will start from scratch and run a basic web application with only 1 view and 1 servlet and see what happens :)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!