Srishti123
Srishti123

Reputation: 63

Dynamic fields on jsp from database using Struts2 ,Hibernate

Using Struts2:

I have a table in my database with fields(2 text boxes and 2 dropdown). And my jsp renders them correctly with respective values. Now What I want is whenever I add any field manually in my database how dynamically I can render it on my jsp using Struts2. Do I need to use ajax???? or How should I proceed.

Thanks in advance.

Updated : I have a table in my database with 2 columns, Name of Label (Name, Age etc) and Type of Input Element (textbox, dropdown etc) Now I want whenever I add any field manually or through some form to database, I need to render it dynamically on my JSP using Struts 2. The corressponding Input element should be shown on the jsp.

Upvotes: 1

Views: 1695

Answers (1)

Quaternion
Quaternion

Reputation: 10458

From your question and comments you'll need comet type functionality. If this is an intranet application where you can control the version of the browser then web sockets are an option.

On the back end there are some considerations. Namely is your application the only means of updating the database or are there multiple applications updating the database. In the first case you can have each client register a listener and then each update flags all listeners. Looking at how a chat server works would address all these issues.

If there are multiple applications which contribute to the database then you could pole for changes or have the database notify you of changes, by creating update triggers which invoke some sort of notification mechanism. The problem being this will be different between databases and so is a more complicated scenario.

Some reading:

Basic Comet: http://en.wikipedia.org/wiki/Comet_%28programming%29

Talks about comet vs web sockets and the atmosphere framework (a comet framework which will use websockets if available): http://jfarcand.wordpress.com/2012/04/19/websockets-or-comet-or-both-whats-supported-in-the-java-ee-land/

If using JPA their callback and listeners might be useful: http://www.objectdb.com/java/jpa/persistence/event

Upvotes: 1

Related Questions