Package org.springmodules.xt.ajax

Examples of org.springmodules.xt.ajax.AjaxResponseImpl


   
    private static final Logger logger = Logger.getLogger(AjaxRedirectSender.class);
   
    public static void sendRedirect(HttpServletResponse httpResponse, String redirectUrl, Map model) throws IOException {
        logger.debug(new StringBuilder("Sending ajax redirect: ").append(redirectUrl));
        AjaxResponse ajaxResponse = new AjaxResponseImpl();
        ajaxResponse.addAction(new RedirectAction(redirectUrl, (Map) null));
        AjaxResponseSender.sendResponse(httpResponse, ajaxResponse);
    }
View Full Code Here


    private SuccessRenderingCallback successRenderingCallback = new DefaultSuccessRenderingCallback();
   
    protected MessageSource messageSource;
   
    public AjaxResponse validate(AjaxSubmitEvent event) {
        AjaxResponseImpl response = new AjaxResponseImpl(this.ajaxResponseEncoding);
       
        if (event.getValidationErrors() != null && event.getValidationErrors().hasErrors() == true) {
            this.removeOldErrors(event, response);
            this.putNewErrors(event, response);
        } else {
            AjaxAction[] successActions = this.successRenderingCallback.getSuccessActions(event);
            if (successActions != null && successActions.length > 0) {
                this.removeOldErrors(event, response);
                for (AjaxAction action : successActions) {
                    response.addAction(action);
                }
            }
        }
       
        this.afterValidation(event, response);
View Full Code Here

            model.put(this.exceptionMessageAttribute, ex.getMessage());
        } else {
            model.put(this.exceptionMessageAttribute, ex.getClass());
        }
        // Create the response with the redirect action:
        AjaxResponse ajaxResponse = new AjaxResponseImpl();
        AjaxAction ajaxRedirect = new RedirectAction(new StringBuilder(request.getContextPath()).append(this.redirectUrl).toString(), model);
        ajaxResponse.addAction(ajaxRedirect);
        return ajaxResponse;
    }
View Full Code Here

    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }
   
    public AjaxResponse viewFeed(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) {
                    // Render the feed via external JSP content:
                    event.getHttpRequest().setAttribute("feed", feed);
                    event.getHttpRequest().setAttribute("subscription", subscriptionName);
                    JspComponent jsp = new JspComponent(event.getHttpRequest(), "/personal/includes/feedPanel.page");
                    // Replace the content of the "viewer" page part:
                    ReplaceContentAction action1 = new ReplaceContentAction("viewer", jsp);
                    // Re-apply javascript Behaviour rules:
                    ApplyBehaviour action2 = new ApplyBehaviour();
                   
                    // Add actions to response:
                    response.addAction(action1);
                    response.addAction(action2);
                } 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

        }
        return response;
    }
   
    public AjaxResponse toggleEntry(AjaxActionEvent event) {
        AjaxResponse response = new AjaxResponseImpl("UTF-8");
        String currentStatus = event.getParameters().get("status");
        if (currentStatus != null && currentStatus.equals("closed")) {
            response = this.showEntry(event);
        } else if (currentStatus != null && currentStatus.equals("expanded")) {
            response = this.hideEntry(event);
View Full Code Here

   
    /**
     * 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

    /**
     * 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

    }
   
    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

        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

        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

TOP

Related Classes of org.springmodules.xt.ajax.AjaxResponseImpl

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.