Integrating PrimeFaces and Apache Trinidad

PrimeFaces is famous of it’s compatibility with other libraries, for example I know there are many users having PrimeFaces and JBoss RichFaces in their projects with no major problems. Recently I’ve also integrated PrimeFaces with Apache Trinidad however it is a bit tricky. In RichFaces case I didn’t have to do anything but with Trinidad I’ve created a very tiny library called compat-trinidad.jar that enables PrimeFaces to work with Trinidad. So what were the major problems of Trinidad integration.

1) Trinidad tr:form does not extend from JSF’s standard UIForm but it uses it’s own UIXForm API, this is an issue when PrimeFaces tries to find the parent form using UIForm API. I’ve resolved this by also checking for tr:form’s component class name. A bit ugly but no other way.
2) Trinidad has something called RenderingContext that is initialized before rendering the view with it’s own viewhandler. However in PrimeFaces ajax requests, No RenderingContext error was thrown when trying to update a trinidad component with PrimeFaces. compat-trinidad.jar fixes this.

So here’s a sample JSF 1.2 page, it simply echoes what you enter to input text using trinidad and primefaces button. Important part here is Trinidad’s outputText is updated with ajax in both cases.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:tr="http://myfaces.apache.org/trinidad"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:ft="http://primefaces.prime.com.tr/facestrace">

<head>
	<p:resources />
</head>

<body>

	<tr:document>

		<tr:form>

			<tr:inputText value="#{testBean.text}" />

			<tr:commandButton id="trinidad_btn" text="TR Submit" partialSubmit="true"/>

			<p:commandButton value="PF Submit" update="output"/>

			<tr:outputText id="output" value="#{testBean.text}" partialTriggers="trinidad_btn"/>

		</tr:form>

	</tr:document>

</body>

</html>

That’s it, now Trinidad users can enjoy the PrimeFaces goodness as well! Note that currently I’ve added Trinidad support only to PrimeFaces 1.0.1-SNAPSHOT, for PrimeFaces 2 and JSF 2, I’ll wait until Trinidad releases a stable release with JSF 2.0 support.

If you wonder how PrimeFaces manages to be compatible and lightweight, the answer is simple; it is designed targeting JSF 2.0 in the first place and it has no artifacts like custom ViewHandler, StateManager, UIViewRoot, Servlet Filters, Html Parsers, BlaBlaContexts as these stuff will break compatibility, cause race conditions and bring overhead.

I believe a JSF component library should focus on providing components only, not Rocket Science.

About these ads

3 Responses to Integrating PrimeFaces and Apache Trinidad

  1. Great work Cagatay!

    I will try to make PrimeFaces work with WebSphere Portal Server as well.

  2. matthiaswessendorf says:

    Good stuff regarding the integration!

    For 1) to blame is this ticket:

    https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=322

    There are no interfaces, just classes – dunno when it’s gonna be fixed. I hope soon.

    @components only: Well, sometimes (especially when building enterprise apps with it) you do need more. That’s what Trinidad delivers ;-)

  3. venkat says:

    HI

    Currently i am using trinidad alpha 2. which is quite stable. Will it be possible for you to give a compatability jar for primefaces against this version.

    Thanks

Follow

Get every new post delivered to your Inbox.

Join 107 other followers

%d bloggers like this: