Skip to main content

JSF as template engine

16 replies [Last post]
vladperl
Offline
Joined: 2004-08-11

Hi,
We are trying to use JSF as template engine. For example to generate HL7 messages.
Let say that we have created the page and we need to get result from rendering of the page in some method without getting through HTTP.
What is the best way to do it? It would be perfect for us to use string that contains result of rendering the Page.

Thanks in advance,
Vladimir

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rogerkeays
Offline
Joined: 2005-06-15

Take a look at this blog for some sample code of how you can use JSF for general purpose templating:

http://www.ninthavenue.com.au/blog/how-to-create-email-from-jsf-pages

vladperl
Offline
Joined: 2004-08-11

Hi Lincoln,
Following your advice I have filled out the enhancement.
See the link:
https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=749

I'm just asking to have possibility to get result of html rendering directly in Java code without going around browser and JSF life cycle :)
Please vote for it and put additional comments to present your point of view on this matter.

Everybody on this forum who like it please help us to promote the idea.

Thank you!
Vladimir

Lincoln Baxter, III

Will do!

And thank you for taking the time to do this. It's the first step to making
change in JEE :) People (like you) who are willing to invest your time and
effort are the reason why JSF and JEE are getting better every day!

--Lincoln

On Thu, Feb 18, 2010 at 5:57 PM, wrote:

> Hi Lincoln,
> Following your advice I have filled out the enhancement.
> See the link:
> https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=749
>
> I'm just asking to have possibility to get result of html rendering
> directly in Java code without going around browser and JSF life cycle :)
> Please vote for it and put additional comments to present your point of
> view on this matter.
>
> Everybody on this forum who like it please help us to promote the idea.
>
> Thank you!
> Vladimir
> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=387496
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"
[att1.html]

vladperl
Offline
Joined: 2004-08-11

Hi Lincoln,
I very much appreciate your activities in area of JSF.
One more suggestion.
Is it possible for JSF users to declare a month of strategic ideas for JSF?
This way we could have more power to define the future direction of JSF.
I see the business process contains the following parts:
1) Create strategic ideas box
2) Accept ideas during one month
3) Vote for ideas using dukes
4) Implement three the most popular ideas by JSF team
5) Start ideas iteration again after implementation finished

P.S.
in case you have read "A Fraction of the Whole" you understand that such box can turn everything upside down :)

vladperl
Offline
Joined: 2004-08-11

>I could, but it would probably be better if you did it, since you know what
>you need (templating not running as a servlet?)

I will fill out the issue during the next couple days and hopefully with your endorsement it will be implemented in prompt manner :)

Thank you for supporting the idea!
Vladimir

Imre Osswald

Hello Vladimir,

you could probably take Facestester, or some code from it (on http://kenai.com/projects/facestester from Jason Lee), if you don't want to use the filter approach. It is still a little bit rough here and there (and development is a little bit slow because of the work we have to do on other projects), but you should be able to use it for your needs.

Imre

Am 17.02.2010 um 22:18 schrieb webtier@javadesktop.org:

>> I could, but it would probably be better if you did it, since you know what
>> you need (templating not running as a servlet?)
>
> I will fill out the issue during the next couple days and hopefully with your endorsement it will be implemented in prompt manner :)
>
> Thank you for supporting the idea!
> Vladimir
> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=387254
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

[smime.p7s]

vladperl
Offline
Joined: 2004-08-11

Hi Imre,
>you could probably take Facestester

Thank you for tip!
I'm going to take a deep look there.

Best regards,
Vladimir

vladperl
Offline
Joined: 2004-08-11

Hi Martin,

>IMHO this very bad idea (especialy for HL7).
In my experience typical company implemented very limited subset of HL7 standard.
Beside in many cases their implementation doesn't strictly follow letter of the standard.
So in many cases it makes sense to create customized version that applied only to particular company.
Our implementation of HL7 messages divided in two parts.
First part used to generate HL7 messages in XML based format(see example below) and other part contains converter that just transform XML to HL7 EDI format.
There is a chance in future everybody will be used HL7 interchange based on XML. In this case we will get rid from convert part of our implementation.
Using HL7 XML Schema as validation tools and EL as way to easy get data we have very simple and powerful way to produce HL messages. Also it's working very fast at least if compare it with XLST as template engine.

>If you can, use HAPI.
Thank you for referring I found their site. I definitely will take a look on it.

For now we capture response from template using the javax.servlet.Filter.
Idea taken from "Core JavaServer Faces 2nd ed." by Geary & Hortsmann.
But it is somewhat inconvenient.
Here is the fragment of our working template:


xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
xsi:schemaLocation="urn:hl7-org:v2xml D:\SPS\doc\HL7\XMLENC~1\XMLENC~1\Support\v231-200307\v231-200307\v231-200307\xsd\ORM_O01.xsd">

|
^~\&

#{edi.laboratoryAccount.myApplication}


#{edi.laboratoryAccount.myAccountId}


#{edi.laboratoryAccount.partnerApplication}


#{edi.laboratoryAccount.myAccountId}







ORM
O01

#{edi.controlNumber}

#{edi.processingMode()}


2.3

Thank you for your response!

Martin Beránek

Dne 17.2.2010 21:16, webtier@javadesktop.org napsal(a):
> Hi Martin,
>
>> IMHO this very bad idea (especialy for HL7).
> In my experience typical company implemented very limited subset of HL7 standard.

You are right. We only need Order and Patient (update,merge) related
messages.

> Beside in many cases their implementation doesn't strictly follow letter of the standard.
> So in many cases it makes sense to create customized version that applied only to particular company.

So look at Terser class - with this I am able easily create and parse
messages based on my rules...

> Our implementation of HL7 messages divided in two parts.
> First part used to generate HL7 messages in XML based format(see example below) and other part contains converter that just transform XML to HL7 EDI format.
> There is a chance in future everybody will be used HL7 interchange based on XML. In this case we will get rid from convert part of our implementation.
> Using HL7 XML Schema as validation tools and EL as way to easy get data we have very simple and powerful way to produce HL messages. Also it's working very fast at least if compare it with XLST as template engine.
>
>> If you can, use HAPI.
> Thank you for referring I found their site. I definitely will take a look on it.

I am using this lib since 2006 without problems...

--
Martin Beránek
mailto:martin.beranek@i.cz
http://www.i.cz

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

vladperl
Offline
Joined: 2004-08-11

>I am using this lib since 2006 without problems...

Sound good! Definitely it makes sense to analyze how everything organize there.
Probably we could compare both approaches using the same type of messages :)
If It makes sense to you let me know. Keep in mind that I need more time to polish some details.

Vladimir

Ed Burns

>>>>> On Wed, 17 Feb 2010 07:30:11 -0800 (PST), webtier@javadesktop.org said:

V> We are trying to use JSF as template engine. For example to generate
V> HL7 messages. Let say that we have created the page and we need to
V> get result from rendering of the page in some method without getting
V> through HTTP.

V> What is the best way to do it? It would be perfect for us to use
V> string that contains result of rendering the Page.

The simplest way people have done this in the past is to wrap the
request/response using a Servlet filter placed in front of the
FacesServlet. You're going to have a tough time doing it without at
least starting the process this way because the JSF runtime makes a lot
of assumptions that it's running in a Servlet container via HTTP.

>>>>> On Wed, 17 Feb 2010 13:48:59 -0500, "Lincoln Baxter, III"
said:

LB> Otherwise you probably still need to run a JSF server, then use an HTTP
LB> client to send requests in order to capture the output. I agree with Martin
LB> -- look at Apache Velocity or something of that nature.

Yes, exactly.

LB> An extension to JSF could do this? Yes. Has it been done? No. I'm
LB> sure a lot of people would love you if you got something working ;)
LB> Including myself.

I do know that people have made it so JSF renders to PDF. But, again,
this was kicking off the process via the Servlet request/response flow.

V> I will fill out the issue during the next couple days and hopefully
V> with your endorsement it will be implemented in prompt manner :)

At this point, I need to step in and remind people what JCP
specifications are for. They are for providing a vendor neutral
programming model for people to get stuff done with Java.

I've said time and again that JCP specifications are emphatically *not*
the places to invent stuff. We tried that with JSF 1.0 and we're still
trying to live it down. Rather, they should standardize existing,
proven, best practices in a way that maximizes the cohesion of the
entire Java platform. I'm proud of the work we've done with JSF 2.0 in
this regard.

However, I desparately want and need innovation from people like
yourself so that we can ultimately improve the core spec. Let's take
two examples I've been mentoring recently.

1. Metamorfaces. I've been working with a gentleman in Senegal on his
ideas to create a Joomla! like technology built on top of JSF. In fact,
I'm presenting it as part of my keynote at JSFdays
next week. You can find out more at .

2. RooFaces. I've been working with a friend here in Orlando to provide
a Roo add-on that enables Roo to generate JSF2 pages. I mentioned it
recently in a comment on a blog entry at . This
also happens to be a Kenai project at .

LB> And thank you for taking the time to do this. It's the first step to
LB> making change in JEE :) People (like you) who are willing to invest
LB> your time and effort are the reason why JSF and JEE are getting
LB> better every day!

Exactly! I believe in the open source credo that "Innovation Happens
Elsewhere" as described in this excellent online book from Sun
luminsaries Ron Goldman and Richard P. Gabriel
.

V> 1) Create strategic ideas box
V> 2) Accept ideas during one month
V> 3) Vote for ideas using dukes
V> 4) Implement three the most popular ideas by JSF team
V> 5) Start ideas iteration again after implementation finished

This is a great idea, particularly now that the JSF spec is lead by a
company with more resources they could devote to JSF than Sun.

Ed Burns JSF Spec co-lead
Oracle America, Inc.

--
| ed.burns@sun.com | office: 408 884 9519 OR x31640
| homepage: | http://ridingthecrest.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

vladperl
Offline
Joined: 2004-08-11

>The simplest way people have done this in the past is to wrap the
>request/response using a Servlet filter placed in front of the
>FacesServlet. You're going to have a tough time doing it without at
>least starting the process this way because the JSF runtime makes a lot
>of assumptions that it's running in a Servlet container via HTTP.

We are using the same approach you mention here.
I was looking for confirmation that our approach is the most practical in current stage of JSF.
And you have provided it. Thank you for that!
But the most important thing you have said that JSF has architecture very much oriented around Servlet.
Those words put my thoughts in very different direction.
First of all, now I understand that is impossible with small tweak in JSF implementation to resolve the issue.
Second, I believe that now is the most important thing is relax as much as possible strong dependency architecture of JSF from Servlet lifecycle.
Starting from eliminating direct dependency between rendering engine and Servlet life cycle perhaps is the best way to make quick and big impact in this direction.

LB> Otherwise you probably still need to run a JSF server, then use an HTTP
LB> client to send requests in order to capture the output. I agree with Martin
LB> -- look at Apache Velocity or something of that nature.

Implementing decoupling jsf rendering engine from servlet lifecycle could provide possibility to use JSF with other template engines.
Who knows maybe some developers would prefer to use Velocity as main rendering force for JSF.

LB> An extension to JSF could do this? Yes. Has it been done? No. I'm
LB> sure a lot of people would love you if you got something working ;)
LB> Including myself.
As you can see from this comment there are many people who have interest to change something in this area.
It would be good if everybody who needs some changes describe the exact reason why they would benefit in case rendering process disconnect from JSF lifecycle.
(Probably there is a need to reformulate the question)
If you get number of reasons you will have more ground to design more precisely the future strategy.

>I do know that people have made it so JSF renders to PDF. But, again,
>this was kicking off the process via the Servlet request/response flow.
This is a perfect case. In many cases we need to render exactly the same report/page but in different from HTML format.
Usually this is PDF but could be something else.
To implement PDF rendering usually apply some kind of converter that can transform HTML to PDF.
So in case to use the converter we need direct access to result of HTML rendering.
Often PDF result must go instead of browser to email box.
It would be fun to have a possibility to use redirect process not only for browser but for email, atom and other communications means :)
In this situation ideal solution would be to have almost the same business logic for handling different types of rendering.

>I've said time and again that JCP specifications are emphatically *not*
>the places to invent stuff. We tried that with JSF 1.0 and we're still
>trying to live it down. Rather, they should standardize existing,
>proven, best practices in a way that maximizes the cohesion of the
>entire Java platform.
I understand your point and I’m ready to agree with it but there are a couple of issues with this approach.
What to do if some of the best, proven and existing practices established outside the Java world.
What to do when Java are losing market share to PHP and Ruby especially in area of web applications and JCP traditionally was the main driving force in area of innovations for Java World.

> I'm proud of the work we've done with JSF 2.0 in this regard.
No doubt here that in general strategy for JSF 2.0 was defined correctly and executed properly.
All main issues have been resolved on this stage.
Many people including myself are thankful for it.

>1. Metamorfaces. I've been working with a gentleman in Senegal on his
>ideas to create a Joomla! like technology built on top of JSF.
There are at least 1700 content management systems on the market.
In fact every single company has to use some kind of CMS.
For now PHP based CMS such as Wordpress, Joomla and Drupal dominate the market place.
The main requirement for CMS is to be very flexible and adaptive system.
Question is if JSF up to this task without taking too much effort from developers such system.
I’m not sure about it.
To be honest I’m planning to develop CMS very soon with my team and already have started to read a couple books on this topic.
The books describe in very clear manner how to create PHP based CMS.
Follow the books and it should be very easy to adapt their insight to JSF based system.
I’m talking so much about CMS because I truly believe that JSF team should use CMS as show case instead of Pet Store.
Definitely it's time to start doing less “pety” kind of examples :)
For today’s market we need something more mature.
If you like the idea to create CMS as show case for JSF advertisement I could help to implement it.
For example prepare specification or design database structure and so on. Of course I’m talking about creating mini kind of CMS.
The perfect name for it would be “Jungla” :) Instead of petit size animals such as cats or dogs it’s time to have lion's and tiger's faces as symbol JSF power.
Regarding Metamorfaces I'm going to dig there.

>2. RooFaces. I've been working with a friend here in Orlando to provide
>a Roo add-on that enables Roo to generate JSF2 pages.
Probably it’s not that bad idea to use JSF rendering mechanism as tools to generate source code.

>This is a great idea, particularly now that the JSF spec is lead by a
>company with more resources they could devote to JSF than Sun.
I really glad that you like the idea. You are practical man so my hope is that you will be able somehow to implement it.
To improve chances to get more resources for JSF developing its good tactic to be more proactive.
I suggest that you draw very ambitious plan and start asking for resources.

Here are the reasons why JSF world benefit from decoupling Template Engine from Servlet life cycle.

1)Testing (FacesTester project as example)
2)Validating rendering result before going online
3)PDF rendering
4)Rendering interchange messages such as X12, HL7 and so on
5)More flexible and complete solution for rendering non-HTML clients such as SVG, XUL, X3D and so on, comparing to RenderKit.
6)Rendering JSON and JavaScript (Frisco JSF additions as example, rise level of usage JavaScript frameworks)
7)Source Code generation (including generation code on the fly)
8)Rendering ORM.xml(JPA entities), business rules(MVEL)
9)Access and Control improvements
10)Navigation Flow improvements
11)Pluggable rendering/template engine (possibility to use Velocity, JavaScript based template engine and so on)
12)Possibility to use Servlet replacement such as JSGI
13)Higher possibility to use JSF by different frameworks and languages

Thank you for attention!
Vladimir

Martin Beránek

Hi,

IMHO this very bad idea (especialy for HL7). If you can, use HAPI.
Insted use some real templating engine.

Dne 17.2.2010 16:30, webtier@javadesktop.org napsal(a):
> Hi,
> We are trying to use JSF as template engine. For example to generate HL7 messages.
> Let say that we have created the page and we need to get result from rendering of the page in some method without getting through HTTP.
> What is the best way to do it? It would be perfect for us to use string that contains result of rendering the Page.
>
> Thanks in advance,
> Vladimir
> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=387185
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

--
Martin Beránek
mailto:martin.beranek@i.cz
http://www.i.cz

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Lincoln Baxter, III

Otherwise you probably still need to run a JSF server, then use an HTTP
client to send requests in order to capture the output. I agree with Martin
-- look at Apache Velocity or something of that nature.

An extension to JSF could do this? Yes. Has it been done? No. I'm sure a lot
of people would love you if you got something working ;) Including myself.

--Lincoln

2010/2/17 Martin Beránek

> Hi,
>
> IMHO this very bad idea (especialy for HL7). If you can, use HAPI. Insted
> use some real templating engine.
>
> Dne 17.2.2010 16:30, webtier@javadesktop.org napsal(a):
>
> Hi,
>> We are trying to use JSF as template engine. For example to generate HL7
>> messages.
>> Let say that we have created the page and we need to get result from
>> rendering of the page in some method without getting through HTTP.
>> What is the best way to do it? It would be perfect for us to use string
>> that contains result of rendering the Page.
>>
>> Thanks in advance,
>> Vladimir
>> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=387185
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>>
>>
> --
> Martin Beránek
> mailto:martin.beranek@i.cz
> http://www.i.cz
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"
[att1.html]

vladperl
Offline
Joined: 2004-08-11

Hi Lincoln,
>An extension to JSF could do this? Yes. Has it been done? No. I'm sure a lot
>of people would love you if you got something working ;) Including myself.

Could you as member of JSF Expert Group fill out proposal to implement it in the next version of JSF :)
For now we have to use sluggish work around using javax.servlet.Filter.

Thank you!

Lincoln Baxter, III

I could, but it would probably be better if you did it, since you know what
you need (templating not running as a servlet?)

https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues

You'll need a dev.java.com account, but those are easy to get, just
register.

Submit an enhancement request.

Thanks for your contributions! It's really a good idea IMO.

--Lincoln

On Wed, Feb 17, 2010 at 3:21 PM, wrote:

> Hi Lincoln,
> >An extension to JSF could do this? Yes. Has it been done? No. I'm sure a
> lot
> >of people would love you if you got something working ;) Including myself.
>
> Could you as member of JSF Expert Group fill out proposal to implement it
> in the next version of JSF :)
> For now we have to use sluggish work around using javax.servlet.Filter.
>
> Thank you!
> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=387247
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"
[att1.html]

Lincoln Baxter, III

Sorry, a dev.java.net account.

On Wed, Feb 17, 2010 at 3:28 PM, Lincoln Baxter, III <
lincolnbaxter@gmail.com> wrote:

> I could, but it would probably be better if you did it, since you know what
> you need (templating not running as a servlet?)
>
> https://javaserverfaces-spec-public.dev.java.net/servlets/ProjectIssues
>
> You'll need a dev.java.com account, but those are easy to get, just
> register.
>
> Submit an enhancement request.
>
> Thanks for your contributions! It's really a good idea IMO.
>
> --Lincoln
>
>
> On Wed, Feb 17, 2010 at 3:21 PM, wrote:
>
>> Hi Lincoln,
>> >An extension to JSF could do this? Yes. Has it been done? No. I'm sure a
>> lot
>> >of people would love you if you got something working ;) Including
>> myself.
>>
>> Could you as member of JSF Expert Group fill out proposal to implement it
>> in the next version of JSF :)
>> For now we have to use sluggish work around using javax.servlet.Filter.
>>
>> Thank you!
>> [Message sent by forum member 'vladperl' (vladperl@hotmail.com)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=387247
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>>
>>
>
>
> --
> Lincoln Baxter, III
> http://ocpsoft.com
> http://scrumshark.com
> "Keep it Simple"
>

--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"
[att1.html]