Package org.apache.myfaces.config.impl.digester.elements

Examples of org.apache.myfaces.config.impl.digester.elements.ManagedBean


        if (rc.getManagedBeans().containsKey(beanName))
        {
            throw new ItemExistsException(beanName);
        }
        // register now
        ManagedBean mbi = new ManagedBean();
        mbi.setName(beanName);
        mbi.setBeanClass(beanClass);
        mbi.setScope(scope);
        rc.addManagedBean(beanName, mbi);
  }
View Full Code Here


     * the session, the application and the none scope.
     */
    public void testIsInValidScope()
    {
        // create sessionBean referencing requestBean
        ManagedBean sessionBean = new ManagedBean();
        sessionBean.setBeanClass(TestBean.class.getName());
        sessionBean.setName("sessionBean");
        sessionBean.setScope("session");
        ManagedProperty anotherBeanProperty = new ManagedProperty();
        anotherBeanProperty.setPropertyName("anotherBean");
        anotherBeanProperty.setValue("#{requestBean}");
        sessionBean.addProperty(anotherBeanProperty);
        runtimeConfig.addManagedBean("sessionBean", sessionBean);
       
        // create requestBean
        ManagedBean requestBean = new ManagedBean();
        requestBean.setBeanClass(TestBean.class.getName());
        requestBean.setName("requestBean");
        requestBean.setScope("request");
        runtimeConfig.addManagedBean("requestBean", requestBean);
       
        try
        {
            new MockValueExpression("#{sessionBean}", TestBean.class).getValue(facesContext.getELContext());
View Full Code Here

     * references if the ProjectStage is not Production.
     */
    public void testIsInValidScopeWithCustomScopes()
    {
        // create scopeBean
        ManagedBean scopeBean = new ManagedBean();
        scopeBean.setBeanClass(TestBean.class.getName());
        scopeBean.setName("scopeBean");
        scopeBean.setScope("session");
        runtimeConfig.addManagedBean("scopeBean", scopeBean);
       
        // create sessionBean referencing requestBean
        ManagedBean sessionBean = new ManagedBean();
        sessionBean.setBeanClass(TestBean.class.getName());
        sessionBean.setName("sessionBean");
        sessionBean.setScope("#{scopeBean.scope}");
        ManagedProperty anotherBeanProperty = new ManagedProperty();
        anotherBeanProperty.setPropertyName("anotherBean");
        anotherBeanProperty.setValue("#{requestBean}");
        sessionBean.addProperty(anotherBeanProperty);
        runtimeConfig.addManagedBean("sessionBean", sessionBean);
       
        // create requestBean
        ManagedBean requestBean = new ManagedBean();
        requestBean.setBeanClass(TestBean.class.getName());
        requestBean.setName("requestBean");
        requestBean.setScope("request");
        runtimeConfig.addManagedBean("requestBean", requestBean);
       
        try
        {
            new MockValueExpression("#{sessionBean}", TestBean.class).getValue(facesContext.getELContext());
View Full Code Here

     * This test is to test the view scope, introduced in jsf 2.0.
     */
    public void testIsInValidScopeViewScope()
    {
        // create viewBean referencing requestBean
        ManagedBean viewBean = new ManagedBean();
        viewBean.setBeanClass(TestBean.class.getName());
        viewBean.setName("viewBean");
        viewBean.setScope("view");
        ManagedProperty anotherBeanProperty = new ManagedProperty();
        anotherBeanProperty.setPropertyName("anotherBean");
        anotherBeanProperty.setValue("#{requestBean}");
        viewBean.addProperty(anotherBeanProperty);
        runtimeConfig.addManagedBean("viewBean", viewBean);
       
        // create requestBean
        ManagedBean requestBean = new ManagedBean();
        requestBean.setBeanClass(TestBean.class.getName());
        requestBean.setName("requestBean");
        requestBean.setScope("request");
        runtimeConfig.addManagedBean("requestBean", requestBean);
       
        try
        {
            new MockValueExpression("#{viewBean}", TestBean.class).getValue(facesContext.getELContext());
View Full Code Here

        Injector injector = Guice.createInjector(new ShoppingModule());
        servletContext.setAttribute(GuiceResolver.KEY, injector);
       
        // simulate Myfaces starting up
        RuntimeConfig rc = RuntimeConfig.getCurrentInstance(externalContext);
        ManagedBean bean = new ManagedBean();
        bean.setBeanClass(ShoppingCart.class.getName());
        bean.setScope("request");
        rc.addManagedBean("shoppingCart", bean);
       
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public void testCustomScope()
    {
        // create the custom scope
        ManagedBean scopeBean = new ManagedBean();
        scopeBean.setBeanClass(HashMap.class.getName());
        scopeBean.setName("scopeBean");
        scopeBean.setScope("application");
        runtimeConfig.addManagedBean("scopeBean", scopeBean);
       
        // create the managed bean
        ManagedBean beanInCustomScope = new ManagedBean();
        beanInCustomScope.setBeanClass(ArrayList.class.getName());
        beanInCustomScope.setName("beanInCustomScope");
        beanInCustomScope.setScope("#{scopeBean}");
        runtimeConfig.addManagedBean("beanInCustomScope", beanInCustomScope);
       
        // resolve the managed bean
        Object resolvedBeanInCustomScope = new MockValueExpression("#{beanInCustomScope}", List.class)
                                                   .getValue(facesContext.getELContext());
View Full Code Here

     * of the value, and the type of the value.
     */
    public void testCustomScopeNoMap()
    {
        // create the custom scope
        ManagedBean scopeBean = new ManagedBean();
        // Scope is ArrayList instead of HashMap
        scopeBean.setBeanClass(ArrayList.class.getName());
        scopeBean.setName("scopeBean");
        scopeBean.setScope("application");
        runtimeConfig.addManagedBean("scopeBean", scopeBean);
       
        // create the managed bean
        ManagedBean beanInCustomScope = new ManagedBean();
        beanInCustomScope.setBeanClass(ArrayList.class.getName());
        beanInCustomScope.setName("beanInCustomScope");
        beanInCustomScope.setScope("#{scopeBean}");
        runtimeConfig.addManagedBean("beanInCustomScope", beanInCustomScope);
       
        // resolve the managed bean
        try
        {
            new MockValueExpression("#{beanInCustomScope}", List.class)
                    .getValue(facesContext.getELContext());
        }
        catch (FacesException fe)
        {
            // the message must contain ...
            final String message = fe.getMessage();
            // ... the expression string
            assertTrue(message.contains(beanInCustomScope.getManagedBeanScope()));
            Object resolvedScopeBean = new MockValueExpression("#{scopeBean}", List.class)
                                               .getValue(facesContext.getELContext());
            // ... the toString() of the value
            assertTrue(message.contains(resolvedScopeBean.toString()));
            // ... and the type of the value
View Full Code Here

     * The ManagedBeanResolver only tries to detect cyclic references if ProjectStage != Production.
     */
    public void testCustomScopeCyclicReferences()
    {
        // create m1
        ManagedBean m1 = new ManagedBean();
        m1.setBeanClass(TestBean.class.getName());
        m1.setName("m1");
        m1.setScope("#{m2.scope}");
        runtimeConfig.addManagedBean("m1", m1);
       
        // create m2
        ManagedBean m2 = new ManagedBean();
        m2.setBeanClass(TestBean.class.getName());
        m2.setName("m2");
        m2.setScope("#{m1.scope}");
        runtimeConfig.addManagedBean("m2", m2);
       
        // try to resolve m1
        try
        {
View Full Code Here

     * Tests the view scope, which was introduced in jsf 2.0
     */
    public void testViewScope()
    {
        // create the managed bean
        ManagedBean beanInViewScope = new ManagedBean();
        beanInViewScope.setBeanClass(ArrayList.class.getName());
        beanInViewScope.setName("beanInViewScope");
        beanInViewScope.setScope("view");
        runtimeConfig.addManagedBean("beanInViewScope", beanInViewScope);
       
        // resolve the managed bean
        Object resolvedBeanInCustomScope = new MockValueExpression("#{beanInViewScope}", List.class)
                                                   .getValue(facesContext.getELContext());
View Full Code Here

     * references if the ProjectStage is not Production.
     */
    public void testIsInValidScopeWithCustomScopes()
    {
        // create scopeBean
        ManagedBean scopeBean = new ManagedBean();
        scopeBean.setBeanClass(TestBean.class.getName());
        scopeBean.setName("scopeBean");
        scopeBean.setScope("session");
        runtimeConfig.addManagedBean("scopeBean", scopeBean);
       
        // create sessionBean referencing requestBean
        ManagedBean sessionBean = new ManagedBean();
        sessionBean.setBeanClass(TestBean.class.getName());
        sessionBean.setName("sessionBean");
        sessionBean.setScope("#{scopeBean.scope}");
        ManagedProperty anotherBeanProperty = new ManagedProperty();
        anotherBeanProperty.setPropertyName("anotherBean");
        anotherBeanProperty.setValue("#{requestBean}");
        sessionBean.addProperty(anotherBeanProperty);
        runtimeConfig.addManagedBean("sessionBean", sessionBean);
       
        // create requestBean
        ManagedBean requestBean = new ManagedBean();
        requestBean.setBeanClass(TestBean.class.getName());
        requestBean.setName("requestBean");
        requestBean.setScope("request");
        runtimeConfig.addManagedBean("requestBean", requestBean);
       
        try
        {
            new MockValueExpression("#{sessionBean}", TestBean.class).getValue(facesContext.getELContext());
View Full Code Here

TOP

Related Classes of org.apache.myfaces.config.impl.digester.elements.ManagedBean

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.