Rectangle 27 2

I think you should use ajax(for example jquery),the following is spring mvc

@RequestMapping(value = "/admin/new/list", method = RequestMethod.GET)
@ResponseBody
public List<News> list()
{
  return newsDao.findAll();
}

and in the jsp page,you may use ajax util (for example jquery)

$.ajax({
            type: "GET",
            url: '<c:url value="/admin/new/list"/>',
            cache:false,
            dataType :'json',
            success: function(data){
                 alert(data);               
           }
    });

the data is json object I don't know whether the above is what you need

I am not looking for AJAX Call at all, I know this is another way. But this is not what I want exactly.

java - Springs MVC JSON Response and convert it to JS Object - Stack O...

java javascript spring java-ee spring-mvc
Rectangle 27 2

public class ArticleController {

    // inject the spring validator.
    @Autowired
    private LocalValidatorFactoryBean validator;

    @RequestMapping(value = "/edit", method = PUT)
    public String doEdit(@ModelAttribute("article") final Article article,
            final BindingResult bindingResult) {
        // generates article's tag, not editable by user
        article.setTag(generateTag(article));
        // validate
        validator.validate(article, bindingResult);

        if (bindingResult.hasErrors()) {
            return "/edit";
        } else {
            service.save(article);
            return "redirect:/list";
        }
    }
}
org.springframework.validation.Validator
LocalValidatorFactoryBean

java - How to re-run Bean Validation on form object? (Spring 4 MVC con...

java spring spring-mvc bean-validation
Rectangle 27 1

Try changing your method to return a String and, within your method, transform your list into a JSON String. For that, you could use google-gson but, given that we're playing with spring already and probably already have those dependencies in the project, you can use Jackson's ObjectMapper. like this:

@RequestMapping(value={"/getServiceCategoriesForVisitType"},method=RequestMethod.GET,headers="Accept=*/*",produces = "application/json")
   public @ResponseBody String loadreateVisitType(HttpServletRequest request,@RequestParam(value="visitTypeCode", required=true) long visitTypeCode)
throws JsonProcessingException {    
    // NOTE1: change the method to return a "String"
    // NOTE2: add "throws JsonProcessingException" to the method (or catch it)
    List<String> serviceCategories1=new ArrayList<String>();   
    serviceCategories1.add("abc"); 
    serviceCategories1.add("pqr"); 
    //return serviceCategories1; 
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(serviceCategories1);
   }
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

I'm pretty sure the above will fix it for you. But just to make sure this answer is complete (if someone else comes up to this questions about the 406 error), the other thing to try is to add this to the @RequestMapping (you've already added that to your method so maybe a note for others):

headers="Accept=*/*",produces = "application/json"
@RequestMapping(value={"/getServiceCategoriesForVisitType"},method=RequestMethod.GET,headers="Accept=*/*",produces = "application/json")

Jquery Ajax throws Error 406--Not Acceptable in Spring MVC - Stack Ove...

jquery spring-mvc
Rectangle 27 7

You could try to set the produces value of your @RequestMapping annotation with text/plain. The Spring documentation lists this as a sample.

I have no control over what Content-Type is set in the request and produces will not match if the request type is not what I set in it. I basically want to return text/plain no matter what the request type is.

Spring MVC 3 Return Content-Type: text/plain - Stack Overflow

spring-mvc content-type apache-tiles
Rectangle 27 1

I have added the relevant code, kindly make the dao with the help of impl I used in the below mentioned code.

**web.xml**

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>MultipleDatabaseConnectivityInSpring</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
     <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
    </servlet>
     <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/dispatcher-servlet.xml
        </param-value>
    </context-param>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>


**persistence.xml**


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="localPersistenceUnitOne"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>in.india.entities.CustomerDetails</class>
        <exclude-unlisted-classes />
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.jdbc.batch_size" value="0" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/shankar?sslmode=require" />
            <property name="hibernate.connection.username" value="username" />
            <property name="hibernate.connection.password" value="password" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
    <persistence-unit name="localPersistenceUnitTwo"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>in.india.entities.CompanyDetails</class>
        <exclude-unlisted-classes />
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.jdbc.batch_size" value="0" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/shankarTwo?sslmode=require" />
            <property name="hibernate.connection.username" value="username" />
            <property name="hibernate.connection.password" value="password" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
        </properties>
    </persistence-unit>
</persistence>


**dispatcher-servlet**


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    default-autowire="byName"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
      http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
      http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- Configure messageSource -->

    <mvc:annotation-driven />
    <context:component-scan base-package="in.india.*" />
    <bean id="messageResource"
        class="org.springframework.context.support.ResourceBundleMessageSource"
        autowire="byName">
        <property name="basename" value="messageResource"></property>
    </bean>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>



    <bean id="entityManagerFactoryOne"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        autowire="constructor">
        <property name="persistenceUnitName" value="localPersistenceUnitOne" />
    </bean>

    <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource"
        autowire="byName">
        <property name="basename" value="messageResource" />
    </bean>

    <bean id="entityManagerFactoryTwo"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        autowire="constructor">
        <property name="persistenceUnitName" value="localPersistenceUnitTwo" />
    </bean>

    <bean id="manager1" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryOne" />
    </bean>

    <bean id="manager2" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactoryTwo" />
    </bean>

    <tx:annotation-driven transaction-manager="manager1" />
    <tx:annotation-driven transaction-manager="manager2" />

    <!-- declare dependies here -->

    <bean class="in.india.service.dao.impl.CustomerServiceImpl" />
    <bean class="in.india.service.dao.impl.CompanyServiceImpl" />

    <!-- Configure MVC annotations -->
    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    <bean
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</beans>



**java class to persist into one database**


package in.india.service.dao.impl;

import in.india.entities.CompanyDetails;
import in.india.service.CompanyService;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

public class CompanyServiceImpl implements CompanyService {

    @PersistenceContext(unitName = "entityManagerFactoryTwo")
    EntityManager entityManager;

    @Transactional("manager2")
    @Override
    public boolean companyService(CompanyDetails companyDetails) {

        boolean flag = false;
        try 
        {
            entityManager.persist(companyDetails);
            flag = true;
        } 
        catch (Exception e)
        {
            flag = false;
        }

        return flag;
    }

}


**java class to persist in another database** 

package in.india.service.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

import in.india.entities.CustomerDetails;
import in.india.service.CustomerService;

public class CustomerServiceImpl implements CustomerService {

    @PersistenceContext(unitName = "localPersistenceUnitOne")
    EntityManager entityManager;

    @Override
    @Transactional(value = "manager1")
    public boolean customerService(CustomerDetails companyData) {

        boolean flag = false;
        entityManager.persist(companyData);
        return flag;
    }
}


**customer.jsp**

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <center>
        <h1>SpringWithMultipleDatabase's</h1>
    </center>
    <form:form method="GET" action="addCustomer.htm"  modelAttribute="customerBean" >
        <table>
            <tr>
                <td><form:label path="firstName">First Name</form:label></td>
                <td><form:input path="firstName" /></td>
            </tr>
            <tr>
                <td><form:label path="lastName">Last Name</form:label></td>
                <td><form:input path="lastName" /></td>
            </tr>
            <tr>
                <td><form:label path="emailId">Email Id</form:label></td>
                <td><form:input path="emailId" /></td>
            </tr>
            <tr>
                <td><form:label path="profession">Profession</form:label></td>
                <td><form:input path="profession" /></td>
            </tr>
            <tr>
                <td><form:label path="address">Address</form:label></td>
                <td><form:input path="address" /></td>
            </tr>
            <tr>
                <td><form:label path="age">Age</form:label></td>
                <td><form:input path="age" /></td>
            </tr>
            <tr>
                <td><input type="submit" value="Submit"/></td>
             </tr>
        </table>
    </form:form>
</body>
</html>


**company.jsp**


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ScheduleJobs</title>
</head>
<body>
 <center><h1>SpringWithMultipleDatabase's</h1></center>
 <form:form method="GET" action="addCompany.htm"  modelAttribute="companyBean" >
 <table>
    <tr>
        <td><form:label path="companyName">Company Name</form:label></td>
        <td><form:input path="companyName" /></td>
    </tr>
    <tr>
        <td><form:label path="companyStrength">Company Strength</form:label></td>
        <td><form:input path="companyStrength" /></td>
    </tr>
    <tr>
        <td><form:label path="companyLocation">Company Location</form:label></td>
        <td><form:input path="companyLocation" /></td>
    </tr>
     <tr>
        <td>
            <input type="submit" value="Submit"/>
        </td>
    </tr>
 </table>
 </form:form>
</body>
</html>

**index.jsp**

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
 <center><h1>Multiple Database Connectivity In Spring sdfsdsd</h1></center>

<a href='customerRequest.htm'>Click here to go on Customer page</a>
<br>
<a href='companyRequest.htm'>Click here to go on Company page</a>
</body>
</html>

**success.jsp**

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ScheduleJobs</title>
</head>
<body>
 <center><h1>SpringWithMultipleDatabase</h1></center>
    <b>Successfully Saved</b>
</body>
</html>

**CompanyController**

package in.india.controller;

import in.india.bean.CompanyBean;
import in.india.entities.CompanyDetails;
import in.india.service.CompanyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
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;

@Controller
public class CompanyController {

    @Autowired
    CompanyService companyService;

    @RequestMapping(value = "/companyRequest.htm", method = RequestMethod.GET)
    public ModelAndView addStudent(ModelMap model) {
        CompanyBean companyBean = new CompanyBean();
        model.addAttribute(companyBean);
        return new ModelAndView("company");
    }

    @RequestMapping(value = "/addCompany.htm", method = RequestMethod.GET)
    public ModelAndView companyController(@ModelAttribute("companyBean") CompanyBean companyBean, Model model) {
        CompanyDetails  companyDetails = new CompanyDetails();
        companyDetails.setCompanyLocation(companyBean.getCompanyLocation());
        companyDetails.setCompanyName(companyBean.getCompanyName());
        companyDetails.setCompanyStrength(companyBean.getCompanyStrength());
        companyService.companyService(companyDetails);
        return new ModelAndView("success");

    }
}

**CustomerController**


package in.india.controller;

import in.india.bean.CustomerBean;
import in.india.entities.CustomerDetails;
import in.india.service.CustomerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
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;

@Controller
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @RequestMapping(value = "/customerRequest.htm", method = RequestMethod.GET)
    public ModelAndView addStudent(ModelMap model) {
        CustomerBean customerBean = new CustomerBean();
        model.addAttribute(customerBean);
        return new ModelAndView("customer");
    }

    @RequestMapping(value = "/addCustomer.htm", method = RequestMethod.GET)
    public ModelAndView customerController(@ModelAttribute("customerBean") CustomerBean customer, Model model) {
        CustomerDetails customerDetails = new CustomerDetails();
        customerDetails.setAddress(customer.getAddress());
        customerDetails.setAge(customer.getAge());
        customerDetails.setEmailId(customer.getEmailId());
        customerDetails.setFirstName(customer.getFirstName());
        customerDetails.setLastName(customer.getLastName());
        customerDetails.setProfession(customer.getProfession());
        customerService.customerService(customerDetails);
        return new ModelAndView("success");

    }
}


**CompanyDetails Entity**


package in.india.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "company_details")
public class CompanyDetails {

    @Id
    @SequenceGenerator(name = "company_details_seq", sequenceName = "company_details_seq", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "company_details_seq")
    @Column(name = "company_details_id")
    private Long companyDetailsId;
    @Column(name = "company_name")
    private String companyName;
    @Column(name = "company_strength")
    private Long companyStrength;
    @Column(name = "company_location")
    private String companyLocation;

    public Long getCompanyDetailsId() {
        return companyDetailsId;
    }

    public void setCompanyDetailsId(Long companyDetailsId) {
        this.companyDetailsId = companyDetailsId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Long getCompanyStrength() {
        return companyStrength;
    }

    public void setCompanyStrength(Long companyStrength) {
        this.companyStrength = companyStrength;
    }

    public String getCompanyLocation() {
        return companyLocation;
    }

    public void setCompanyLocation(String companyLocation) {
        this.companyLocation = companyLocation;
    }
}


**CustomerDetails Entity**

package in.india.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "customer_details")
public class CustomerDetails {

    @Id
    @SequenceGenerator(name = "customer_details_seq", sequenceName = "customer_details_seq", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customer_details_seq")
    @Column(name = "customer_details_id")
    private Long customerDetailsId;
    @Column(name = "first_name ")
    private String firstName;
    @Column(name = "last_name ")
    private String lastName;
    @Column(name = "email_id")
    private String emailId;
    @Column(name = "profession")
    private String profession;
    @Column(name = "address")
    private String address;
    @Column(name = "age")
    private int age;
    public Long getCustomerDetailsId() {
        return customerDetailsId;
    }

    public void setCustomerDetailsId(Long customerDetailsId) {
        this.customerDetailsId = customerDetailsId;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmailId() {
        return emailId;
    }

    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

Multiple database with Spring+Hibernate+JPA - Stack Overflow

hibernate spring jpa multi-database
Rectangle 27 0

<div>   
    <form action="/foo">  
      <select name="dropDown">
            <option value="bar">bar</option>

     </select>
    </form>   
</div>

java - Pass drop down list value from jsp to spring controller - Stack...

java spring jsp spring-mvc
Rectangle 27 0

I think the best you are going to be able to do is generate a list of bean names that is used as the value of the check boxes. Then when the user submits the page, build a list of selected beans (from the check boxes) and get the beans from your application context (i.e. getBean("bean name");)

java - Spring MVC Forms - Retrieve a list of beans or strings from mul...

java spring-mvc
Rectangle 27 0

Derivation of delete queries using given method name is supported starting with version 1.6.0.RC1 of Spring Data JPA. The keywords remove and delete are supported. As return value one can choose between the number or a list of removed entities.

Long removeByLastname(String lastname);

List<User> deleteByLastname(String lastname);

Spring Data: "delete by" is supported? - Stack Overflow

spring spring-data spring-data-jpa
Rectangle 27 0

You are missing the name attribute on the form:select. For it to work with @ModelAttribute("questionsList") it would have to be something like:

Although I truly discourage this, since it causes a lot of confusion with the path attribute, which has a totally different purpose.

Furthermore, your post data will only contain the selected value associated with the select name (ex: questionsList:1), so setting this to a list doesn't make that much sense.

<form:select path="questionsList" name="questionId">
public ModelAndView processForm(@ModelAttribute("answer1") String answer1, @ModelAttribute("questionId") Integer questionId) {

Spring MVC form not returning value from dropdown list - Stack Overflo...

forms spring spring-mvc
Rectangle 27 0

My web.xml is :

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4">
        <servlet>
            <servlet-name>springornek</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springornek</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

My springornek-servlet is :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <bean id="basitDenetimci" class="denetim.BasitDenetimci" />
        <bean id="urlEsleme"
            class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/index.htm">basitDenetimci</prop>
                </props>
            </property>
        </bean>
        <bean id="gorunumCozumleyici"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass">
                <value>org.springframework.web.servlet.view.JstlView</value>
            </property>
            <property name="prefix">
                <value>/WEB-INF/jsp/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>
    </beans>

My springornek Class is :

    package denetim;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;

    public class BasitDenetimci implements Controller{

        @Override
        public ModelAndView handleRequest(HttpServletRequest arg0,
                HttpServletResponse arg1) throws Exception {
            return new ModelAndView("basit");
        }

    }

My index.jsp is : 

    <%@ page contentType="text/html; charset=ISO-8859-9"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:redirect url="/index.htm"/>
    <html>
    <head>
    <title>Hello World</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
    </html>

My basit.jsp is :

    <%@ page contentType="text/html; charset=ISO-8859-9"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
    <title>springornek</title>
    </head>
    <body>
        <h1>Welcome!</h1>
    </body>
    </html>

Jars that I using :

jstl-1.2.jar
jstl-api-1.2-sources.jar
jstl-connector-3.0.jar
spring.jar
spring-aop.jar
spring-beans-3.1.1.release-sources.jar
spring-context.jar
spring-core.jar
spring-dao.jar
spring-mock.jar
spring-orm.jar
spring-web.jar
spring-webmvc.jar

java - Error - Web Project using Tomcat server and Spring MVC framewor...

java eclipse spring spring-mvc tomcat
Rectangle 27 0

Binding for the dropdown doesnt work after when returning back to the same form after a submit action. Selected values are not getting displayed back on the form.

jsp - spring form composed item value of a drop down list - Stack Over...

spring jsp java-ee spring-mvc jstl
Rectangle 27 0

Try to use spring "form" taglib. You can create special class that encapsulate all fields and pass it to model in your "GET" method (that displays page). Assume that name of passed object is "entity". Also you have to pass list of all enum values to your model. (See example here: spring-form:options tag with enum). Jsp will look like this:

<form:form commandName="entity" action="/action" method="POST">
    <form:select path="sessionOne">
        <form:options items="${availableOptions}" />
    </form:select>
    <form:select path="sessionTwo">
        <form:options items="${availableOptions}" />
    </form:select>
    <!-- and so on -->
</form:>
@RequestMapping(value = "/action", method = RequestMethod.POST)
public String handleHugeForm(@ModelAttribute Entity entity) {
    // do what you want
}

Spring MVC/JSP handle huge forms - Stack Overflow

forms spring jsp spring-mvc
Rectangle 27 0

public class ArticleController {

    // inject the spring validator.
    @Autowired
    private LocalValidatorFactoryBean validator;

    @RequestMapping(value = "/edit", method = PUT)
    public String doEdit(@ModelAttribute("article") final Article article,
            final BindingResult bindingResult) {
        // generates article's tag, not editable by user
        article.setTag(generateTag(article));
        // validate
        validator.validate(article, bindingResult);

        if (bindingResult.hasErrors()) {
            return "/edit";
        } else {
            service.save(article);
            return "redirect:/list";
        }
    }
}
org.springframework.validation.Validator
LocalValidatorFactoryBean

java - How to re-run Bean Validation on form object? (Spring 4 MVC con...

java spring spring-mvc bean-validation
Rectangle 27 0

Have you got the @RequestMapping annotations set up in your controller, so that submitted form is returned to the correct method? In this case, you'd want:

@RequestMapping(method = RequestMethod.POST)
foo()

java - Pass drop down list value from jsp to spring controller - Stack...

java spring jsp spring-mvc
Rectangle 27 0

I think you're right in what's the problem. When you do path="formFields[${formFieldRow.index}].value" you're returning a String value from each radiobutton of the form and Spring should know how to convert this String value into each FieldValue object to fill the List value.

So you need to create your customEditor and in your initbinder associate this editor to the List class:

@InitBinder
public void initBinder(final WebDataBinder binder) {
    binder.registerCustomEditor(FieldValue.class, CustomEditor() ));
}

and your CustomEditor class should extends PropertyEditorSupport like this:

public class CustomEditor extends PropertyEditorSupport{  
    public void setAsText(String text) {
        FieldValue field;
        //you have to create a FieldValue object from the string text 
        //which is the one which comes from the form
        //and then setting the value with setValue() method
        setValue(field);
    }
}

java - Nested form data binding with Lists of Objects in Spring MVC - ...

java forms spring-mvc nested-forms data-binding
Rectangle 27 0

th:attr
<input th:if="${filterType == 'Unapproved'}" type="checkbox" th:attr="name=${file.id}" th:value="Approved" th:text="Approve"/>
<input th:if="${filterType == 'Unapproved'}" type="checkbox"  th:attr="name=${file.id}" th:value="Deleted" th:text="Delete"/>
<input th:if="${filterType == 'Approved'}" type="checkbox" th:attr="name=${file.id}" th:value="Unapproved" th:text="Unapprove" />
<input th:if="${filterType == 'Deleted'}" type="checkbox" th:attr="name=${file.id}" th:value="Approved" th:text="Approve" />

spring mvc - Thymeleaf is not checking values when I load the list int...

spring-mvc spring-boot thymeleaf
Rectangle 27 0

Derivation of delete queries using given method name is supported starting with version 1.6.0.RC1 of Spring Data JPA. The keywords remove and delete are supported. As return value one can choose between the number or a list of removed entities.

Long removeByLastname(String lastname);

List<User> deleteByLastname(String lastname);

That's a great tip!!!

Spring Data: "delete by" is supported? - Stack Overflow

spring spring-data spring-data-jpa
Rectangle 27 0

You're not preserving your model attribute from request to request - you either need to include all the values from your bean in the page as inputs, POST them back with the next request, and have Spring bind them to the new bean on the POST request, or tell Spring to store it in the session with @SessionAttributes:

@Controller
@RequestMapping("/admin/customerRequests")
@SessionAttributes("customerRequestsBean")
public class CustomerRequestsController {

only what is on my List in my customerRequestsBean is where I am getting null values from the post

Do you already have an @SessionAttributes annotation on your controller?

java - Spring MVC - Not able to retreive values from list on bean afte...

java spring jsp spring-mvc
Rectangle 27 0

You could try to set the produces value of your @RequestMapping annotation with text/plain. The Spring documentation lists this as a sample.

I have no control over what Content-Type is set in the request and produces will not match if the request type is not what I set in it. I basically want to return text/plain no matter what the request type is.

Spring MVC 3 Return Content-Type: text/plain - Stack Overflow

spring-mvc content-type apache-tiles
Rectangle 27 0

import org.springframework.web.bind.annotation.RestController;

@RestController
public class YourController {

   @RequestMapping(value = "/getAllStudents", method = RequestMethod.GET)
   public List<Student> getAllExpenses() {
    List<Student> students= studentDaoImp.getStudents();
    return students;
 }
}

And add below dependencies in your classpath:

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.0</version>
</dependency>
<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.0</version>
</dependency>

Optionally you can remove below code from your Spring Configuration file:

<!-- telling container to take care of annotations stuff -->
    <context:annotation-config />

    <!-- declaring base package -->
    <context:component-scan base-package="com.controller" />

java - unable to use @ResponseBody to send json object in spring mvc -...

java json spring spring-mvc