问题描述:

Spring 3.0 (form:select, form:option(s) ) tag library supports rendering HTML 5 data-* attributes using a bean's property? If yes , an example would help.

Background : I am developing a Spring MVC app and using Bootstarp css and JS and spring provided tags. Need to use HTML 5 data-* attributes to keep additional data with dropdowns options. Based upon the user selection in one of the dropdown , I want update further dropdowns and I want to avoid AJAX calls to fetch options for next dropdown since I have the data during page load.

I understand JQuery has attribute support but that would require javascript code execution on page load, so looking for HTML 5 support. Any other suggestions to handle this are welcome.

网友答案:

Data-* attributes are supported on Spring 3.0 form tags (along with any validly-named custom attribute you specify, I believe). You can also use the value of a bean's property as the attribute value, e.g.

<form:input data-test="${myBean.propertyName}" path="propertyName" />

To answer the second part of your question, where you ask if there's a way to get the Spring form tag library to populate the data-* attributes with the contents of the bean's property that you specify, this does not happen automatically: you would need to write a custom tag that does this.

相关阅读:
Top