com.t2decode.sample.HomeController.java Source code

Java tutorial

Introduction

Here is the source code for com.t2decode.sample.HomeController.java

Source

/*
 * This file is part of sample.
 *
 * sample is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * sample is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * sample. If not, see <http://www.gnu.org/licenses/>.
 */
package com.t2decode.sample;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.context.MessageSource;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.portlet.ActionResponse;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestParam;

import com.t2decode.sample.domain.Contact;
import com.t2decode.sample.service.ContactService;

/**
 * Handles requests for the view mode.
 */
@Controller
@RequestMapping("VIEW")
public class HomeController {

    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private ContactService contactService;

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RenderMapping
    public String home(Locale locale, Model model) {
        model.addAttribute("contactList", contactService.listContact());
        return "list";
    }

}