I ‘m dynamically loading spring checkbox tags according to changes in select tag. But it generates error like :
2012-08-31 09:27:14.829 org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag: Neither BindingResult nor plain target object for bean name 'stockList' available as request attribute
W 2012-08-31 09:27:14.831 /stocks
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'stockList' available as request attribute
C 2012-08-31 09:27:14.832 Uncaught exception from servlet
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'stockList' available as request attribute
in my app engine server log.
My code is given below
<link rel="stylesheet"
href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script
src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script type="text/javascript">
function loadStocks() {
var exchange = $("#stockExchange").val();
var a;
if (exchange = "BO") {
a = "<form:checkbox path='stockList' value='INFY' label='Infosys' />"
+ "<form:checkbox path='stockList' value='HINDALCO' label='HINDALCO' />"
+ "<form:checkbox path='stockList' value='TTM' label='Tata Motors' />";
} else if (exchange == "NS") {
a = "<form:checkbox path='stockList' value='INFY' label='Infosys' />";
}
$("#kit").html(a);
}
</script>
</head>
<body>
<div data-role="page">
<div data-role="content">
<form:form method="POST" commandName="search">
<ul data-role="listview">
<li data-role="fieldcontain">
<div id="kit">
<form:select path="stockExchange" onchange="loadStocks()"
id="stockExchange">
<form:option value="">Select Stock Exchange</form:option>
<form:option value="BO">BSE</form:option>
<form:option value="NS">NSE</form:option>
</form:select>
</div>
</li>
<li data-role="fieldcontain"><label>Select Stocks</label>
<div id="kit">
<form:checkbox path="stockList" value="INFY" label="Infosys" />
<form:checkbox path="stockList" value="HINDALCO" label="HINDALCO" />
<form:checkbox path="stockList" value="TTM" label="Tata Motors" />
<form:checkbox path="stockList" label="RELIANCE IND."
value="RELIANCE" />
</div></li>
<li data-role="fieldcontain"><input type="submit"
value="Submit" /></li>
</ul>
</form:form>
</div>
<!-- /content -->
</div>
<!-- /page -->
</body>
This javascript function won’t work this way. Look to HTML source code in your browser and you will notice that is different than JSP’s. The
<form:xxxx/>tags are spring tags to generate HTML quickly and make property binding easier. So, for example:will be transformed aproximately to this plain HTML:
As your javascript function is in client-side, spring tags won’t be transformed, so you will have to use plain html in your Javascript function. Something like that:
Hope I’ve explained myself well.
P.S.: Why
idof inputs arestockList1,stockList2andstockList3? Answer and related info here, check it out, will help you.EDIT:
Another solution, maybe easier, is to create a hidden div in your JSP with the inputs needed in JS function and let spring to transform it. Later, in your JS function you can clone these inputs generated by Spring with JQuery. This way avoids you to create plain HTML understandable by Spring.