Package org.apache.struts.tiles

Examples of org.apache.struts.tiles.ComponentContext


   * @return the component context
   * @throws Exception if preparations failed
   */
  protected ComponentContext getComponentContext(ComponentDefinition definition, HttpServletRequest request)
      throws Exception {
    ComponentContext context = ComponentContext.getContext(request);
    if (context == null) {
      context = new ComponentContext(definition.getAttributes());
      ComponentContext.setContext(context, request);
    }
    else {
      context.addMissing(definition.getAttributes());
    }
    return context;
  }
View Full Code Here


         HttpServletRequest request,
         HttpServletResponse response)
  throws Exception {

      // Try to retrieve tile context
    ComponentContext context = ComponentContext.getContext( request );
    if( context == null )
      {
      request.setAttribute( "actionError", "Can't get component context.");
      return (mapping.findForward("failure"));
      }
      // Get requested test from tile parameter
    String param;

      // Set a definition in this action
    param = (String)context.getAttribute( "set-definition-name" );
    if( param != null )
      {
      try
        {
          // Read definition from factory, but we can create it here.
        ComponentDefinition definition = DefinitionsUtil.getDefinition( param, request, getServlet().getServletContext() );
        //definition.putAttribute( "attributeName", "aValue" );
        DefinitionsUtil.setActionDefinition( request, definition);
        }
       catch( FactoryNotFoundException ex )
        {
        request.setAttribute( "actionError", "Can't get definition factory.");
        return (mapping.findForward("failure"));
        }
       catch( NoSuchDefinitionException ex )
        {
        request.setAttribute( "actionError", "Can't get definition '" + param +"'.");
        return (mapping.findForward("failure"));
        }
       catch( DefinitionsFactoryException ex )
        {
        request.setAttribute( "actionError", "General error '" + ex.getMessage() +"'.");
        return (mapping.findForward("failure"));
        }
      }

      // Overload a parameter
    param = (String)context.getAttribute( "set-attribute" );
    if( param != null )
      {
      context.putAttribute( param, context.getAttribute( "set-attribute-value" ));
      } // end if

    return (mapping.findForward("success"));

    }
View Full Code Here

                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
      // Try to retrieve tile context
    ComponentContext context = ComponentContext.getContext( request );
    if( context == null )
      { // Not found, create a context
        // This context will be detected by the TilesRequestProcessor which will do an include
        // instead of a forward.
      ComponentContext tileContext = new ComponentContext( );
      ComponentContext.setContext( tileContext, request);
      }
    return (mapping.findForward("success"));
    }
View Full Code Here

    System.out.println("Enter action SetPortalPrefsAction");
  HttpSession session = request.getSession();
  PortalPrefsForm prefsForm = (PortalPrefsForm)form;

          // Try to retrieve tile context
    ComponentContext context = ComponentContext.getContext( request );
    if( context == null )
      {
      throw new ServletException( "This action must be called by a Tile, not directly" );
      }
View Full Code Here

        throws Exception {

        log.debug("Enter Rss Channel Action");

        // Try to retrieve tile context
        ComponentContext context = ComponentContext.getContext(request);
        if (context == null) {
            throw new ServletException("This action must be called by a Tile, not directly");
        }

        ActionMessages errors = new ActionMessages();

        // -- Retrieve parameters --
        // Urls can come from a list, or from a single attribute.

        List channels = (List) context.getAttribute(CHANNEL_URLS_KEY);
        if (channels == null) {
            Object url = context.getAttribute(CHANNEL_URL_KEY);
            channels = new ArrayList(1);
            channels.add(url);
        }

        log.debug("urls count" + channels.size());

        // -- Loop through channels --
        ArrayList channelBeans = new ArrayList(channels.size());
        try {
            for (int i = 0; i < channels.size(); i++) {
                RSSDigester digester = new RSSDigester();
                String url = (String) channels.get(i);
                // Add application path if needed
                if (url.startsWith("/")) {
                    url = toFullUrl(request, url);
                }

                log.debug("Channel url=" + url);

                Channel obj = (Channel) digester.parse(url);

                log.debug("Channel:" + obj);

                channelBeans.add(obj);
            }
        } catch (Throwable t) {
            errors.add(
                ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("rss.access.error"));

            servlet.log(t.toString());
        }

        // -- Handle Errors ---
        if (!errors.isEmpty()) {
            this.saveErrors(request, errors);

            if (mapping.getInput() != null) {
                return new ActionForward(mapping.getInput());
            }

            // If no input page, use error forwarding

            log.debug("Exit Rss Channel Action : error");

            return mapping.findForward("error");
        }

        // -- Save Bean, and Continue  ---

        log.debug("Exit Rss Channel Action");

        // Use Tile context to pass channels
        context.putAttribute(CHANNELS_KEY, channelBeans);

        return mapping.findForward("continue");
    }
View Full Code Here

    if (definition == null) {
      throw new ServletException("No Tiles definition found for name '" + getUrl() + "'");
    }

    // get current component context
    ComponentContext context = getComponentContext(definition, request);

    // execute component controller associated with definition, if any
    Controller controller = getController(definition, request);
    if (controller != null) {
      if (logger.isDebugEnabled()) {
View Full Code Here

   * @return the component context
   * @throws Exception if preparations failed
   */
  protected ComponentContext getComponentContext(ComponentDefinition definition, HttpServletRequest request)
      throws Exception {
    ComponentContext context = ComponentContext.getContext(request);
    if (context == null) {
      context = new ComponentContext(definition.getAttributes());
      ComponentContext.setContext(context, request);
    }
    else {
      context.addMissing(definition.getAttributes());
    }
    return context;
  }
View Full Code Here

    if (definition == null) {
      throw new ServletException("No Tiles definition found for name '" + getUrl() + "'");
    }

    // get current component context
    ComponentContext context = getComponentContext(definition, request);

    // execute component controller associated with definition, if any
    Controller controller = getController(definition, request);
    if (controller != null) {
      if (logger.isDebugEnabled()) {
View Full Code Here

   * @return the component context
   * @throws Exception if preparations failed
   */
  protected ComponentContext getComponentContext(ComponentDefinition definition, HttpServletRequest request)
      throws Exception {
    ComponentContext context = ComponentContext.getContext(request);
    if (context == null) {
      context = new ComponentContext(definition.getAttributes());
      ComponentContext.setContext(context, request);
    }
    else {
      context.addMissing(definition.getAttributes());
    }
    return context;
  }
View Full Code Here

    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());

    view.render(new HashMap(), request, response);
    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
    PathAttribute attr = (PathAttribute) cc.getAttribute("content");
    assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());

    view.render(new HashMap(), request, response);
    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
    attr = (PathAttribute) cc.getAttribute("content");
    assertEquals("/WEB-INF/jsp/content.jsp", attr.getValue());
  }
View Full Code Here

TOP

Related Classes of org.apache.struts.tiles.ComponentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.