Handling and storing Java hashmap (map map) in the java script to JSP for later u…

I have a hashmap as variable in baking bean like.

private Map<String, Map> states;

At JSP page, I have two combo menu 1st is for country and second is for states. I need to populate second combo menu based on selected country on first combo menu, Mapping is there at above hash map. Any suggestions. I am using spring mvc and jsp. I can access above map at javascript using

stateMap ='${resetForm.states}';

But it will be a string. Please help

Thanks

You should always separate as much as possible the server-side from client-side, else you’ll end up having a hard to mantain, not understandable and error prone code. That being said, you can convert your map to JSON and send that json to the client-side, so it can be handled as you want:

    var statesJSON = JSON.parse(  );

Now you can write your client-side code (regarding the population of the drop-down lists) by using the statesJSON
global variable. You can follow these links for how to populate a drop-down list based on selection on another :

  • populate-one-dropdown-based-on-selection-in-another
  • populate-one-dropdown-list-based-on-the-selection-of-other-dropdown-list
  • populate-a-second-drop-down-menu-depends-upon-first-drop-down-selection
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Handling and storing Java hashmap &lpar;map map&rpar; in the java script to JSP for later u…

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录