Showing posts with label JSF. Show all posts
Showing posts with label JSF. Show all posts

Monday, July 7, 2008

JSF in a portlet has never been this easy!

We just released JBoss Portlet Bridge Beta3 along with some good supporting documentation and example projects. See the documentation for full details.

The majority of the code written for this release is internal to the portlet bridge project (refactoring, 301 spec updates and enhancements, bug fixes...). The next release (Beta 4 - early Sept) will be huge for the portlet bridge for the following reasons:
  • The EG is currently discussing a lot of significant clarifications and improvements. For example, working with the JSF 2.0 EG to allow certain needs and working on Portlet 2.0 areas of the spec.
  • There is currently a lot of discussion about navigation between portlet modes. Once this is nailed down in the spec, we will implement it.
  • The Portlet 1.0 version should be getting close to public review.
Other than the spec related reasons for release schedule, we must work in unison with the latest Seam and RichFaces relases, make sure that we squash any bugs concerning the 3 integration points, handle features/improvements/refactorings, and try to test and give feedback to the 301 EG. And, of course we can't forget about JBoss Portal 2.7+!

There are soo many cool things going on right now within the JBoss Portal project, I would like to tell you about all of them but then this post wouldn't be about JBPB anymore. Just stay tuned to this blog...

With that said, here are a few tips for JSF portlet developers that concern this release:
  • Namespacing
    In situations where you need to use the id of an element in your JSF/xhtml markup, you would normally see something like 'form1:myBtn' in the rendered markup. But now with the bridge namespacing you will see something similar to:

    jbpns_2fdefault_2fNews_2fStories_2fStoryTemplateWindow12snpbj:_viewRoot:form1:myBtn

    To overcome this, you can use the following expression in your Facelets page to prepend the namespace to your javascript code:

    document.getElementById('#{facesContext.externalContext.response.namespace}the_rest_of_JSF_ID

    since this uses the portletResponse, once you try to view this page on the servlet application side, you will get an exception. To avoid this, you need to check for the type of response in your backing bean and assign a new "safe" namespace variable for the UI.

  • Excluding Attributes from the Bridge Request Scope
    When your application uses request attributes on a per request basis and you do not want that particular attribute to be managed in the extended bridge request scope, you must use the following configuration in your faces-config.xml. Below you will see that any attribute namespaced as foo.bar or any attribute beginning with foo.baz(wildcard) will be excluded from the bridge request scope and only be used per that application's request.

    <application>
    <application-extension>
    <bridge:excluded-attributes>
    <bridge:excluded-attribute>foo.bar</bridge:excluded-attribute>
    <bridge:excluded-attribute>foo.baz.*</bridge:excluded-attribute>
    </bridge:excluded-attributes>
    </application-extension>
    </application>

    Or you can use the javax.portlet.faces.annotation.ExcludeFromManagedRequestScope annotation to accomplish the same thing.
For more information on this release or to find out more about the project, visit the project page.

Thursday, April 10, 2008

JBoss Portlet Bridge Beta2 Released

Supports:
  • JBoss Portal 2.6.4
  • Seam 2.0.2.CR1
  • RichFaces 3.2.0.GA (with exception of upload component)
  • JSF 1.2
This release of the bridge has quite a few bug fixes and enhancements:
  • Portlet EL Variable support
  • New SeamIdentity Bridge Extension: instant SSO between your Seam application and your JBoss Portal server by a simple dependency in your pom
  • RichFaces Maven Archetype
  • Removal of PortalStateManager configuration
  • More documentation

EL Variable Support

portletConfig: object of type javax.portlet.PortletConfig

sessionPortletScope: mutable Map containing PortletSession attribute/values at PORTLET_SCOPE.

sessionApplicationScope: mutable Map containing PortletSession attribute/values at APPLICATION_SCOPE.

portletPreferenceValue: immutable Map containing the set of portlet preferences where the key is the name of the preference and the value is the first portlet preference value from the (potential) set of values.

portletPreferenceValues: immutable Map containing the set portlet preferences where the key is the name of the preference and the values are the set of this portlet preference's values.


SeamIdentity Bridge ExtensionJust add the following dependency to your JBoss Seam (Maven) project for SSO between JBoss Portal and Seam applications.
<dependency>
<groupid>org.jboss.portletbridge.extension.seam</groupid>
<artifactid>PortalIdentity</artifactid>
<version>1.0.0.B2</version>
</dependency>
RichFaces Maven Archetype
This is the new Beta2 release of the RichFaces archetype - only a few settings are different from the previous snapshot release.
mvn archetype:create
-DarchetypeGroupId=org.jboss.portletbridge.archetypes
-DarchetypeArtifactId=richfaces-basic
-DarchetypeVersion=1.0.0.B2
-DgroupId=org.whatever.project
-DartifactId=myprojectname
-DremoteRepositories=http://repository.jboss.org/maven2/

Removal of PortalStateManager configuration
The following is no longer needed in the faces-config.xml
 <state-manager>
org.jboss.portletbridge.application.PortalStateManager
</state-manager>
Visit the Portlet Bridge project page for more details.

Wednesday, March 12, 2008

RichFaces Portlet Archetype

I just finished creating a Maven archetype for the RichFaces portlet using the JBoss Portlet Bridge. An archetype basically gives you a empty project shell with all of the proper config files and package names that are custom to your project. It comes packaged with a simple demo of the RichFaces ajax repeater code.

From the command line run:
mvn archetype:create -DarchetypeGroupId=org.jboss.portletbridge.archetypes -DarchetypeArtifactId=richfaces-basic
-DarchetypeVersion=1.0.0-SNAPSHOT -DgroupId=org.whatever.project -DartifactId=myprojectname
-DremoteRepositories=http://snapshots.jboss.org/maven2/
Navigate to the newly created project folder and run mvn install - now you are ready to deploy the war file located in the target directory.

Thursday, February 14, 2008

JBoss Portlet Bridge 1.0.0 Beta Released!

Thanks to the collaboration of the JBoss RichFaces, Seam and Portal teams, we are happy to announce an initial beta release of JBoss Portlet Bridge.
The JBoss Portlet Bridge is an implementation of the JSR-301 specification to support JSF within a portlet and with added enhancements to support other web frameworks. Currently the bridge supports any combination of JSF, Seam, and RichFaces to run inside a portlet.

The following is supported with JBoss Portlet Bridge 1.0.0.B1 Download
  • You can download the portlet bridge binaries here, which contain the required jars along with a deployable EAR file. The EAR is the Seam Booking Demo which uses both RichFaces and Seam.

Deploy

  • copy the ear file from example/seamEar.ear to JBoss_Home/server/default/deploy and start the server.

Test Drive

  • You should see a SeamBooking tab with the official JBoss Seam Booking Demo.
Setup and Configuration
  • Check out the configuration examples here.
Live Demo
  • The Seam Booking and RichFaces component demos can be viewed here.
All information to get up and running with configuration options for any combination of the frameworks mentioned above can be found on the wiki.

JBoss World day 1

Yesterday was the first JBoss World day.

I had the chance to go on stage during the keynote, invited by our CTO Sacha Labourey to make a little (but working) demo of JBoss Portal 2.6.4. My goal was to show to the audience the current JBoss Portal product and to get the following message out:

  • JBoss Portal 2.6.4 just released
  • JBoss Portlet Container 2.0 Beta, an implementation of the Portlet 2.0 spec (will be released tomorrow, more to come, stay tuned)
  • JBoss Portlet Bridge to make the integration of JSF/RF/Seam apps in JBoss Portal
Right now I am sitting at Thomas session about JBoss Portal. 

My talk is tomorrow morning at 9 AM and you don't want to miss it if you are present and want to hear about Portlet 2.0. I hope to see you there!

Friday, January 11, 2008

How to access the Portlet Mode from a JSF Portlet

We at JBoss a division of Red Hat use Hudson as a Continuous Integration tool. So I thought why not write a portlet that integrates with Hudson. The portlet can be downloaded from Portlet Swap. I ended up using the RI JSF implementation and JSF-Portlet bridge. It took me a while to figure out how to access some portal/portlet related objects in managed bean so I thought I should share what I found out.

To get the portlet mode in JSF's managed bean, you need to do
Object reqObj = FacesContext.getCurrentInstance().getExternalContext().getRequest();
if  (reqObj instanceof PortletRequest)
{
request = (PortletRequest)reqObj;
return request.getPortletMode();
}


You can get PortletPreferences similary by using request.getPreferences().

To get init parameters that you have specified in portlet.xml, you use
Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
if (null != applicationMap)
{
PortletConfig config = (PortletConfig)applicationMap.get("javax.portlet.PortletConfig");
return config.getInitParameter(param);
}


Thursday, November 15, 2007

Seam 2.0 Portlet Example

Update - This post is deprecated. Please see this article about the new JBoss Portlet Bridge.


We are happy to announce a "technology preview" of the JBoss Portal Seam 2.0 portlet. Thanks to the hard work of the JSR-301 Expert Group we are able to integrate the Seam Booking Example via a portlet. However, there are still some limitations and RichFaces is currently not integrated.
For the booking example, we have replaced RichFaces components with standard JSF RI 1.2 components.
We made this example beyond easy to get up and running and it shouldn't take more than a few minutes to have it running locally on your machine.

Prerequisites
  • Install latest version of Maven 2.x
  • Checkout the project using a subversion client from http://anonsvn.jboss.org/repos/portletbridge/trunk/examples/seam/booking
  • I used a Mysql database for this demo. You can use any of the DBs that Jboss Portal supports but for the sake of following along with this tutorial, I recommend downloading and starting a Mysql instance on your local machine.

Local Setup
Once you have Mysql started, login to the mysql console as root and run the following:
create database jbossportal;

GRANT ALL PRIVILEGES ON jbossportal.* TO 'jbossportal'@'localhost' IDENTIFIED BY 'jbossportal';

That's it!

Now, navigate to the root of the SeamBookingPortlet application and run
mvn install

Once the build is finished and successful, navigate to SeamBookingPortlet/ear and run
mvn cargo:start

*Note - this will take a few minutes. This downloads JBoss AS 4.2.2.GA along with the core installation of JBoss Portal 2.6.2. The download was around 100MB, but I removed as much as possible and got it down to 40MB. Once this is finished and the server is started, do yourself (and our servers ;) a favor and copy the zip file from SeamBookingPortlet/ear/target/installs/jboss-4.2.2.GA-2.6.2.zip to somewhere outside of this directory (anywhere on your machine) and open the ear/pom.xml to point to your new local file location. This can be changed at the bottom of the pom.xml file.

Now you are ready to deploy the SeamBookingDemo ear to your running JBoss server. Open a new console window and navigate to the same directory you were in SeamBookingPortlet/ear and run
mvn cargo:deploy

After you see that the Seam application has deployed. Open a new window/tab and visit http://localhost:8080/portal. You should see the Seam Booking application in a portlet window.

This example uses the core installation of JBoss Portal 2.6.2, Seam 2.0 GA, and the JSR-301 Bridge from MyFaces. The code for the booking demo is unmodified and a direct port from the Seam cvs repository. The modifications made to the JBoss AS download are minimal. First, I installed the core JBoss Portal 2.6.2 ( How to install). Then I added the datasource files for both Seam Booking and Portal. Finally I added the mysql driver to the server lib folder. That is all the changes that were made from the 4.2.2 GA release (other than I deleted around 50MB of unneeded files for this demo).

Thanks to the JSR 301 specification it is now possible to make Seam applications work in a Portlet environment. The next challenge for us, is to get Rich Faces components working in Seam applications in the same Portlet environment.

Thursday, November 1, 2007

JSFUnit is born

Well or at least it has its official blog!

I encourage you to have a look at it because it's a real progress in web UI unit testing which allow to test your web UI without relying on the underlying layer (CSS/HTML/HTTP) and make sure that your application behaves correctly when a user interacts with it.

Friday, June 22, 2007

JSF is great but...

that kind of code does not help to find out why the value was wrong. It is part of the class org.apache.myfaces.renderkit.RendererUtils (1.1.1)


public static Boolean getBooleanValue(UIComponent component)
{
Object value = getObjectValue(component);
if (value==null || value instanceof Boolean)
{
return (Boolean) value;
}
else
{
throw new IllegalArgumentException("Expected submitted value of type Boolean for Component : "+
getPathToComponent(component));
}
}



It's so trivial that I will not submit a patch (perhaps it is already improved now).

It's an half rant, Thomas will do a full JSF rant next week when he will tell you how trivial it is to make a JSF application executed in a portlet container and a target environment that is MyFaces or Sun RI (or why we had to develop the JSFMetaBridge).