Mix jsp and jsf

I’ll clarify a few. Jsf is very painful to work from a design point of view, to some extent in an attempt to draw a picture with hands tied to the back, but it is good for chewing forms and listing a lot of data. Thus, the sites we create in my company are jsf admin pages and jsp user pages. The problem occurs when custom pages have some complex forms and stuff, and jsf starts up.

Here's the question: I'm on a clean jsp page. I need to access some jsf page that uses a bean session. How can i initialize this bean? If I were on the jsf page, I could have a commandLink command that prepared the data. The only thing I can think of is to have a dummy jsf page that will do the job and redirect me to the desired jsf page, but it is so ugly and I don't want to end up with 50 dummy pages. I would prefer to find a mechanism to reinitialize a bean that is already in a session with some desired parameters.

Edit: some details. In this particular situation, I have tests that are either complete or filtered. This is the same test with the same logic and everything, except when the test is filtered, it should eliminate some questions depending on the answers. After clicking the link, it should run the requested test in one of two modes. Links are part of the main menu tree and are visible on many sibling jsp pages. My task is to have 4 links: testA full, testA filter, testB full, testB is filtered, that all lead to the same jsf page and TestFormBean should be reinitialized accordingly.

Edit: I researched the chips a bit, and until this helps me, I will definitely take this into account for the next project.

+4
source share
5 answers

To solve this problem, I would probably create a JSF snippet that includes only your form, and then use <c:import> to include it in my JSF page.

This solution is probably a little fragile depending on your environment.

EDIT: See Chris Hall's answer, FacesContext not available outside of FacesServlet .

+1
source

Have you studied using facelets? It allows you to get rid of all the differences of JSF / JSP (this is an alternative and improved controller).

It also supports excellent development-time semantics with the jsfc tag ...

 <input type="text" jsfc="#{SomeBean.property}" class="foo" /> 

internally translated into the correct JSF material, so you can work with existing tools.

+4
source

You can get a managed bean inside the tag library using something like this:

 FacesContext context = FacesContext.getCurrentInstance(); Object myBean = context.getELContext().getELResolver().getValue(context.getELContext(), null, "myBeanName"); 

However, you will need to use the tag library from one of your JSF pages. FacesContext.getCurrentInstance () returns null when it is called outside of FacesServlet.

+3
source

Create your own JSP tag handler. You can then extract the component from the scope of the session and then initialize it on the fly. See this tutorial for more details.

0
source

Actually, I solved this by removing the bean from the session, so it should be generated again when the jsf page is called. Then I take the parameters from the request in the constructor.

0
source

Source: https://habr.com/ru/post/1276537/


All Articles