You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Daniel Haensse <ha...@swissembedded.com> on 2006/06/06 07:18:56 UTC

Servlet and myfaces

Dear list,

I would like to combine servlet and myfaces in an application.

In Myfaces, if a user logs in, a session is opened. A managed bean for the 
visual stuff and a managed bean for the model are started in this context 
(registered with session scope in faces-config).

The servlet should now access the instances of the visual and model managed 
beans associated with the session (user) and generated different jpeg-images, 
depending on the state of the model and visual (e.g. locale, access 
rights,...).

I found this example code, but I don't understand the FactoryFinder stuff
http://www.mail-archive.com/users@myfaces.apache.org/msg21786.html
Any good references to solve the problem? Is the FactoryFinder the right 
solution?

Another problem associated with this, is how the visual and model managed bean 
can have access to each other (reference) within this session scope. 
I found some example like this, but I doubt that this is working correctly if 
multiple sessions are open (from same and different users):
	static protected MainScreenView self = null;
	
	public MainScreenView() {
		self = this;
	}

	public static MainScreenView getInstance() {
		return self;
	}

I'm using realm stuff in web.xml

Is there a way to the the different instances running, and the scope their are 
associated to?

regards

Dani

Re: Servlet and myfaces

Posted by Daniel Haensse <ha...@swissembedded.com>.
Hey Dani,

that is really a greenhorn's question ;-)

check this 
http://wiki.apache.org/myfaces/AccessFacesContextFromServlet
http://mail-archives.apache.org/mod_mbox/myfaces-users/200606.mbox/%3C003b01c69b76$f32c22c0$6701a8c0@laptop%3E

The servled would look like this, the managed bean has the name "appModel" and 
class AppModel in this example

public class CompressImages extends AbstractFacesServlet {
	 protected void processRequest(HttpServletRequest request,
			 HttpServletResponse response) throws ServletException, IOException {
		// Get faces context
	    FacesContext facesContext = getFacesContext(request, response);
	    AppModel appModelBean = (AppModel) 
getManagedBean("appModel",facesContext);		

	    // We only serve request with valid session !!!
	    if (appModelBean==null) {
	    	java.util.logging.Logger.global.info("Bean is null.");
	    	return;
	        } 
	    else {
	        	java.util.logging.Logger.global.info("Got bean.");
	        }		

regards

Dani