Package com.dtikhonov.controller

Source Code of com.dtikhonov.controller.GreetingController

package com.dtikhonov.controller;

/**
* Created by dtikhonov on 08/05/14.
*/
import com.dtikhonov.MessageManager;
import com.dtikhonov.listeners.MyMessageListener;
import com.dtikhonov.model.Message;
import com.dtikhonov.publishers.MyPublisherInterface;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.beans.factory.annotation.Autowired;

@Controller
public class GreetingController {
    private final static Logger logger = Logger.getLogger(MyMessageListener.class);
    private String result = "result";
    @Autowired
    private MessageManager messageManager;
    @Autowired
    private MyPublisherInterface meesagePublisher;
    public void setResult(String result){
        this.result = result;
    }
    @RequestMapping(value="/greeting", method=RequestMethod.GET)
    public ModelAndView greeting() {
        return new ModelAndView("greeting", "command", new Message());
    }
    @RequestMapping(value="/addGreeting", method=RequestMethod.POST)
    public String addGreeting(@ModelAttribute("SpringWeb")Message message, Model model) {
        messageManager.addMessage(message);
        model.addAttribute("message", message);
        logger.info("add message");
        meesagePublisher.publish(message.getContent());
        return result;
    }
    @RequestMapping(value="/messageList", method=RequestMethod.GET)
    public ModelAndView listMessage(){
        ModelAndView modelAndView = new ModelAndView("messages");
        modelAndView.addObject("messageListSize", messageManager.getMessageList().size());
        modelAndView.addObject("messageList", messageManager.getMessageList());

        return modelAndView;
    }
}
TOP

Related Classes of com.dtikhonov.controller.GreetingController

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.