Search code examples
web-widget

How do generate dynamic web page with in the same web application


I thought of re-framing this question once again, to make it clear. Thanks a lot the comments. I am developing a web application in which I am making use of widgets.

Take a real use case scenario, suppose USER-A logins into the my web app and he uses some widgets say A,B and C widgets. He places Widget A in the center, WIDGET-B on to the top right hand side and WIDGET-C on to the left hand side of the page.

USER_B logins into my system and uses the some widgets and places the widgets in different positions since widgets are made draggable and resizable. When the user publishes the page the widget should appear exactly in the same position exactly in the same position where he/she placed.

We are using Jquery HTML5 at the front end and servlet and my sql at the back end.


Solution

  • Forget about users, just consider retrieving any dynamic content. You've got some arbitrary URL

    http://mysite.com/some/path/or/other
    

    or possibly with some parameters

    http://mysite.com/some/path/or/other?thing=somevalue
    

    When the browser hits that URL some code of your will run, and you have access to the URL. Depending upon the tools you are using you may even have the parts of the URL broken out for you into some useful variables, if not you can extract the bits you care about.

    String interestingBit; // somehow gets set to "other"
    String thing; // somehow gets set "somevalue"
    

    Now you can write some code to go fetch data from a file or a database,

    databaseRetrieve( interstingBit, thing);
    

    once again nice frameworks may make all this really easy. Then it's just a matter of presenting the data. So dealing with user-specific content can follow this approach. You've got to deal with other issues such as deciding how to structure the repository of content and managing the security, but as I understand your question you were asking about the interpretion of the URL.

    Editedin response to clarified question:

    Seems like you're developing "personalisation" function that is often provided by "Portal" products and frameworks. The key point is that you have a per-user set of preferences, which control what content is displayed and where it is displayed. There are many such products, I work for IBM so I know about WebSphere Portal and Lotus Mashups, to name but two.

    So to implement this you need:

    1. To base the page composition and layout on data retrieved dynamically, say from a database. For this you need to figure out what to stash in the database (say a list of widget names, their sizes and position, and perhaps their styles and configuration too.) and the how to render a page from that information. I don't know JQuery, but you may have to create a bit of code to do this, not really difficult, but some work.
    2. How to select a particular instance from the database based on the user's id and the page they select. Typically the user asks for http://mysite.com/sport and your app knows the user's id from authentication information established earlier in the session and passed around via cookies. In the case of Java EE this is just available in the servlet API.
    3. How to capture the user's edits into something you can save in your repository.