You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jan van de klok <ja...@chronotech.nl> on 2006/06/06 13:48:59 UTC

JspViewHandler createView

Hi there, I'm cuurently replacing JSF RI of Sun By Myfaces. The problem I ran
into is the following: we had subclassed the sun ViewhandlerImpl class and
re-implemented the createview method. Basiccaly this reimplementation
checked the viewid to see wether or not it was pointing to a public or
private section of the webapp. If it pointed to the private section and the
User was not logged in, a view was created for the login page otherwise the
requested page view was created. This worked OK for the sun RI.

For Myfaces I did the same (subclassed JspViewHandlerImpl). The problem here
is that although I call the super.createView(...) for the login page, the
original requested page is created. 

How can I fix this?. Is there another way to solve this problem neatly?

Jan

Here is the subclass code snippet of the overridden method : 


	public UIViewRoot createView(FacesContext fc, String viewId) {
		// The pageUrl is the ViewId, check if it is a public or private
		// page....

		if (viewId.indexOf("jsp/public/") < 0) { // If the page is considered
													// to be private

			HttpSession session = (HttpSession) fc.getExternalContext()
					.getSession(true);
			String userId = (String) session.getAttribute("_login_");
			if (null == userId) {// check if user is logged in....
				// user is not authenticated yet, see if the uid and pwd is
				// supplied on the request
				// >>>>>>>>> check if uid and pwd are send alog with the request
				String uid = (String) fc.getExternalContext()
						.getRequestParameterMap().get("uid");
				String pwd = (String) fc.getExternalContext()
						.getRequestParameterMap().get("pwd");
				if (uid != null) {
					// try to simulate the login using the uid and pwd value
					LoginManager loginManager = null;
					javax.faces.context.FacesContext context =
javax.faces.context.FacesContext
							.getCurrentInstance();
					javax.faces.application.Application app = context
							.getApplication();
					javax.faces.el.VariableResolver resolver = app
							.getVariableResolver();
					Object obj = resolver.resolveVariable(context,
							"loginManager");
					if (obj != null) {
						loginManager = (LoginManager) obj;
						loginManager.setUserId(uid);
						loginManager.setPassword(pwd);
						String result = loginManager.login();
						if (result.equals(LoginManager.AUTHENTICATION_OKE)) {
							return super.createView(fc, viewId); // send the
																	// original
																	// requested
																	// page
						}
					}
				}
				// if not logged in (or implicit login failed , redirect to the
				// loging page
				// store the requested page on the session for redirect after
				// succesfull login
				session.setAttribute(REQUESTED_PAGE, viewId);
				session.setAttribute(REQUESTED_PAGE_QUERY_STRING,
						((HttpServletRequest) fc.getExternalContext()
								.getRequest()).getQueryString());
				return super.createView(fc, LOGIN_PAGE);// Redirect to the login
														// page
			}
		}

		if (viewId.indexOf("originalRequestedUrl.jsp") >= 0) { // show the
																// previous
																// requested
																// page (the one
																// before
																// redirect to
																// login
			HttpSession session = (HttpSession) fc.getExternalContext()
					.getSession(true);
			String originalUrl = (String) session.getAttribute(REQUESTED_PAGE);

			if (originalUrl != null) {
				// restore original query string
				Object queryString = session
						.getAttribute(REQUESTED_PAGE_QUERY_STRING);
				if (queryString != null) {
					HttpServletRequest request = ((HttpServletRequest) fc
							.getExternalContext().getRequest());
					request.setAttribute(REQUESTED_PAGE_QUERY_STRING,
							queryString);
					session.removeAttribute(REQUESTED_PAGE_QUERY_STRING);
				}
			}
			// if no original url, just show the login page again
			if (originalUrl == null)
				originalUrl = LOGIN_PAGE;

			return super.createView(fc, originalUrl);// Redirect to the login
														// page

		}

		return super.createView(fc, viewId); // send the original requested
												// page
	}



--
View this message in context: http://www.nabble.com/JspViewHandler--createView-t1741267.html#a4731734
Sent from the MyFaces - Users forum at Nabble.com.


Re: JspViewHandler createView

Posted by Jan van de klok <ja...@chronotech.nl>.
Solved my problem by reimplement the renderView method instead of the
createView method.
--
View this message in context: http://www.nabble.com/JspViewHandler--createView-t1741267.html#a4747316
Sent from the MyFaces - Users forum at Nabble.com.