دنبال کننده ها

۱۳۹۶ آذر ۱۰, جمعه

How to add HttpServletRequest attribute from JSF when redirecting to a custom servlet ?

[ad_1]



I am implementing sort of ImageServlet serving an Image, inspired by BalusC example here http://balusc.omnifaces.org/2007/04/imageservlet.html



My servlet implementation expects to have a parameter "Animal" of type Animal



 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
LOGGER.info("On ImageServlet");

// Get Animal from request.
Animal animal = (Animal) request.getAttribute("Animal");


My JSF page have at some point a graphicImage tag



<h:graphicImage value="faces/image?Animal=#animalForm.animal" />


My animalForm bean is serving the Animal correctly



public Animal getAnimal()

LOGGER.info("Current animal is : " + this.animal);
return this.animal;



I know that the Animal=#animalForm.animal is wrong as it adds a Parameter, which will be of type String and not an Attribute but I can not find the way to add a (Typed) attribute here.



I have also read about more up-to-date way of doing the same thing with omnifaces, but right now I am on an learning curve and I have (unfortunatelly) started by project with ManagedBean and Tomcat so I would need to switch to CDI objects first. I plan to do that latter once I have something working at the first place




[ad_2]

لینک منبع