Spring – BindingResult and a normal target object of the BEAN name cannot be used as a request attr

See answer in English> What causes “java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name’command’ available as request attribute”? 6

Hi expert,
I have this controller code throwing the above error. It works fine, until yesterday, I don’t know what a colleague did with this code, today I see the error:

< p>BindingResult and the ordinary target object of the bean name’sideForm’ are not available as request attributes

Can you tell me where to look for this kind of error? Did I make any mistakes or return errors in the POST or GET method declaration?

Thank you very much for your help:)

package com.att.analytics.ui;

import java.util. Arrays;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
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 com.si.myworld. business.AdminChart;
import com.si.myworld.business.Chart;
import com.si.myworld.dao.AdminChartSummaryData;
import com.si.myworld.dao.BulletinData;< br />import com.si.myworld.dao.ChartData;

@RequestMapping("/index.html")
@Controller
public class IndexController {

private static final Logger log = Logger.getLogger(IndexController.class);

/**
* Called to load the page initially (GET request)
*
* @param model
* @return
*/
@RequestMapping (method = RequestMethod.GET)
public String getCharts(ModelMap model) {

Chart chart = new Chart();
chart.setTimeline("Monthly");
chart.setStartDt("mm/dd/yyyy");
chart.setEndDt("mm/dd/yyyy");

AdminChartSummaryData acsd = new AdminChartSummaryData();
List list = acsd.getLandingChartDataList();

if (list.size() == 4) {
Chart chart1 = new Chart(list.get(0) );
Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list.get(2));
Chart chart4 = new Chart(list. get(3));
model.put("chart1", chart1);
model.put("chart2", chart2);
model.put("chart3", chart3) ;
model.put("chart4", chart4);

log.info("chart 1>>>>" + chart1);


ChartData cd = new ChartData();

String chartOneDatasource = cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

String breadcrumbOne = chart1.getChartGroup() + ">>"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"< br /> + chart2.getChartSubgroup();
String breadcrumbThree = chart3.getChartGroup() + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();

BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();

model.put("sideForm", chart);



model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource", chartTwoDatasource);
model.put("chartThreeDatasource" , chartThreeDatasource);
model.put("chartFourDatasource", chartFourDatasource);

model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo);
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);

model.put("bulletin", bulletin );
}

return "land";
}


@RequestMapping(method = RequestMethod.POST)
public String loadCharts(HttpServletRequest request, ModelMap model, @ModelAttribute("sideForm") Chart chart) {

String from_date = reque st.getParameter("startDt");
String to_date = request.getParameter("endDt");

chart.setStartDt(from_date);
chart.setEndDt(to_date) ;

ChartData cd = new ChartData();

BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();



AdminChartSummaryData acsd = new AdminChartSummaryData();
List list = acsd.getLandingChartDataList();
if (list.size() == 4 ) {
Chart chart1 = new Chart(list.get(0));
Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list. get(2));
Chart chart4 = new Chart(list.get(3));
model.put("chart1", chart1);
model.put("chart2" , chart2);
model.put("chart3", chart3);
model.put("chart4", chart4);


String chartOneDatasource = cd .fetchChartDatasourceName(chart1
.getChartSubgroup()) ;
String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource", chartTwoDatasource) ;
model.put("chartThreeDatasource", chartThreeDatasource);
model.put("chartFourDatasource", chartFourDatasource);

String breadcrumbOne = chart1.getChartGroup() + "> >"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"
+ chart2.getChartSubgroup();
String breadcrumbThree = chart3. getChartGroup() + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();


model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo);
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);
}
return "land";
}


@ModelAttribute("timeline")
public Collection populateTimeline() {
return Arrays. asList("Daily", "Weekly", "Monthly", "Quarterly",
"Annually", "12_Month_Rolling");
}
}

This page Get the value from the form shown below:


Timeline





From:




To:






make sure your Spring form mentions modelAttribute = "< Model Name". Example:

@Controller
@RequestMapping("/greeting.html")
public class GreetingController {

@ModelAttribute("greeting")
public Greeting getGreetingObject() {
return new Greeting();
}

/**
* GET
*
*
*/
@RequestMapping(method = RequestMethod.GET)
public String handleRequest() {
return "greeting";
}

/**
* POST
*
*
*/
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processSubmit(@ModelAttribute("greeting") Greeting greeting, BindingResult result){
ModelAndView mv = new ModelAndView();
mv.addObject("greeting", greeting);
return mv;
}
}

In your JSP:

See English answer> What causes "Java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name'command' available as request attribute"? 6

Hey experts,
I have this controller code throw The above error occurred. It worked fine. Until yesterday, I didn’t know what a colleague did with this code. Today I saw an error: BindingResult and the ordinary target object of the bean name'sideForm' are not available for use Request attributes

Can you tell me where to look for this kind of error? Did I make any mistakes or return errors in the POST or GET method declaration?

Thank you very much for your help:)

package com.att.analytics.ui;

import java.util. Arrays;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
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 com.si.myworld. business.AdminChart;
import com.si.myworld.business.Chart;
import com.si.myworld.dao.AdminChartSummaryData;
import com.si.myworld.dao.BulletinData;< br />import com.si.myworld.dao.ChartData;

@RequestMapping("/index.html")
@Controller
public class IndexController {

private static final Logger log = Logger.getLogger(IndexController.class);

/**
* Called to load the page initially (GET request)
*
* @param model
* @return
*/
@RequestMapping(method = RequestMethod.GET)
public String getCharts(ModelMap model) {

Chart chart = new Chart();
chart.setTimeline("Monthly");
chart .setStartDt("mm/dd/yyyy");
chart.setEndDt("mm/dd/yyyy");

AdminChartSummaryData acsd = new AdminChartSummaryData();
List list = acsd.getLandingChartDataList();

if (list.size() == 4) {
Chart chart1 = new Chart(list.get(0));< br /> Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list.get(2));
Chart chart4 = new Chart(list.get(3 ));
model.put("chart1", chart1);
model.put("chart2", chart2);
model.put("chart3", chart3);
model.put("chart4", chart4);

log.info("chart 1>>>>" + chart1);


ChartData cd = new ChartData();

String chartOneDatasource = cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

String breadcrumbOne = chart1.getChartGroup() + ">>"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"< br /> + chart2.getChartSubgroup();
String breadcrumbThree = chart3.getChartGroup() + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();


BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();

model.put("sideForm", chart);
< br />

model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource", chartTwoDatasource);
model.put("chartThreeDatasource", chartThreeDatasource", chartThreeDatasource );
model.put("chartFourDatasource", chartFourDatasource);

model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo) ;
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);

model.put("bulletin", bulletin);
}

return "land";
}


@RequestMapping(method = RequestMethod.POST)
public String loadCharts(HttpServletRequest request, ModelMap model, @ModelAttribute("sideForm") Chart chart) {

String from_date = request. getParameter("startDt");
String to_date = request.getParameter("endDt");

chart.setStartDt(from_date);
chart.setEndDt(to_date);< br />
ChartData cd = new ChartData();

BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();



AdminChartSummaryData acsd = new AdminChartSummaryData();
List list = acsd.getLandingChartDataList();
if (list.size() == 4) {
Chart chart1 = new Chart(list.get(0));
Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list.get( 2));
Chart chart4 = new Chart(list.get(3));
model.put("chart1", chart1);
model.put("chart2", chart2 );
model.put("chart3", chart3);
model.put("chart4", chart4);


String chartOneDatasource = cd.fetchChartDatasourceName (chart1
.getChartSubgroup()); String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource",chartTwoDatasource);< br /> model.put("chartThreeDatasource", chartThreeDatasource);
model.put("chartFourDatasource", chartFourDatasource);

String breadcrumbOne = chart1.getChartGroup() + ">>"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"
+ chart2.getChartSubgroup();
String breadcrumbThree = chart3.getChartGroup( ) + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();


model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo);
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);
}
return "land";
}


@ModelAttribute("timeline")
public Collection populateTimeline() {
return Arrays. asList("Daily", "Weekly", "Monthly", "Quarterly",
"Annually", "12_Month_Rolling");
}
}

This page Get the value from the form shown below:


Timeline





From:




To:






Make sure your Spring form mentions modelAttribute = "< Model Name". Example:

@Controller
@RequestMapping("/ greeting.html")
public class GreetingController {

@ModelAttribute("greeting")
public Greeting getGreetingObject() {
return new Greeting();
}

/**
* GET
*
*
*/
@RequestMapping(method = RequestMethod.GET)< br /> public String handleRequest() {
return "greeting";
}

/**
* POST
*
*
*/
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processSubmit(@ModelAttribute("greeting") Greeting greeting, BindingResult result){
ModelAndView mv = new ModelAndView ();
mv.addObject("greeting", greeting);
return mv ;
}
}

In your JSP:

Leave a Comment

Your email address will not be published.