Travis Emery
Travis Emery

Reputation: 89

Path on spring form select not working

I am having an issue getting the jsp to render properly. The path on my select tag seems to be the culprit, but I cannot track don't why.

I get the error: Error 500: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

And my code is:

Controller.java

@Controller 
@RequestMapping("view")
@SessionAttributes({"analyticFormBean"})
public class RolesAnalyticsController {
@RenderMapping
public String defaultRenderer(RenderRequest request, RenderResponse response, ModelMap map){
    logger.entering(SOURCE_CLASS, "defaultRenderer");
    request.setAttribute("reportList", getReportList());
    logger.exiting(SOURCE_CLASS, "defaultRenderer", VIEW_JSP);
    return VIEW_JSP;
}

View.jsp

<form:form id="reportForm" method="POST" action="${submitReportQuery}">

<form:select path="query" id="reportSelection" onchange="javascript:checkForFields()">
    <form:option value="NONE" label="--- Select ---"/>
    <form:options items="${reportList}" />
</form:select>

&nbsp;
<input type="submit" value="Submit" name="Submit" ><br>

<div class="fieldPlaceholder" id="fieldPlaceholder"></div>

Bean.java

public class AnalyticFormBean {
    private int reportID;
    private String query;
    private String queryResult;
    private String[] listOfQueries;

Upvotes: 1

Views: 6334

Answers (2)

JohnNY
JohnNY

Reputation: 549

I dont see you using the bean in the form... you need to add it to the form.

<form:form commandName="analyticFormBean" .......>

Upvotes: 0

Affe
Affe

Reputation: 47984

You're missing two things,

  • the backing bean has to be actually added to the ModelMap at some point, so you need a map.addAttribute("analyticFormBean", new AnalyticFormBean()) (or with whatever initial values you want added to it, etc.)

  • You have to tell the form tag the name of the backing object <form:form commandName="analyticFormBean" etc>

Upvotes: 3

Related Questions