Examples of AjaxResponse


Examples of org.springmodules.xt.ajax.AjaxResponse

   
    /**
     * Show a feed entry.
     */
    private AjaxResponse showEntry(AjaxActionEvent event) {
        AjaxResponse response = new AjaxResponseImpl("UTF-8");
        String subscriptionName = event.getParameters().get("subscription");
        if (subscriptionName != null) {
            try {
                // Get the feed from user's subscriptions:
                Feed feed = this.getFeedFromSubscriptionName(subscriptionName);
                if (feed != null) {
                    // Get the feed entry at the corresponding index:
                    int entryIndex = Integer.parseInt(event.getParameters().get("entryIndex"));
                    Entry entry = (Entry) feed.getEntries().get(entryIndex);
                   
                    // Set the entry object in the request:
                    event.getHttpRequest().setAttribute("entry", entry);
                    // Render the entry via external JSP content:
                    JspComponent jsp = new JspComponent(event.getHttpRequest(), "/personal/includes/entryPanel.page");
                   
                    // Change the class of the web element that fired the event:
                    SetAttributeAction action1 = new SetAttributeAction(event.getElementId(), "class", "expanded");
                   
                    // Construct the CSS selector identifying the web page part that will be updated with the JSP content:
                    String selector = new StringBuilder("#").append(event.getElementId()).append("~").append("div.entryBody").toString();
                    ElementMatcher matcher = new SelectorMatcher(Arrays.asList(selector));
                    // Replace the content of the web page part identified by the selector:
                    ReplaceContentAction action2 = new ReplaceContentAction(matcher, jsp);
                    // Call a client-side javascript function:
                    Map<String, Object> params = new HashMap<String, Object>();
                    params.put("selector", selector);
                    ExecuteJavascriptFunctionAction action3 = new ExecuteJavascriptFunctionAction("showEntryEffect", params);
                   
                    // Add actions to response:
                    response.addAction(action1);
                    response.addAction(action2);
                    response.addAction(action3);
                } else {
                    this.renderErrorMessage(event, response, "message.error.feed.not.found", "No feed found.");
                }
            } catch (UserNotExistentException ex) {
                logger.warn(ex.getMessage(), ex.getCause());
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

    /**
     * Hide the feed entry: this could be completely done via pure client side javascript, but
     * this is a sample application, so let us play a bit ;)
     */
    private AjaxResponse hideEntry(AjaxActionEvent event) {
        AjaxResponse response = new AjaxResponseImpl("UTF-8");
       
        // Change the class of the web element that fired the event:
        SetAttributeAction action1 = new SetAttributeAction(event.getElementId(), "class", "closed");
       
        // Construct the CSS selector identifying the web page part that will be updated :
        String selector = new StringBuilder("#").append(event.getElementId()).append("~").append("div.entryBody").toString();
        ElementMatcher matcher = new SelectorMatcher(Arrays.asList(selector));
        // Call a client-side javascript function for hiding the entry:
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("selector", selector);
        ExecuteJavascriptFunctionAction action2 = new ExecuteJavascriptFunctionAction("hideEntryEffect", params);
       
        // Add actions to response:
        response.addAction(action1);
        response.addAction(action2);
       
        return response;
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

    }
   
    public AjaxResponse validateUsername(AjaxActionEvent event) {
        String username = event.getParameters().get("username");
        boolean exists = this.userService.checkUserAccount(username);
        AjaxResponse response = new AjaxResponseImpl("UTF-8");
        if (!exists) {
            TaggedText msg = new TaggedText(
                    this.messageSource.getMessage("user.available.username", null, "Available", LocaleContextHolder.getLocale()),
                    TaggedText.Tag.SPAN);
            msg.addAttribute("class", "okMessage");
           
            ReplaceContentAction action = new ReplaceContentAction("username.validation", msg);
           
            response.addAction(action);
        } else {
            TaggedText msg = new TaggedText(
                    this.messageSource.getMessage("user.unavailable.username", null, "Not Available", LocaleContextHolder.getLocale()),
                    TaggedText.Tag.SPAN);
            msg.addAttribute("class", "warnMessage");
           
            ReplaceContentAction action = new ReplaceContentAction("username.validation", msg);
           
            response.addAction(action);
        }
        return response;
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

       
        assertXpathNotExists("/ajax-response/*", rendering);
    }
   
    public void testValidateWithNoErrorsPart2() throws Exception {
        AjaxResponse response = null;
        String rendering = null;
        DefaultValidationHandler handler = new DefaultValidationHandler();
        handler.setMessageSource(new DelegatingMessageSource());
        handler.setSuccessRenderingCallback(new SuccessRenderingCallback() {
            public AjaxAction[] getSuccessActions(AjaxSubmitEvent event) {
                AjaxAction action = new ReplaceContentAction("test", new SimpleText("Default message"));
                return new AjaxAction[]{action};
            }
        });
       
        response = handler.validate(submitEvent);
        rendering = response.render();
        System.out.println(rendering);
       
        assertXpathEvaluatesTo("Default message", "//replace-children/content", rendering);
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        assertXpathEvaluatesTo("Default message", "//replace-children/content", rendering);
    }
   
    public void testEncoding() throws Exception {
        DefaultValidationHandler handler = new DefaultValidationHandler();
        AjaxResponse response = handler.validate(submitEvent);
        String rendering = response.render();
       
        System.out.println(rendering);
       
        assertTrue(rendering.indexOf("encoding=\"ISO-8859-1\"") != -1);
       
        handler = new DefaultValidationHandler();
       
        handler.setAjaxResponseEncoding("UTF-8");
       
        response = handler.validate(submitEvent);
        rendering = response.render();
       
        System.out.println(rendering);
       
        assertTrue(rendering.indexOf("encoding=\"UTF-8\"") != -1);
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        this.sender = new AjaxResponseSender();
    }
   
    public void testSendResponse() throws Exception {
        MockHttpServletResponse httpResponse = new MockHttpServletResponse();
        AjaxResponse ajaxResponse = new AjaxResponseImpl();
       
        String text = "simple text";
       
        ajaxResponse.addAction(new ReplaceContentAction("test", new SimpleText(text)));
       
        this.sender.sendResponse(httpResponse, ajaxResponse);
       
        assertTrue(httpResponse.getContentAsString().contains(text));
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        Exception ex = new Exception("exception");
       
        RedirectExceptionHandler handler = new RedirectExceptionHandler();
        handler.setRedirectUrl("/ajax/exception.action");
       
        AjaxResponse response = handler.handle(httpRequest, ex);
        assertNotNull(response);
        assertXpathExists("//redirect/content/target/@url", response.render());
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        assertTrue(httpResponse.getContentAsString().contains(text));
    }
   
    public void testSendResponseWithI18nCharsSucceeds() throws Exception {
        MockHttpServletResponse httpResponse = new MockHttpServletResponse();
        AjaxResponse ajaxResponse = new AjaxResponseImpl("UTF-8");
       
        String text = "questo è un semplice testo";
       
        ajaxResponse.addAction(new ReplaceContentAction("test", new SimpleText(text)));
       
        this.sender.sendResponse(httpResponse, ajaxResponse);
       
        assertTrue(httpResponse.getContentAsString().contains(text));
    }
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        this.submitEvent = new AjaxSubmitEventImpl("submitEvent", request);
        this.submitEvent.setCommandObject(target);
    }
   
    public void testValidateWithErrorsPart1() throws Exception {
        AjaxResponse response = null;
        String rendering = null;
        DefaultValidationHandler handler = new DefaultValidationHandler();
        handler.setMessageSource(new DelegatingMessageSource());
       
        // Errors:
        this.submitEvent.setValidationErrors(this.errors);
       
        response = handler.validate(submitEvent);
        rendering = response.render();
        System.out.println(rendering);
       
        assertXpathEvaluatesTo("Default Message 1", "//append-as-children/content/div", rendering);
        assertXpathEvaluatesTo("wildcard", "//append-as-children/context/matcher/@matchMode", rendering);
        assertXpathExists("//execute-javascript/content/script", rendering);
View Full Code Here

Examples of org.springmodules.xt.ajax.AjaxResponse

        assertXpathExists("//execute-javascript/content/script", rendering);
        assertTrue(rendering.indexOf("new Effect.Highlight(\"ErrorCode1\",{\"startcolor\":\"#FF0A0A\"});") != -1);
    }
   
    public void testValidateWithErrorsPart2() throws Exception {
        AjaxResponse response = null;
        String rendering = null;
        DefaultValidationHandler handler = new DefaultValidationHandler();
        handler.setMessageSource(new DelegatingMessageSource());
        handler.setErrorRenderingCallback(new DefaultErrorRenderingCallback() {
            public Component getErrorComponent(AjaxSubmitEvent event, ObjectError error, MessageSource messageSource, Locale locale) {
                return new TaggedText(messageSource.getMessage(error.getCode(), null, error.getDefaultMessage() + " for event : " + event.getEventId(), locale), TaggedText.Tag.SPAN);
            }
        });
       
        // Errors:
        this.submitEvent.setValidationErrors(this.errors);
       
        response = handler.validate(submitEvent);
        rendering = response.render();
        System.out.println(rendering);
       
        assertXpathEvaluatesTo("Default Message 1 for event : submitEvent", "//append-as-children/content/span", rendering);
        assertXpathEvaluatesTo("wildcard", "//append-as-children/context/matcher/@matchMode", rendering);
        assertXpathExists("//execute-javascript/content/script", rendering);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.