<p>I will elaborate somewhat. Jsf is kind-of extremely painful for working with from designer's perspective, somewhat in the range of trying to draw a picture while having hands tied at your back, but it is good for chewing up forms and listing lots of data. So sites we are making in my company are jsf admin pages and jsp user pages. Problem occurs when user pages have some complicated forms and stuff and jsf starts kickin' in. </p>

<p>Here is the question: I'm on pure jsp page. I need to access some jsf page that uses session bean. How can I initialize that bean? If I was on jsf page, I could have some commandLink which would prepare data. Only thing I can come up with is having dummy jsf page that will do the work and redirect me to needed jsf page, but that's kind of ugly, and I don't want to end up with 50 dummy pages. I would rather find some mechanism to reinitialize bean that is already in session with some wanted parameters.</p>

<p>Edit: some more details. In this specific situation, I have a tests that are either full or filtered. It's a same test with same logic and everything, except if test is filtered, it should eliminate some questions depending on answers. Upon a clicking a link, it should start a requested test in one of the two modes. Links are parts of main menu-tree and are visible on many sibling jsp pages. My task is to have 4 links: testA full, testA filtered, testB full, testB filtered, that all lead on same jsf page and TestFormBean should be reinitialized accordingly.</p>

<p>Edit: I've researched facelets a bit, and while it won't help me now, I'll definitely keep that in mind for next project.</p>

[{'answer_id': 43549, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 2, 'selected': False, 'text': '<p>have you looked into using facelets? It lets you get rid of the whole JSF / JSP differences (it\'s an alternate and superior view controller).</p>\n\n<p>It also supports great design-time semantics with the jsfc tag...</p>\n\n<pre><code>&lt;input type="text" jsfc="#{SomeBean.property}" class="foo" /&gt;\n</code></pre>\n\n<p>gets translated internally to the correct JSF stuff, so you can work with your existing tools.</p>\n'}, {'answer_id': 63883, 'author': 'Eric  DeLabar', 'author_id': 7556, 'author_profile': 'https://Stackoverflow.com/users/7556', 'pm_score': 2, 'selected': True, 'text': "<p>To solve this one I'd probably create a JSF fragment that only includes your form, then use a <code>&lt;c:import&gt;</code> tag to include it in my JSF page.  </p>\n\n<p>That solution is probably a little fragile depending on your environment though.</p>\n\n<p>EDIT: See Chris Hall's answer, <code>FacesContext</code> is not available outside the <code>FacesServlet</code>.</p>\n"}, {'answer_id': 69050, 'author': 'MetroidFan2002', 'author_id': 8026, 'author_profile': 'https://Stackoverflow.com/users/8026', 'pm_score': 0, 'selected': False, 'text': '<p>Create a custom JSP tag handler. You can then retrieve the bean from session scope and then initialize it on the fly. See this <a href="http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html" rel="nofollow noreferrer">tutorial</a> for more details.</p>\n'}, {'answer_id': 71584, 'author': 'Slartibartfast', 'author_id': 4433, 'author_profile': 'https://Stackoverflow.com/users/4433', 'pm_score': 0, 'selected': False, 'text': "<p>Actually, I've resolved this by removing bean from session, so it has to be generated again when jsf page is called. Then I pick up get parameters from a request in constructor.</p>\n"}, {'answer_id': 72213, 'author': 'Chris Hall', 'author_id': 5933, 'author_profile': 'https://Stackoverflow.com/users/5933', 'pm_score': 2, 'selected': False, 'text': '<p>You can retrieve a managed bean inside of a tag library using something like this:</p>\n\n<pre><code>FacesContext context = FacesContext.getCurrentInstance();\nObject myBean = context.getELContext().getELResolver().getValue(context.getELContext(), null, "myBeanName");\n</code></pre>\n\n<p>However, you\'d need to use the tag library from one of your JSF pages.  FacesContext.getCurrentInstance() returns null when it\'s called outside of the FacesServlet.</p>\n'}]
['https://Stackoverflow.com/questions/42828', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4433/']