How to implement a dynamic GUI in JSP

I have a requirement when I need to display some fields in a JSP. These fields are dynamic in nature, that is, for ex :, if I change some value in the drop-down list, some fields will be hidden, and some others may appear. I do not want to write Javascripts to show / hide divs, rather I want the logic to be encoded somewhere on the server side.

I have an idea to implement a custom tag library, but I will not get a solution from the box.

Any new suggestions or solutions are welcome.

+4
source share
4 answers

You better do it in JavaScript. Having said that, you can send an AJAX request to get new form fields based on the input provided. For example, set <div> to set the HTML coming from the server.

+1
source

Using the struts framework, there are some tags that can hide and show fields based on values

Logic / Logic Tag Example

0
source

If you want to use a web framework, try Struts 2 . It provides tags like <s:if test="some ognl expression" ...> for selectively rendering html content.

Otherwise, you can just go with JSTL core tags that contain the tags <c:if text="some Java EL expression" ...> and <c:choose ...> ( Example ).

Remember to reload the page after changing the values โ€‹โ€‹of the selection window to refresh the interface. This may require JavaScript.

0
source

The DOM (Document Object Model) in Javascript is a very powerful and cross browser.

remove node in user interface

1.removeChild (hostname)

add node to user interface

2.elementNode.insertBefore (new_node, existing_node)

I used it. it works well. more information about the DOM.

http://www.w3schools.com/dom/default.asp

0
source

All Articles