I'm adding an object to my ModelAndView
in spring and forwarding to my jsp view. I need to access that object in my jquery. Is this possible without first putting the value in a hidden field? How is it done?
Model attributes are the data representations used internally by the model. Data attributes and model attributes can be the same. For example, a column called SIZE , with values S , M , and L , are attributes used by an algorithm to build a model.
ModelAttribute can be applied to both methods as well as method-parameters. It accepts an optional "value", which indicates the name of the attribute. If no value is supplied to the annotation, then the value would default to the return type name in case of methods and parameter type name in case of method-parameters.
@ModelAttribute is an annotation that binds a method parameter or method return value to a named model attribute, and then exposes it to a web view. In this tutorial, we'll demonstrate the usability and functionality of this annotation through a common concept, a form submitted from a company's employee.
1) addAttributeIt adds the specified attribute under the supplied name. Model addAttribute(String attributeName, @Nullable Object attributeValue) attributeName - the name of the model attribute - can never be null attributeValue - the model attribute value - can be null.
<script type="text/javascript">
var modelAttributeValue = '${modelAttribute}';
</script>
This will resolve the model attribute added by model.addAttribute("modelAttribute", value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With