Package org.apache.struts.tiles

Examples of org.apache.struts.tiles.ComponentContext


        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


      Controller controller) {

      this.page = page;
      this.role = role;
      this.controller = controller;
      subCompContext = new ComponentContext(attributes);
    }
View Full Code Here

     */
    public InsertHandler(String page, String role, Controller controller) {
      this.page = page;
      this.role = role;
      this.controller = controller;
      subCompContext = new ComponentContext();
    }
View Full Code Here

     * @exception JspException On errors processing tag.
     */
public int doStartTag() throws JspException
    {
      // retrieve component context
    ComponentContext compContext = (ComponentContext)pageContext.getAttribute(ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
    if( compContext == null )
        throw new JspException ( "Error - tag importAttribute : no tiles context found." );

      // set scope
    scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );

      // push attribute in requested context.
    if( name != null )
      {
      Object value = compContext.getAttribute(name);
        // Check if value exist and if we must send a runtime exception
      if( value == null )
        if(!isErrorIgnored)
          throw new JspException ( "Error - tag importAttribute : property '"+  name + "' not found in context. Check tag syntax" );
         else
          return SKIP_BODY;

      pageContext.setAttribute(name, value, scope);
      }
     else
      { // set all attributes
      Iterator names = compContext.getAttributeNames();
      while(names.hasNext())
        {
        String name = (String)names.next();
        if(name == null ) {
          if(!isErrorIgnored)
            throw new JspException ( "Error - tag importAttribute : encountered an attribute with key 'null'" );
          else
            return SKIP_BODY;
        }

        Object value = compContext.getAttribute(name);
        // Check if value exist and if we must send a runtime exception
        if( value == null ) {
          if(!isErrorIgnored)
            throw new JspException ( "Error - tag importAttribute : property '"+ name + "' has a value of 'null'" );
          else
View Full Code Here

      {
      return EVAL_PAGE;
      } // end if

      // Get context
    ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);

    if( compContext == null )
      throw new JspException ( "Error - tag.getAsString : component context is not defined. Check tag syntax" );

    Object value = compContext.getAttribute(attribute);
    if( value == null)
      { // no value : throw error or fail silently according to ignore
      if(isErrorIgnored == false )
        throw new JspException ( "Error - tag.getAsString : attribute '"+ attribute + "' not found in context. Check tag syntax" );
       else
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

    System.out.println("Enter action RetrievePortalAction");
      // Get current session.
    HttpSession session = request.getSession();

          // 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" );
      }

      // Get user portal list from user context
    PortalSettings settings = getSettings( context, session );

      // Set parameters for tiles
    context.putAttribute( "numCols", Integer.toString(settings.getNumCols()) );
    for( int i=0; i<settings.getNumCols(); i++ )
      context.putAttribute( "list"+i, settings.getListAt(i) );

    System.out.println("Exit action RetrievePortalAction");
    return (mapping.findForward("success"));
    }
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

     * @param beanName Name of bean to retrieve.
     * @param pageContext Current pageContext.
     * @return Requested bean or <code>null</code> if not found.
     */
    public static Object findAttribute(String beanName, PageContext pageContext) {
        ComponentContext compContext = ComponentContext.getContext(pageContext.getRequest());
       
        if (compContext != null) {
            Object attribute = compContext.findAttribute(beanName, pageContext);
            if (attribute != null) {
                return attribute;
            }
        }

View Full Code Here

     * @param pageContext Current pageContext.
     * @return Requested bean or <code>null</code> if not found.
     */
    public static Object getAttribute(String beanName, int scope, PageContext pageContext) {
        if (scope == ComponentConstants.COMPONENT_SCOPE) {
            ComponentContext compContext = ComponentContext.getContext(pageContext.getRequest());
            return compContext.getAttribute(beanName);
        }
        return pageContext.getAttribute(beanName, scope);
    }
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.