Thursday 9 June 2011

Contd. Richfaces 4

In continuation to my previous post on Richfaces 4 Why and How!

Creating dynamic Richfaces 4 components:

Adding dynamic components to the page is little bit tricky now! Though it's a temporary solution which I am going to post, but later it will work as it used to work before!

The issue is when we create a dynamic component it does not appear in the first go, or may appear with the only texts but no styling! Then we would wonder what's gone wrong!

The reason for this I found in Richfaces forum is:
Actually it's just JSF 2 problem which I believe should be solved at some point by the Oracle and Apache guys. Dynamically rendering of the components (which was at component tree before but just not rendered) works fine in JSF as it pre-renders resources for all the components even for those which are not rendered. But that is not applied to the case when the component was not present in JSF tree at all. And unfortunately it's your case. And the only workaround we found:
add <dropDownMenu rendered="false"/> to the page.

So, for e.g. we have rich:dropDownMenu, which we want to create dynamically and add menu items dynamically, to make it work in the web page, we need to add dummy components with rendered attribute false to the page. Below is a sample code:

dropdownmenu.xhtml

    <h:form id="form">
        <rich:toolbar height="26px" binding="#{dropDownMenuBean.menuBar}"/>

        <rich:toolbar rendered="false" />
        <rich:dropDownMenu rendered="false" />
        <rich:menuItem rendered="false" />
    </h:form>

DropDownMenuBean.java

@ManagedBean
@ViewScoped
public class DropDownMenuBean {
    private UIToolbar menuBar;
  
    public void setMenuBar(UIToolbar menuBar) {
        this.menuBar = menuBar;
    }

    public UIToolbar getMenuBar() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        menuBar = (UIToolbar) ctx.getApplication()
            .createComponent(ctx, UIToolbar.COMPONENT_TYPE,
            "org.richfaces.ToolbarRenderer");
        UIDropDownMenu dropDownMenu = (UIDropDownMenu) ctx.getApplication()
            .createComponent(ctx, UIDropDownMenu.COMPONENT_TYPE,
            "org.richfaces.DropDownMenuRenderer");
        HtmlOutputText label = (HtmlOutputText) ctx.getApplication()
            .createComponent(HtmlOutputText.COMPONENT_TYPE);
        label.setValue("File");
        dropDownMenu.getFacets().put(UIDropDownMenu.Facets.label.name(), label);
        dropDownMenu.setMode(Mode.ajax);
        dropDownMenu.setHideDelay(0);
      
        UIMenuItem menItm = (UIMenuItem) ctx.getApplication().createComponent(ctx,
                UIMenuItem.COMPONENT_TYPE,
                "org.richfaces.MenuItemRenderer");
        menItm.setLabel("New");
        menItm.setIcon("/images/icons/create_doc.gif");
        menItm.setMode(Mode.ajax);
        menItm.setOnclick("alert('hello');");
        dropDownMenu.getChildren().add(menItm);

        UIMenuItem menItm2 = (UIMenuItem) ctx.getApplication().createComponent(ctx,
                UIMenuItem.COMPONENT_TYPE,
                "org.richfaces.MenuItemRenderer");
        menItm2.setLabel("Open");
        menItm2.setIcon("/images/icons/open_doc.gif");
        menItm2.setMode(Mode.ajax);
        menItm2.setOnclick("alert('hello2');");
        dropDownMenu.getChildren().add(menItm2);

        menuBar.getChildren().add(dropDownMenu);
      
        return menuBar;
    }
}


This way it's done for other dynamic components, creating dummy components with rendered attribute set to false. I by myself at least found out for dropDownMenu and extendedDataTable, I need to do this while creating dynamically!

That's it for now! :)

Sunday 29 May 2011

Downloads

Click on this link to download this
JSF Presentation

Tuesday 24 May 2011

Improve the quality of your code using Find Bugs [configuration and reports in Eclipse]

What is FindBugs?

FindBugs is a static analysis tool that examines your class or JAR files looking for potential problems by matching your bytecodes against a list of bug patterns. With static analysis tools, you can analyze software without actually running the program. Instead the form or structure of the class files are analyzed to determine the program's intent, often using the Visitor pattern.

Please find information below on how to configure and use find bugs in our eclipse.

For more details please refer link. http://findbugs.sourceforge.net/manual/eclipse.html


A:Steps to configure FindBugs in our eclipse

Step-1) From Eclipse help menu open "Install new Software" menu item.









Step-2) Click on Add site and fill following site details and hit ok button.







Step-3) Select "FindBugs" for installation.






.


Step-4) Accept licence conditions – Click finish








B:How to use FindBugs in our eclipse

Step-1) Select java file/package/project and right click to select find bugs. Now it will generate bugs report.









Step-2)Report will be generated like below.











Step-3) To see generated report go to view shown below.










Happy coding :) :) :)

Monday 23 May 2011

Videos

Videos will be added here later.

Your Favorite Technology

Discussion about your Your Favorite Technology is coming soon..
Watch this space for more updates.

General Discussion

I have almost completed the design of the new blog.
I would like to receive a feed back on this.

1) Did you like the Design ? Yes / No
2) Did you like the Menus ? Yes/ No
3) What else we can Include in the Menu?
4) What else you expect to add in the design ?

Please suggest your ideas or answers as comments to this post.

Sunday 22 May 2011

Outing Photos

What you can do here?

 Post your technical queries and get best solutions from the experts.
 Share technical tricks and tips you have used.
 Share new technologies to the group.

Instructions On How to post.

When you have to post any contents in this blog. Follow these steps given below.

1) Individuals given Admin permission can post contents.
2) Login to your blog account and go to Dashboard->posting->New Post.
3) Add your contents by creating a new post.
4) Go to Edit Pages and identify in which category your post can be included and Edit that particular page under the list of pages given. Update the links to your new post where ever it is mentioned.

Rules for posting:

Only technical discussions should be posted here.
No contents related to project or project specific code should be posted.
Technical queries should be in terms of generic language.
Personal abuses are restricted.
All postings are moderated.
Any member violating the rules should be responsible for consequences.


Wednesday 18 May 2011

Richfaces 4 Why and How!!!



It has a latest stable release of Richfaces 4.0.0.Final. Though few features like hotkey and contextmenu not available in this release (planned to release in the release 4.1), it would be better to move the projects which uses Richfaces 3.3.3 and JSF 2 to use Richfaces 4.0 now!

Why Richfaces 4?
First question in mind is “what’s new in it”! Here are the features:
  • Richfaces 4 allows users to take full advantage of all the enhancements in JSF 2.
  • A full set of AJAX enabled components in two libraries
    1. a4j: page centric AJAX controls (a4j:ajax extending the base JSF 2.0 f:ajax tag)
    2. rich: self contained, ready to use components
  • Client-side validation, expanding JSR 303 Bean Validation all the way to the browser.
  •  Advanced queuing to match the high performance requirements of real world enterprise applications.
  • Push component upgrades including Java Messaging Service (JMS) integrations, and various transport mechanisms based on browser support.
  • Own Component Development Kit (CDK).
Look into the demo page to find out new components with source xhtml page and Bean classes. (http://richfaces-showcase.appspot.com/)

How to add Richfaces 4 and start using it!
Must follow the below link for migrating from Richfaces 3.3.3 to Richfaces 4:
I am writing few important hints during startup of migration:
  • Adding Richfaces 4 in maven based project:
Here is a snippet from pom.xml
<properties> 
<!-- for Alhpa versions it was just 'ALPHA2' -->
<org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>
...
</properties>

<dependencyManagement>
<dependencies>
<!-- Ricfaces 4.0.0.Final -->
      <dependency>
                                <groupId>org.richfaces</groupId>
                                <artifactId>richfaces-bom</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                                <scope>import</scope>
                                <type>pom</type>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.ui</groupId>
                                <artifactId>richfaces-components-ui</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.core</groupId>
                                <artifactId>richfaces-core-impl</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                </dependency>
                <dependency>
                                <groupId>org.richfaces.cdk</groupId>
                                <artifactId>annotations</artifactId>
                                <version>${org.richfaces.bom.version}</version>
                                <scope>provided</scope>
      </dependency>
</dependencies>
</dependencyManagement

  • Web.xml
1. RichFaces Filter not needed anymore as RichFaces 4 uses JSF 2 System Events for configuration and requests handling.
2. Remove org.ajax4jsf.VIEW_HANDLERS context parameter. it was needed to configure facelets view handler for JSF 1.2 only.
3. org.richfaces.SKIN changed to org.richfaces.SKIN
  • Design of xhtml page:

The xhtml file should look like this, with proper <h:head> and <h:body> tags.
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"

<h:head>
</h:head>

<h:body>
<ui:composition>
</ui:composition>
</h:body>

</html>
As in Richfaces 3.3.3, used to write tags like <head></head> and <body></body>, now within these tags only JSP components rendered.

  • Dynamic components:
Now to create a component dynamically in Java class we need to use UI component. Html components are not available to use in Java classes.
For e.g. to create <rich:column> dynamically used to do like below:

import org.richfaces.component.html.HtmlColumn;
                                HtmlColumn column = new HtmlColumn();                            

                Now we need to use UI component like below:
import org.richfaces.component.UIColumn;
Application app = FacesContext.getCurrentInstance().getApplication();
UIColumn col = app.createComponent(UIColumn.COMPONENT_TYPE);

I will keep updating further issues and solutions to it!
All the best! :)

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Walgreens Printable Coupons