How to implement dynamic GUI in JSP
i have a requirement where i need to display some fields on the JSP. These fields are dynamic in nature, meaning, for ex:, if i changed some value in the dropdown, some fields will be hidden and some other fields might come. I dont want to write Javascripts for show/hide of divs, rather want logic to be coded somewhere at server side.
I have an idea of implementing a custom tag library, but i wnat if i could get an o开发者_Go百科ut of the box solution.
any new suggestions or solutions are welcomed.
You had better do it in JavaScript. Having said that, you can send AJAX request to get the new form fields based on the input provided. For example, have a <div>
to set the HTML coming from the server.
Use struts framework , there are some tags which can hide and show fields based on values
Logic/logicout tags example
If you want to use a web framework, try Struts 2. It provides tags like <s:if test="some ognl expression" ...>
to selectively render html content.
Otherwise you could just go with the JSTL core tags, which provide a <c:if text="some Java EL expression" ...>
and a <c:choose ...>
tag ( Example ).
Remember to reload the page after changing select box values in order to update the UI. For this some JavaScript might be needed.
DOM (Document Object Model) in Javascript is very powerful and cross browser.
to remove a node on UI
1.removeChild(nodename)
to add a node on UI
2.elementNode.insertBefore(new_node,existing_node)
I used it. it works well. more information on DOM.
http://www.w3schools.com/dom/default.asp
精彩评论