Package org.apache.shale.clay.config.beans

Examples of org.apache.shale.clay.config.beans.ComponentBean


        ServletContextListener chainsListener = new ChainListener();
        ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
        chainsListener.contextInitialized(servletContextEvent);
       
        // find the config bean definition in the commons XML config file
        ComponentBean configBean = standardConfigBean.getElement("acme:city");
        assertNotNull("acme:city exists", configBean);
        assertEquals("id", "city", configBean.getId());
       
        AttributeBean size = configBean.getAttribute("size");
        assertNotNull("size", size);
        assertEquals("size", "20", size.getValue());
       
        AttributeBean value = configBean.getAttribute("value");
        assertNotNull("value", value);
        assertEquals("value", "#{@managed-bean-name.city}", value.getValue());
       
        AttributeBean maxlength = configBean.getAttribute("maxlength");
        assertNotNull("maxlength", maxlength);
        assertEquals("maxlength", "30", maxlength.getValue());
       
        AttributeBean required = configBean.getAttribute("required");
        assertNotNull("required", required);
        assertEquals("required", "true", required.getValue());
      

        // load a template that points/extends the acme:city widget
        ComponentBean templateRoot = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/altns.html");
        assertNotNull("/org/apache/shale/clay/config/altns.html",  templateRoot);
       
        // config bean after extend by the html template
        ComponentBean cityConfigBean = findForId(configBean.getId(), templateRoot);
        assertNotNull("city from html template", cityConfigBean);
       
        // inherit from acme:city
        assertEquals("id", "city", cityConfigBean.getId());
       
        // html override
        size = cityConfigBean.getAttribute("size");
        assertNotNull("size", size);
        assertEquals("size", "10", size.getValue());
       
        // inherit from acme:city
        value = cityConfigBean.getAttribute("value");
        assertNotNull("value", value);
        assertEquals("value", "#{@managed-bean-name.city}", value.getValue());
       
        // html override
        maxlength = cityConfigBean.getAttribute("maxlength");
        assertNotNull("maxlength", maxlength);
        assertEquals("maxlength", "100", maxlength.getValue());
       
        // html override
        required = cityConfigBean.getAttribute("required");
        assertNotNull("required", required);
        assertEquals("required", "false", required.getValue());
       
        // just because we can
        chainsListener.contextDestroyed(servletContextEvent);
View Full Code Here


        if (root.getId() != null && root.getId().equals(id)) {
           return root;
        }
        Iterator ci = root.getChildren().iterator();
        while (ci.hasNext()) {
           ComponentBean child = (ComponentBean) ci.next();
           ComponentBean target = findForId(id, child);
           if (target != null) {
              return target;
           }
        }
       
View Full Code Here

       AttributeBean attr = new AttributeBean();
       attr.setName("value");
       attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
       attr.setValue("10");
      
       ComponentBean displayElement = new ComponentBean();
       displayElement.setJsfid("inputText");
       displayElement.setComponentType("javax.faces.HtmlOutputText");
       displayElement.setId("testId");
       displayElement.addAttribute(attr);
      
       assertNotNull("attribute case insensitive", displayElement.getAttribute("VaLue"));
      
       ClayContext clayContext = new ClayContext();
       clayContext.setFacesContext(facesContext);
       clayContext.setChild(child);
       clayContext.setAttribute(attr);
View Full Code Here

           AttributeBean attr = new AttributeBean();
           attr.setName("value");
           attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
           attr.setValue("@value")//symbolic attribute
                     
           ComponentBean displayElement = new ComponentBean();
           displayElement.setJsfid("inputText");
           displayElement.setComponentType("javax.faces.HtmlOutputText");
           displayElement.setId("testId");
           displayElement.addAttribute(attr);
           displayElement.addSymbol(createSymbol("@value", "10"));
                     
           ClayContext clayContext = new ClayContext();
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           Command command = new PropertyValueCommand();
           boolean isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = 10", "10", child.getValue());

          
           // test a symbol value of an el value
           child = (javax.faces.component.html.HtmlOutputText)
                        facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", "#{value}"));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
           servletContext.setAttribute("value", "10");
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = 10", "10", child.getValue());

          
           // test a symbol value with a null value symbol replacement
           child = (javax.faces.component.html.HtmlOutputText)
                 facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", null));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = null", null, child.getValue());


           // test a symbol value with an empty String value. 
           // this will evaluate to null since it is a symbol replacement.
           child = (javax.faces.component.html.HtmlOutputText)
                     facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", ""));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = null", null, child.getValue());

           //no symbol replacement for a empty string - should return
           //an empty string.  This allows components like the selectItem
           //to create an empty select list pick.
           attr.setValue("")//empty string          
           child = (javax.faces.component.html.HtmlOutputText)
                        facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = \"\"", "", child.getValue());

           //Case insensitive and reoccurring replacement
           attr.setValue("@TeSt1, @tEst1 never @test2; @test1, @teSt1 till ya @tesT3")//test multiple symbols          
           child = (javax.faces.component.html.HtmlOutputText)
                     facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@test1", "rock"));
           displayElement.addSymbol(createSymbol("@test2", "stop"));
           displayElement.addSymbol(createSymbol("@test3", "drop"));

           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           // normally done in the AssignChildrenCommand
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = \"rock, rock never stop; rock, rock till ya drop\"",
                   "rock, rock never stop; rock, rock till ya drop", child.getValue());
View Full Code Here

        UIComponent parent = (UIComponent)
              facesContext.getApplication().createComponent("javax.faces.NamingContainer");
        assertNotNull("javax.faces.NamingContainer", parent);
        parent.setId("parent");
       
        ComponentBean displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("@wynn");
        displayElement.addSymbol(createSymbol("@wynn", "test"));
       
        ClayContext clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        Command command = new CreateComponentCommand();
        boolean isFinal = command.execute(clayContext);
        assertEquals("command finished", false, isFinal);
       
        UIComponent child = (UIComponent) clayContext.getChild();
        assertNotNull("child", child);
       
        assertEquals("id = test", "test", child.getId());
       
       
        //null component id symbol replacement
        parent = (UIComponent)
             facesContext.getApplication().createComponent("javax.faces.NamingContainer");
        assertNotNull("javax.faces.NamingContainer", parent);
        parent.setId("parent");
       
        displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("@wynn");
        displayElement.addSymbol(createSymbol("@wynn", null));
       
        clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        command = new CreateComponentCommand();
        try {
            isFinal = command.execute(clayContext);
            assertTrue("id replacement failed", false);
        } catch (RuntimeException e) {
            assertTrue("null component id",
                    e.getMessage().startsWith("The component symbol substitution failed for id \"@wynn\""));   
        }
       
        //missing component id symbol replacement
        parent = (UIComponent)
             facesContext.getApplication().createComponent("javax.faces.NamingContainer");
        assertNotNull("javax.faces.NamingContainer", parent);
        parent.setId("parent");
       
        displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("@wynn");
       
        clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        command = new CreateComponentCommand();
        try {
            isFinal = command.execute(clayContext);
View Full Code Here

        AttributeBean attr = new AttributeBean();
        attr.setName("value");
        attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
        attr.setValue("@[a]@[ab]")//symbolic attribute
                  
        ComponentBean displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("testId");
        displayElement.addAttribute(attr);
        displayElement.addSymbol(createSymbol("@[ab]", "43"));
        displayElement.addSymbol(createSymbol("@[a]", "67"));
            
        ClayContext clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setChild(child);
        clayContext.setAttribute(attr);
        clayContext.setDisplayElement(displayElement);
        // normally done in the AssignChildrenCommand
        clayContext.setSymbols(displayElement.getSymbols());
               
        Command command = new PropertyValueCommand();
        boolean isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
        assertEquals("value = 6743", "6743", child.getValue());     

   
        //create a target component
        child = (javax.faces.component.html.HtmlOutputText)
                           facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
        assertNotNull("javax.faces.HtmlOutputText", child);

        attr.setValue("@{a}@{ab}")//symbolic attribute
        displayElement.addSymbol(createSymbol("@{ab}", "43"));
        displayElement.addSymbol(createSymbol("@{a}", "67"));

        clayContext.setChild(child);

        isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
        assertEquals("value = 6743", "6743", child.getValue());     


       
        //create a target component
        child = (javax.faces.component.html.HtmlOutputText)
                           facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
        assertNotNull("javax.faces.HtmlOutputText", child);

        attr.setValue("@(a)@(ab)")//symbolic attribute
        displayElement.addSymbol(createSymbol("@(ab)", "43"));
        displayElement.addSymbol(createSymbol("@(a)", "67"));

        clayContext.setChild(child);

        isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
View Full Code Here

        //loads the default and the custom address config files
        loadConfigFile("/org/apache/shale/clay/config/address-config.xml");
         
        // test vertical inheritance
        ComponentBean bean = standardConfigBean.getElement("baseSymbolLabel");
        assertNotNull(bean);
        //look for a base symbol definition
        SymbolBean symbol = (SymbolBean) bean.getSymbols().get("@mystyle");
        assertNotNull(symbol);
        assertEquals("@mystyle == color:blue", "color:blue", symbol.getValue());

        // symbol1Label extends baseSymbolLabel
        bean = standardConfigBean.getElement("symbol1Label");
        assertNotNull(bean);
        //look for inherited symbol
        symbol = (SymbolBean) bean.getSymbols().get("@mystyle");
        assertNotNull(symbol);
        assertEquals("@mystyle == color:blue", "color:blue", symbol.getValue());

        // symbol2Label extends symbol1Label
        bean = standardConfigBean.getElement("symbol2Label");
        assertNotNull(bean);
        //look for an overridden symbol
        symbol = (SymbolBean) bean.getSymbols().get("@mystyle");
        assertNotNull(symbol);
        assertEquals("@mystyle == color:red", "color:red", symbol.getValue());

       
        //test nested/inner element inheritance
        bean = standardConfigBean.getElement("symbolPanel");
        assertNotNull(bean);
       
        assertEquals(bean.getChildren().size(), 2);
        Iterator ei = bean.getChildrenIterator();
        while (ei.hasNext()) {
            ElementBean ebean = (ElementBean) ei.next();
            if (ebean.getRenderId() == 1) {
                //look for inherited symbol
                symbol = (SymbolBean) ebean.getSymbols().get("@mystyle");
View Full Code Here

    }

    private ComponentBean createVerbatim(Class classz, String value)
            throws InstantiationException, IllegalAccessException {

        ComponentBean target = (ComponentBean) classz.newInstance();
        target.setJsfid("verbatim");
        target.setComponentType("javax.faces.HtmlOutputText");

        AttributeBean attr = new AttributeBean();
        attr.setBindingType(AttributeBean.BINDING_TYPE_VALUE);
        attr.setName("value");
        attr.setValue(value);
        target.addAttribute(attr);

        attr = new AttributeBean();
        attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
        attr.setName("escape");
        attr.setValue(Boolean.FALSE.toString());
        target.addAttribute(attr);

        attr = new AttributeBean();
        attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
        attr.setName("isTransient");
        attr.setValue(Boolean.TRUE.toString());
        target.addAttribute(attr);

        return target;
    }
View Full Code Here

        return target;
    }

    public void testRollup() throws Exception {

        ComponentBean root = createVerbatim(ComponentBean.class, "0");
        for (int i = 1; i < 10; i++) {
            ElementBean child = (ElementBean) createVerbatim(ElementBean.class,
                    String.valueOf(i));
            child.setRenderId(i);
            root.addChild(child);
        }

        ((TemplateConfigBean) htmlTemplateConfigBean).optimizeTree(root);

        assertEquals("#Children", 0, root.getChildren().size());

        AttributeBean attr = root.getAttribute("value");
        assertNotNull(attr);

        assertEquals("root value", "0123456789", attr.getValue());

    }
View Full Code Here

        //   + 5
        //   + 6
        //   + 7
        //   + 8
        //   + 9
        ComponentBean root = createVerbatim(ComponentBean.class, "0");
        ElementBean lastChild = null;
        for (int i = 1; i < 5; i++) {
            lastChild = (ElementBean) createVerbatim(ElementBean.class, String
                    .valueOf(i));
            lastChild.setRenderId(i);
            root.addChild(lastChild);
        }

        for (int i = 5; i < 10; i++) {
            ElementBean child = (ElementBean) createVerbatim(ElementBean.class,
                    String.valueOf(i));
            child.setRenderId(i);
            lastChild.addChild(child);
        }

        ((TemplateConfigBean) htmlTemplateConfigBean).optimizeTree(root);

        assertEquals("#Children", 0, root.getChildren().size());

        AttributeBean attr = root.getAttribute("value");
        assertNotNull(attr);

        assertEquals("root value", "0123456789", attr.getValue());

    }
View Full Code Here

TOP

Related Classes of org.apache.shale.clay.config.beans.ComponentBean

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.