Package org.apache.struts.tiles

Examples of org.apache.struts.tiles.ComponentDefinition


         HttpServletResponse response)
  throws Exception {

    System.out.println( "Start dynamic definition" );
      // Create template definition
    ComponentDefinition definition = new ComponentDefinition();
    String path = "/tutorial";
      // set definition 'contents'
    //definition.setTemplate( "/tutorial/basic/myFramesetLayout.jsp" );
    definition.put( "title", "My first dynamic frameset page", true );
      // using type="string" is the same as direct=true
    definition.put( "header", path + "/common/header.jsp", "string", null );
    definition.put( "footer", path + "/common/footer.jsp", true );
    definition.put( "menu", path + "/basic/menu.jsp", true );
    definition.put( "body", path + "/basic/helloBody.jsp", true );

    System.out.println( "definition=" + definition );
      // Save our definition as a bean :
    request.setAttribute( "templateDefinition", definition );
View Full Code Here


    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 )
        {
View Full Code Here

     * @throws JspException On errors processing tag.
     */
    public int doStartTag() throws JspException {
        // Do we extend a definition ?
        if (extendsDefinition != null && !extendsDefinition.equals("")) {
            ComponentDefinition parentDef =
                TagUtils.getComponentDefinition(extendsDefinition, pageContext);

            definition = new ComponentDefinition(parentDef);

        } else {
            definition = new ComponentDefinition();
        }

        // Set definitions attributes
        if (page != null) {
            definition.setTemplate(page);
View Full Code Here

    */
   public DefinitionCatalog( String catalogName, HttpServletRequest request, ServletContext context)
     throws FactoryNotFoundException, DefinitionsFactoryException
   {
     // Get definition containing list of definitions
   ComponentDefinition catalogDef = DefinitionsUtil.getDefinition( catalogName, request, context);
   if(debug)
     System.out.println( "Got definition " + catalogDef );
     // Get list of definition names
   List list = (List)catalogDef.getAttribute( DEFINITION_LIST_ATTRIBUTE );
   Iterator i = list.iterator();
   while(i.hasNext() )
     {
     String name = (String)i.next();
     System.out.println( "add " + name );
     ComponentDefinition def = DefinitionsUtil.getDefinition(name, request, context);
     if(def==null)
       throw new NoSuchDefinitionException("Can't find definition '" + name + "'" );
     add( name, def );
     } // end loop
   if(debug)
View Full Code Here

      throw new ServletException( "Error - CustomSkinAction : attribute '"
                                  + LAYOUT_ATTRIBUTE
                                  + "' not found in Tile's attributes. Need it to select appropriate layout"  );

      // Get user current skin
    ComponentDefinition definition = getCurrentDefinition( context, request, getServlet().getServletContext() );
      // get requested layout from definition
    String layout = (String)definition.getAttribute(layoutKey);
    if(layout==null)
      throw new ServletException( "Error - CustomSkinAction : no layout defined for key '"
                                  + layoutKey
                                  + "' in currently selected skin '"
                                  + getUserSetting(context, request ) + "'."  );
View Full Code Here

  {
    // Get selected key
  String selected = getUserSetting(context, request);

  DefinitionCatalog catalog = getCatalog( context, request, servletContext);
  ComponentDefinition definition =  (ComponentDefinition)catalog.get( selected );
  if( definition == null )
    definition = (ComponentDefinition)catalog.getDefault();

  return definition;
  }
View Full Code Here

            return (false);
        }

        ServletWebContext swcontext = (ServletWebContext) context;

        ComponentDefinition definition = null;
        try
        {
            definition = TilesUtil.getDefinition(forwardConfig.getPath(),
                    swcontext.getRequest(),
                    swcontext.getContext());
        }
        catch (FactoryNotFoundException ex)
        {
            // this is not a serious error, so log at low priority
            log.debug("Tiles DefinitionFactory not found, so pass to next command.");
            return false;
        }

        // Do we do a forward (original behavior) or an include ?
        boolean doInclude = false;
        ComponentContext tileContext = null;

        // Get current tile context if any.
        // If context exists, we will do an include
        tileContext = ComponentContext.getContext(swcontext.getRequest());
        doInclude = (tileContext != null);

        // Controller associated to a definition, if any
        Controller controller = null;

        // Computed uri to include
        String uri = null;

        if (definition != null)
        {
            // We have a "forward config" definition.
            // We use it to complete missing attribute in context.
            // We also get uri, controller.
            uri = definition.getPath();
            controller = definition.getOrCreateController();

            if (tileContext == null) {
                tileContext =
                        new ComponentContext(definition.getAttributes());
                ComponentContext.setContext(tileContext, swcontext.getRequest());

            } else {
                tileContext.addMissing(definition.getAttributes());
            }
        }

        // Process definition set in Action, if any.  This may override the
        // values for uri or controller found using the ForwardConfig, and
        // may augment the tileContext with additional attributes.
        // :FIXME: the class DefinitionsUtil is deprecated, but I can't find
        // the intended alternative to use.
        definition = DefinitionsUtil.getActionDefinition(swcontext.getRequest());
        if (definition != null) { // We have a definition.
                // We use it to complete missing attribute in context.
                // We also overload uri and controller if set in definition.
                if (definition.getPath() != null) {
                    log.debug("Override forward uri "
                              + uri
                              + " with action uri "
                              + definition.getPath());
                        uri = definition.getPath();
                }

                if (definition.getOrCreateController() != null) {
                    log.debug("Override forward controller with action controller");
                        controller = definition.getOrCreateController();
                }

                if (tileContext == null) {
                        tileContext =
                                new ComponentContext(definition.getAttributes());
                        ComponentContext.setContext(tileContext, swcontext.getRequest());
                } else {
                        tileContext.addMissing(definition.getAttributes());
                }
        }


        if (uri == null) {
View Full Code Here

        }

        // Try to dispatch to requested definition
        try {
            // Read definition from factory, but we can create it here.
            ComponentDefinition definition =
                TilesUtil.getDefinition(
                    name,
                    request,
                    getServlet().getServletContext());
                   
View Full Code Here

    log.debug("Extract menu item from '" + object + "'");

    if (object instanceof String) { // definition name
      try {
        ComponentDefinition def =
          DefinitionsUtil.getDefinition(
            (String) object,
            request,
            servletContext);

        extractItems(result, def, request, servletContext);

      } catch (Exception ex) { // silently fail
      }

    } else if (object instanceof List) {
      List list = (List) object;
      Iterator iter = list.iterator();
      while (iter.hasNext()) {
        extractItems(result, iter.next(), request, servletContext);
      }

    } else if (object instanceof ComponentDefinition) {
      ComponentDefinition definition = (ComponentDefinition) object;
      Object attribute = definition.getAttribute("items");
      if (attribute == null) {
        attribute = definition.getAttribute("list");
      }

      if (attribute == null) {
        return;
      }
View Full Code Here

  * @throws JspException InstantiationException Can't create requested controller
   */
  protected TagHandler processDefinitionName(String name) throws JspException {

    try {
        ComponentDefinition definition = TilesUtil.getDefinition(name, (HttpServletRequest)pageContext.getRequest(),pageContext.getServletContext());
        if (definition == null) { // is it possible ?
            throw new NoSuchDefinitionException();
        }
        return processDefinition(definition);

View Full Code Here

TOP

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

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.