Package org.apache.shale.component

Examples of org.apache.shale.component.Token


    public void testMessageDefault() throws Exception {
       
        final String SUMMARY_MESSAGE = messages.getMessage("token.summary.invalid");
        final String DETAIL_MESSAGE = messages.getMessage("token.detail.invalid");;
               
        Token token = (Token) facesContext.getApplication().createComponent("org.apache.shale.Token");
        assertNotNull(token);
       
        UIViewRoot root = facesContext.getViewRoot();
        assertNotNull(root);
       
        // add token to the component tree
        root.getChildren().add(root.getChildCount(), token);
             
        token.setId("messageDefault");
        token.setMessageSummary(null)// no message property override
       
        StringBuffer htmlSnippet = encode(token);      
        // check rendered markup
        String id = getAttribute(htmlSnippet, "id");
        assertEquals("id", token.getClientId(facesContext), id);

        String name = getAttribute(htmlSnippet, "name");
        assertEquals("id", token.getClientId(facesContext), name);

        String type = getAttribute(htmlSnippet, "type");
        assertEquals("id", "hidden", type);

        String value = getAttribute(htmlSnippet, "value");
        assertNotNull("value", value);
       
        // simulate form post on dirty page
        Map map = facesContext.getExternalContext().getRequestParameterMap();
        map.put(id, value);
       
        // simulate apply values
        token.decode(facesContext);
        assertEquals("value", value, token.getSubmittedValue());
        
        // simulate validation and invalidates token
        token.validate(facesContext);
       
        checkNoMessages(token);
       
        // simulate double post
        token.validate(facesContext);
       
        // check for the custom message
        checkMessage(SUMMARY_MESSAGE, DETAIL_MESSAGE, token);
       
     }
View Full Code Here


        if ((context == null) || (component == null)) {
            throw new NullPointerException();
        }

        Token token = (Token) component;
        if (token.isRendered()) {
            String clientId = token.getClientId(context);
            Map map = context.getExternalContext().getRequestParameterMap();
            token.setSubmittedValue(map.get(clientId));
        }

    }
View Full Code Here

        if ((context == null) || (component == null)) {
            throw new NullPointerException();
        }

        Token token = (Token) component;
        if (token.isRendered()) {
            ResponseWriter writer = context.getResponseWriter();
            writer.startElement("input", token);
            String clientId = token.getClientId(context);
            writer.writeAttribute("id", clientId, "id");
            writer.writeAttribute("name", clientId, "id");
            writer.writeAttribute("type", "hidden", null);
            writer.writeAttribute("value", token.getToken(), null);
        }

    }
View Full Code Here

        if ((context == null) || (component == null)) {
            throw new NullPointerException();
        }

        Token token = (Token) component;
        if (token.isRendered()) {
            ResponseWriter writer = context.getResponseWriter();
            writer.endElement("input");
        }

    }
View Full Code Here

    public void testMessagePropertyOverride() throws Exception {

       final String SUMMARY_MESSAGE = "This page is dirty.  Evil browser back button.";
       final String DETAIL_MESSAGE = "This page has been mark as having durability of a single submit and this contract has been violated by the submission of a dirty page.";

       Token token = (Token) facesContext.getApplication().createComponent("org.apache.shale.Token");
       assertNotNull(token);
      
       UIViewRoot root = facesContext.getViewRoot();
       assertNotNull(root);
      
       // add token to the component tree
       root.getChildren().add(root.getChildCount(), token);
            
       token.setId("messagePropertyOverride");
       token.setMessageSummary(SUMMARY_MESSAGE);
       token.setMessageDetail(DETAIL_MESSAGE);
      
       StringBuffer htmlSnippet = encode(token);      
       // check rendered markup
       String id = getAttribute(htmlSnippet, "id");
       assertEquals("id", token.getClientId(facesContext), id);

       String name = getAttribute(htmlSnippet, "name");
       assertEquals("id", token.getClientId(facesContext), name);

       String type = getAttribute(htmlSnippet, "type");
       assertEquals("id", "hidden", type);

       String value = getAttribute(htmlSnippet, "value");
       assertNotNull("value", value);
      
       // simulate form post on dirty page
       Map map = facesContext.getExternalContext().getRequestParameterMap();
       map.put(id, value);
      
       // simulate apply values
       token.decode(facesContext);
       assertEquals("value", value, token.getSubmittedValue());
       
       // simulate validation and invalidates token
       token.validate(facesContext);
      
       checkNoMessages(token);
      
       // simulate double post
       token.validate(facesContext);
      
       // check for the custom message
       checkMessage(SUMMARY_MESSAGE, DETAIL_MESSAGE, token);
      
    }
View Full Code Here

        //value of the "token.invalid" key in the "org.apache.shale.util.TestBundle"
        final String SUMMARY_MESSAGE = "Invalid resubmit of the same form is bad news Lucy Luo";
        final String DETAIL_MESSAGE = "This page has been mark as having durability of a single submit and this contract has been violated by the submission of a dirty page.";
               
        Token token = (Token) facesContext.getApplication().createComponent("org.apache.shale.Token");
        assertNotNull(token);
       
        UIViewRoot root = facesContext.getViewRoot();
        assertNotNull(root);
       
        // add token to the component tree
        root.getChildren().add(root.getChildCount(), token);
             
        token.setId("messageFacesConfigBundleOverride");
        token.setMessageSummary(null)// no message property override
        token.setMessageDetail(null);   // no message property override
       
       
        StringBuffer htmlSnippet = encode(token);      
        // check rendered markup
        String id = getAttribute(htmlSnippet, "id");
        assertEquals("id", token.getClientId(facesContext), id);

        String name = getAttribute(htmlSnippet, "name");
        assertEquals("id", token.getClientId(facesContext), name);

        String type = getAttribute(htmlSnippet, "type");
        assertEquals("id", "hidden", type);

        String value = getAttribute(htmlSnippet, "value");
        assertNotNull("value", value);
       
        // simulate form post on dirty page
        Map map = facesContext.getExternalContext().getRequestParameterMap();
        map.put(id, value);
       
        // simulate apply values
        token.decode(facesContext);
        assertEquals("value", value, token.getSubmittedValue());
        
        // simulate validation and invalidates token
        token.validate(facesContext);
       
        checkNoMessages(token);
       
        // simulate double post
        token.validate(facesContext);
       
        // check for the custom message
        checkMessage(SUMMARY_MESSAGE, DETAIL_MESSAGE, token);
       
     }
View Full Code Here

TOP

Related Classes of org.apache.shale.component.Token

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.