This discussion is archived
1 2 Previous Next 16 Replies Latest reply: May 24, 2012 2:59 AM by gimbal2 RSS

Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?

937630 Newbie
Currently Being Moderated
I'm new to JEE6 web apps with JSF 2.x frontends (GlassFish 3), and I still wasn't able to find a solution for this dynamic JSF 2.x problem:

*From inside a running JSF 2.x web app (Servlet 3.0), which possibilities (if any) do I have to dynamically add generated JSF pages (whole new .xhtml files) to specific folders of the (exploded) document root, so that these pages can be dispatched to the client like any traditional, statically-deployed one?*

Background: An app for "promoting" authors/editors (content providers) which has these few main requirements:
<ol>
<li>New providers will register under <tt>www.acme.com/app/register.xhtml</tt>.</li>
<li>The system will grant each provider "sub-domain" associated with web space under
<tt>www.acme.com/app/<b>providerX</b></tt> where providerX is an arbitrary sub-domain name chosen by the provider during the registration.</li>
<li>Each provider will initially have some pre-defined pages in their document context root, e.g.
<tt>www.acme.com/app/providerX/index.xhtml</tt>, <tt>about-me.xhtml</tt>, <tt>contact.xhtml</tt>, etc.</li>
<li>Each provider will have an administration console for managing 2 tasks:
<ul>
<li type="a"><tt>www.acme.com/app/providerX/admin/page-manager.xhtml</tt> </li>
<li type="a"><tt>www.acme.com/app/providerX/admin/customer-manager.xhtml</tt></li>
</ul>
to specify new pages with offers, publish these pages in their document context root, e.g. <tt>www.acme.com/app/<b>providerX</b>/<b>my-services</b>.xhtml</tt> (customized page name), and
to manage their readers/customers, respectively.
</li>
<li>Thus, each providerX will also have a pre-deployed customer registration page running, which creates standard customer accounts. E.g.:
<ul>
<li type="disc"><tt>www.acme.com/app/providerX/customers/registration.xhtml</tt></li>
<li type="disc"><tt>www.acme.com/app/providerX/customers/login.xhtml</tt></li>
<li type="disc"><tt>www.acme.com/app/providerX/customers/customer-account-dashboard.xhtml</tt></li>
</ul>
</li></ol>
Please note: I know that for such kind of systems a CMS would be more suitable, but is such a system -- here aiming at only basic functionality -- also realizable in pure JEE 6 technologies, i.e. w/o CMS???

<b>The unclear main aspect is stated in my initial question above. Basically, I hope to get these clarifications:</b>
<ol>
<li><b>Which app architecture designs can I use to deploy new generated JSF pages or servlets from within a running JSF page or servlet???</b></li>
<li><b>Supposing that all relevant page description data provided by a provider is stored in a db:
Where can I "cache" the new .xhtml pages generated from these data on-the-fly when (a) an exploded WAR, and (b) a packaged WAR is running???</b>
The pages shall be "hooked" to the scope (doc root) of the respective provider and dispatches by the <tt>FacesServlet</tt> as such.</li>
</ol>
Due to the crucial importance in a current project, I'd really appreciate any constructive help very much.
Natalia.
  • 1. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    gimbal2 Guru
    Currently Being Moderated
    The JEE6 specification provides no services for these matters - nor should it. Its in the containers themselves you should be looking for possibilities. So investigate what deployment options Glassfish, JBoss, Weglogic, etc. have. I know for a fact that JBoss 7 has quite flexible deployment features, so perhaps you will want to start there.
  • 2. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    @gimbal2: Thank you very much for the quick response and hint. Though I currently try things with GlassFish 3, JBoss 7 would also be OK for me.

    Supposing to have the container control possibilities of JBoss 7, could you please shortly name the ones essential for this scenario (so that I can better imagine the power and also investigate further on these features)?
    And, knowing that such a response isn't self-evident but would be a big favor for me at the moment, could you please give a brief description on how these control possibilities are usually combined to a working solution? -- As I'm currently still not seeing the "whole picture". A brief sketch of the top-level strategy will suffice completely.

    Quite uncertain, I could imagine that the key topics here are:
    <ol>
    <li>some kind of separated "sub-domains" for each provider, dynamically created, controlled and isolated from the others by the front controller servlet (perhaps even some kind of "virtual hosts" within the server).</li>
    <li>for each provider "sub-domain", a specific security mechanism with basically 2-3 roles ("provider", "editor", and "customer") which, with my understandings, must be configurable dynamically by the respective provider itself, i.e. concerning the available persons, groups and person/group-to-role mappings, and probably the definition of new security roles if needed.
    Could this be handled at container level, or must this be treated by a dedicated security sub-component at app-level???</li>
    </ol>

    Thank you a million for pointing me in the right direction.
    Natalia
  • 3. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    EJP Guru
    Currently Being Moderated
    Re the CMS remark, it's a bit like what I am doing at the moment. I have a learning application which is pesented via JSF and which has a lot of pages provided by the application, e.g. login, change profile, user home page, and so forth, but also a set of actual learning texts that are contributed by third parties that I really don't want to be part of the web app proper, for deployment reasons, and that have to be updateable and grow-able independent of the web app.

    I wrestled with various architectural concepts such as looking for a JSF based CMS to use as a back end. I think I have finally settled on JSF, the Java Content Repository as the data store, some hooks in the application that make it look in the JCR as well as the disk for pages, and WebDAV (rather than a CMS) as the means of updating the repository. Apache Jackrabbit is giving me all that. The application doesn't generate pages, the users have to write them, but I support that with various custom tags. I guess the application could write pages too, it's just another button push :-)
  • 4. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    @EJP: Thank you very much for your remark concerning the solution with JCR.

    For me, it was Apache Jackrabbit too that I investigated last week a bit to "derive" a Document Repository based solution. Finally I wondered if it really would be necessary to involve a technology (a) completely new to me and (b) that is not present in the standard JEE 6 tech stack. That's why I asked this forum (and also in StackOverflow), as I couldn't imagine that this kind of dynamic scenario isn't a real-world scenario out there. Unfortunately, at least in StackOverflow, I haven't received constructive suggestions yet.

    Concerning your arch, if permitted, I've got 2 "quick questions":
    <ol>
    <li>What exactly is stored in the JCR, and what in the WebDAV?
    If I got it right, the JCR stores pages only of your app, and WebDAV the 3rd-party pages(?), right?</li>
    <li>Not yet exactly knowing what's in JCR, what is delivered to the JSF layer, and how do both layers work/interact together?</li>
    </ol>
    It's because I'm still wondering if JCR could be a working solution for me.
    I'll basically have 2 essential storage requirements:
    <ol>
    <li type="a">semi-dynamic data/record types -- think of POJOs with some pre-defined regular attributes and 0..* dynamic (user-defined) attributes.</li>
    <li type="a">semi-dynamic presentation widgets and pages that render the above data objects -- think of some standard and some custom-created pages, each customizable via layout+theme templates and custom widget placements+configs; widgets almost each having such a semi-dynamic data object as data provider.</li>
    </ol>
    Maybe finally a JCR-involving solution is also a solution for me ;-)
    Thank you very much, Natalia.
  • 5. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    Please, does nobody have any further/concrete tips on how to solve this kind of problem in GlassFish v3 or, alternatively, in Tomcat 7 web container?!?
    I'd very thankful for any suggestions.
    Thanks a lot in advance, Natalia.
  • 6. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    EJP Guru
    Currently Being Moderated
    <li>What exactly is stored in the JCR, and what in the WebDAV?
    The pages contributed by the content authors are in the JCR.
    The rest of your question doesn't make sense. WebDAV isn't a store, it is a web-based means of accessing the JCR.
  • 7. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    gimbal2 Guru
    Currently Being Moderated
    Natalia F. wrote:
    <li type="a">semi-dynamic data/record types -- think of POJOs with some pre-defined regular attributes and 0..* dynamic (user-defined) attributes.</li>
    I would make those user defined attributes a List or Map if I were you, so you can stay out of the realm of dynamic objects. Compiled languages like Java are not the tool for the job when you want to introduce dynamic code, things are meant to be static at runtime. If you want dynamic objects, you make your life quite difficult. Seeing as you're new to it all, that is not something I'd consider attempting if I were you.
  • 8. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    Dear gimbal2: Thank you for your answer.

    Using Java, I thought of an Array or Map of "DynAttribute" entries, the latter storing attribute name (would be key entry in a Map-based solution), attribute value, and attribute type (metadata).

    Determining you as one of the experts in this forum, please, could I ask you how you'd solve this kind of web apps in JSF2 (one of the requirements stated at the beginning of this thread):

    Having a "page-manager.xhtml" JSF2 UI at "/page-manager" context that lets registered member X define a website (=a set of .jsf/.xhtml pages) in a new context "/websiteX" (where "websiteX" is freely chosen and associated with dedicated webspace to store the pages in the filesystem):

    How to store these dynamically created website pages from within the PageManagerServlet?

    <ol><li type="a">Could I create a new exploded WAR structure in the filesystem (or elsewhere) when a new context is defined, and then store new .jsf/.xhtml files therein when a new page is defined, all this with usual file operations? -- Would this be enough, or...</li>
    <li type="a">...after storing a new page, would I need to explicitly tell the container to deploy the page (or re-deploy the WAR(?)) so that I can instantly test/run the page when it is new/modified, or will it be compiled automatically when pointing a browser to it???
    I guess both is possible, but for performance reasons, a pre-compile would be better. How can I achieve this?</li>
    </ol>

    Thank you a million for your help, Natalia.
  • 9. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    gimbal2 Guru
    Currently Being Moderated
    Natalia F. wrote:
    Determining you as one of the experts in this forum, please, could I ask you how you'd solve this kind of web apps in JSF2 (one of the requirements stated at the beginning of this thread):
    I'm certainly an expert at having an opinion about everything.
    >
    Having a "page-manager.xhtml" JSF2 UI at "/page-manager" context that lets registered member X define a website (=a set of .jsf/.xhtml pages) in a new context "/websiteX" (where "websiteX" is freely chosen and associated with dedicated webspace to store the pages in the filesystem):

    How to store these dynamically created website pages from within the PageManagerServlet?

    <ol><li type="a">Could I create a new exploded WAR structure in the filesystem (or elsewhere) when a new context is defined, and then store new .jsf/.xhtml files therein when a new page is defined, all this with usual file operations? -- Would this be enough, or...</li>
    <li type="a">...after storing a new page, would I need to explicitly tell the container to deploy the page (or re-deploy the WAR(?)) so that I can instantly test/run the page when it is new/modified, or will it be compiled automatically when pointing a browser to it???
    I guess both is possible, but for performance reasons, a pre-compile would be better. How can I achieve this?</li>
    </ol>

    Thank you a million for your help, Natalia.
    I only see mention of xhtml files - that is the easy part. But XHTML files don't actually do anything at all. What about classes like JSF managed beans? jar libraries? database connections and ORM/JPA support which also adds the complexity of having to deal with all the configuration descriptor files? Even if you can automatically deploy all that, replacing existing classes and reloading them is a whole different matter.

    My "expert" opinion: this cannot be done with JSF. In fact the only Java web framework which I can think of that has any chance of making something like this possible is Play framework. I'd really take the road that EJP took: make the content dynamic, not the webapp.
  • 10. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    Dear gimbal2: First, thank you very much for you opinion.
    I only see mention of xhtml files - that is the easy part. But XHTML files don't actually do anything at all. What about classes like JSF managed beans? jar libraries? database connections and ORM/JPA support which also adds the complexity of having to deal with all the configuration descriptor files? Even if you can automatically deploy all that, replacing existing classes and reloading them is a whole different matter.
    O.K., that's a good point. In respect and just to clarify, I thought the 1st web app (new-contexts installer app) would be in charge of installing "the framework" -- basically, the editor to create the new pages (carrier documents) as well as a pre-defined set of widgets to populate the pages, each widget having its own pre-defined JSF ManagedBeans as well as connections to the business tier of the member X context (at least to the pre-defined JPA PersistenceContext accessing the backend db of member X context).

    Thus, the actual dynamics are in (a) the page set with individual page names, (b) the widgets composition topology on each page, and (c) the dynamic content data (text, images, table cell contents, etc.) provided through each widget. -- After having the several "carrier documents" in place with its individual names, for the pages admin it's all more or less a widget selection and configuration issue.
    That's the coarse plan.
    My "expert" opinion: this cannot be done with JSF. In fact the only Java web framework which I can think of that has any chance of making something like this possible is Play framework. I'd really take the road that EJP took: make the content dynamic, not the webapp.
    So, the plan is not possible in JSF2 ???

    If this would be true, than, in consequence, the whole bunch of neat Web 2.0 Website creation sites like "Squarespace.com" or "Weebly.com" could NOT be realized in JSF2, could they??? Actually, I really cannot believe that!
    What do you think on that?

    Thanks a lot, Natalia.
  • 11. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    EJP Guru
    Currently Being Moderated
    Another thing I have done in a few places where I simply cannot be faffed with writing a bean is to put a Map into session scope and stick things in there for transmission between pages and the application proper. Might be an interesting line of enquiry. Are you contemplating user-contributed beans? or are you just trying to give the same facility without the beans?
  • 12. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    gimbal2 Guru
    Currently Being Moderated
    Natalia F. wrote:
    If this would be true, than, in consequence, the whole bunch of neat Web 2.0 Website creation sites like "Squarespace.com" or "Weebly.com" could NOT be realized in JSF2, could they??? Actually, I really cannot believe that!
    Both seem to work as CMS systems and are likely built on top of either Ruby or PHP - scripting languages which are interpreted at runtime. The CMS part can surely be done with any programming language (but using some platforms will cost a whole lot more time, money and effort than others; there is a reason why there are a million of them built in PHP and there are almost none built in Java), but that's not what you're asking.

    And yes, I do believe that you can't do just any requirement using JSF. I also believe that there is a gray area of requirements that you COULD do with JSF, but shouldn't because there are far more suitable tools available. Perhaps this one falls in the latter, I don't know. I do love JSF by the way, I'm just not the type to be a fan boy and throw realism out the window.
  • 13. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    937630 Newbie
    Currently Being Moderated
    Dear EJP: Thank you for your answer.
    Are you contemplating user-contributed beans? or are you just trying to give the same facility without the beans?
    If I got it right, you're asking if the app will handle custom-defined data types (custom entities), right?
    Well, for now it only should be able to handle a pre-defined "DataRecord" structure, which will have an arbitrary number of supported atomic -type entries of types like boolean, integers, etc., and arrays thereof. Thus, the app will NOT -- at least at the moment -- use custom-defined entity beans.

    Btw., could you please tell me which of the JSF-based CMSs found in your investigations (mentioned in one of your previous posts) you found promising? -- Preferably among the JSF *2* ones.

    Thank you very much, Natalia.
  • 14. Re: Creating new JSF2 pages from a running Servlet (3.0) or JSF2 page?
    gimbal2 Guru
    Currently Being Moderated
    Natalia F. wrote:
    Btw., could you please tell me which of the JSF-based CMSs found in your investigations (mentioned in one of your previous posts) you found promising? -- Preferably among the JSF *2* ones.
    Flexive, but its JEE5 / JSF 1.2:

    http://www.flexive.org/

    That is really the only one I know, perhaps EJP knows a few more.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points