[jboss-user] [JBoss Portal] - Re: Best way to learn

Agathon do-not-reply at jboss.com
Tue Aug 22 12:16:27 EDT 2006


"danny_hon" wrote : We are also looking at what is the best framework for creating portlets.  We find some issues using Struts.  If we use request.setAttribute(...) in an Action class, the variable is not visible in the JSP.  The work around is to use request.getSession.setAttribute(...).  This is not very elegant, and we have to remove the sessiono attribute later.  In addition, the validation from a form is not working.  Even though it does not accept the invalid values (which is good), it does not show the error from the JSP <html:errors /> tag.  It seems like these 2 problems are related to the fact that variable set by request.setAttribute() is not visible by the forwarded JSP.
  | 
  | We are using JBP 2.2.x + Struts-Bridge 1.0.  Does anyone have the same problem?  Any help is appreciated.

Sorry about the late reply; I was very busy over the last little while. Perhaps I was a little over-zealous in stating there are "zero problems" using Struts in a Portlet context. This problem stems from the fact that Struts actions and the rendering of the resulting JSP are (usually) contained in two separate requests. To fix this you will need to extend the PortletRequestProcessor provided with the Struts Bridge. Here is an example:


  | public class CustomPortletRequestProcessor extends PortletRequestProcessor {
  |     public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  |     		HttpSession session = request.getSession();
  | 		ActionMessages errors = (ActionMessages)session.getAttribute(Globals.ERROR_KEY);
  | 		session.removeAttribute(Globals.ERROR_KEY);
  | 		
  | 		request.setAttribute(Globals.ERROR_KEY, errors);
  |     	
  |     		super.process(request, response);
  |     	
  |     		errors = (ActionMessages)request.getAttribute(Globals.ERROR_KEY);
  |     		
  |     		if (errors != null && errors.isAccessed()) {
  |     			request.removeAttribute(Globals.ERROR_KEY);
  |     		} else {
  |     			session.setAttribute(Globals.ERROR_KEY, errors);
  |     		}
  |     }
  | }
  | 

The dual request is also a problem if you want to keep your Hibernate session (if you're using Hibernate) open for both requests (action and render). We haven't found a solution to this problem and are presently using a workaround; using tag libraries to load some objects/collections in the view.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3966744#3966744

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3966744



More information about the jboss-user mailing list