1

Hi I am creating an application where for each user form elements being displayed could be different (type of element, number of element, label of the form element, order of appearance : all these could differ from user to user).

I am fetching these user prefernece from DB.

I was hoping to implement some technique/tool/method so that I could create the JSP to be shown to the user at runtime from centralized framework (I want to reuse the same component for creating JSP for the users).

I am thinking some XML transformation using XSLT, but not sure how to do it or whether that is the best approach.

Any suggestions?

PS : I am using Struts + Spring Framework.

Rachit Agrawal
  • 685
  • 4
  • 13
  • 35
  • Interesting. I would go with jquery for creating dynamic elements – Anupam Oct 23 '12 at 07:26
  • Could you direct me to a example? Would it be possible to create prepopulated fields, dropdowns? – Rachit Agrawal Oct 23 '12 at 07:48
  • What I meant was, if you are planning to do it on client side then you could use jquery to create dynamic elements [like this](http://stackoverflow.com/questions/268490/jquery-document-createelement-equivalent). – Anupam Oct 23 '12 at 07:51
  • I want to do it on server side. That way prepopulating the fields and managing the whole setup would be efficient. – Rachit Agrawal Oct 23 '12 at 08:01
  • I think XML/XSLT is NOT the way to go (having had to maintain such beasts in the past - anyone remember Cocoon?). I would start "simple" and simply code in JSP with regular logic. If you are getting really fancy (different ordering and placement of fields, etc), then I would look at a client-side approach as others have suggested. There are quite a few frameworks/tools to do this with. – nickdos Oct 23 '12 at 08:25
  • Could you suggest any framework/tool? – Rachit Agrawal Oct 23 '12 at 08:48
  • well u can simply put ur
    tag inside a jsp conditions like if else it would work perfectly
    – Hussain Akhtar Wahid 'Ghouri' Oct 23 '12 at 09:52

2 Answers2

0

If you want do this on server side then maybe you can do something with Apache Tiles http://tiles.apache.org/. There is a runtime composition API as well http://tiles.apache.org/2.2/framework/tutorial/advanced/runtime.html.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
0

After enough R&D i have come up with the following approach. Get the user preferences in Java object(in list/map format). This object should contain the label name, order, input type, default value etc. Then transform this Java object to a JSON object( using any lib like GSON, Jackson etc).

Next parse this JSON object in javascript using javascript/jquery and then parse the thus formed JSON object to create the form fields(by iterating ovet the JSON object)

Rachit Agrawal
  • 685
  • 4
  • 13
  • 35
  • is there any performance issue, if you create dynamic html using json in clientside? which approach is better, creating dynamic page from client side or server side? – Manu Benjamin Oct 11 '15 at 06:16