Tuesday, August 21, 2007

JSF Custom components

This article will concentrate on:
  1. When to create JSF component ?
  2. How to create JSF component?
  3. Simple custom component
First: When to create JSF component?
Before jumping into custom JSF component development, you should know the purpose of creating JSF custom components.
you decide to create this component
  1. when you want to visible components such as input/output fields.
  2. when you want to handle things like basic validation and/or data conversion.
Second: How to create JSF component?
The general term "JSF UI Component" refers to a collection of the following:
  • UIComponent Class:A Java class derived from either the UIComponentBase or extended from an existing JSF UIComponent such as outputText. This is the actual Java class representing the core logic of the component.
  • Renderer Class:This is a class that only contains code to render a UIComponent. Rendering classes can provide different renderings for a UI Component. For such as either a button or hyperlink for the UICommand component.
  • UI Component Tag Class:This is a JSP tag handler class that allows the UI Component to be used in a JSP.
  • Tag Library Descriptor File:This is a standard J2EE JSP tag library descriptor (tld) file which associates the tag handler class with a usable tag in a JSP page.
  • Associated helper classes:These include a collection of standard (included in JSF RI) or custom helper classes such as Converters, Validators, ActionListeners etc.
Third:Simple custom component
Step 1: Creating a UIComponent Class
UIComponent will extend the UIComponentBase abstract class.We could have also based our new UI Component class on the concrete UIOutput base class which is basically the same as the UIComponentBase with the exception that it has a "value" attribute.

package com.mufic.mufix.component.page;


import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;

import java.io.IOException;
import javax.faces.context.ResponseWriter;

public class UIComp extends UIComponentBase {

public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();

String title = (String)getAttributes().get("title");
writer.startElement("h3", this);
if(title != null)
writer.writeText(title, "title");

else
writer.writeText("Hello from a MUFIX custom JSF UI Component!", null);
writer.endElement("h3");
writer.startElement("p", this);

writer.endElement("p");
}

public String getFamily() {
return "MUFIX";
}
}


As you can see, this custom UI Component renders a formatted Hello MUFIX message using encodeBegin() method.


Step 2: Registering the custom UI Component in Faces-config.xml
We'll add a required entry for our custom component in the faces-config.xml file. The syntax for adding our custom UI component is:

Step 3. Building a Custom JSP Tag Library
we need a custom tag library comprised of a tag library descriptor file (TLD) along with references to taghandlers classes.

Building the Tag Handler

JSP taghandler class is derived from javax.faces.webapp.UIComponentTag. It's main purpose is to:
  1. Associate a JSP callable tag (handler class) with the UI Component.
  2. Associate a separate renderer class (if needed) to the UI Component.
  3. Set the properties from the submitted tag attribute values to the UI Component.
Here is the source code for our tag handler class

package com.mufic.mufix.component.page;

import javax.faces.application.Application;
import javax.faces.webapp.UIComponentTag;
import javax.faces.component.UIComponent;
import javax.faces.el.ValueBinding;
import javax.faces.context.FacesContext;

public class FacesTag extends UIComponentTag {
// Declare a bean property for the hellomsg attribute.
private String title = null;


// Associate the renderer and component type.
public String getComponentType() {
return "com.mufic.mufix.component.page";
}
public String getRendererType() {
return null;
}


protected void setProperties(UIComponent component) {
super.setProperties(component);

if (title != null) {
component.getAttributes().put("title", title);
}
}
public void release() {
super.release();
setTitle(null);
}
public void setTitle(String title) {
this.title = title;
}
}

The first thing to note is the "title" bean property of type String along with its associated getter and setter methods at the bottom of the class. The title bean property, "title", is also an attribute in the JSP tag. title="title">


Finally: To use the page tag, we simply place it into the body of the JSP and set an optional "title" attribute.
<%@ taglib uri="http://mufic.com/component" prefix="mufix"%>

Rreferences :
  1. JSF IN ACTION
  2. http://www.theserverside.com/tt/articles/article.tss?l=BuildingCustomJSF
elTanahy

Saturday, July 14, 2007

What is JavaServer Faces?

In terms of the four layers of a RAD tool, JavaServer Faces defines three of them:
  1. Component architecture
  2. Standard set of UI widgets
  3. Application infrastructure.
JSF’s component architecture
JSF’s component architecture defines a common way to build UI widgets.This architecture enables standard JSF UI widgets (buttons, hyperlinks, checkboxes,text fields, and so on)
Components are event oriented, so JSF allows you to process client-generatedevents (for instance, changing the value of a text box or clicking on a button). Because web-based applications, unlike their desktop cousins, must often appease multiple clients (such as desktop browsers, cell phones, and PDAs), JSF has a powerful architecture for displaying components in different ways. It also has extensible facilities for validating input (the length of a field, for example) and converting objects to and from strings for display.
Faces can also automatically keep your UI components in synch with Java objects that collect user input values and respond to events, which are called backing beans.
In addition, it has a powerful navigation system and full support for multiple languages. These features make up JSF’s application infrastructure— basic building blocks necessary for any new system.
JavaServer Faces defines the underpinnings for tool support, but the implementation of specific tools is left to vendors, as is the custom with Java. You have a choice of tools from industry leaders that allow you to visually lay out a web UI in a way that’s quite familiar to users of RAD development tools such as Visual Studio.NET.

Widget Toolkit (SWT)
JSF runs on the server. As such, a Faces application will run in a standard Java web container like Apache Tomcat [ASF, Tomcat], Oracle Application Server [Oracle, AS], or IBM WebSphere Application Server [IBM, WAS], and display HTML or some other markup to the client. If you click a button in a Swing application, it will fire an event that you can handle directly in the code that resides on the desktop. In contrast, web browsers don’t know anything about JSF components or events; they just know how to display HTML

Rreferences :
  1. JSF IN ACTION
elTanahy

Wednesday, July 4, 2007

Graduation Day

Today it is my graduation day, I have graduated after 4 years studying in MUFIC.
I am very happy because i won't study stupid subjects and watchdog project win a admiration of all people who examined us

This photo was took to our project team with LPC2294 schematic.
from left to right (Me - Isalm Nigm - Abbas - Mohammed Awaad - Amr Eissa).

Sunday, June 10, 2007

DHCP Attacks

DHCP attacks centre on two methods
  1. Denial of service
  2. DHCP impersonation
Denial of Service Attacks
  • Address starvation with MAC flooding
Attack
  1. DHCP servers have a limited number of addresses that they can give out.
  2. DHCP scopes commonly have less than 200 addresses that they give out to hosts (the rest of the space is often reserved for static IP devices, such as servers, printers, etc).
  3. An attacker has to do is send DHCP requests using random MAC addresses.
  4. It keeps sending requests until the DHCP server stops responding. Of course, the DHCP has no idea what's going on, so it keeps responding to all the requests it sees coming in.
Mitigation
  1. Mitigation of this attack is very simple with a Cisco switch.
  2. Using a feature called port security.
  3. Port security does is limit the number of MAC addresses a client machine can use.
  4. Port security is supported on Cisco 2950's and above. The switch clears the MAC address associated with a port when the link goes down

Friday, June 8, 2007

Bye Bye Exams

I 've just finished my exams and i did not return to CPP
I will start working in my graduation project
you can know every thing about my project Watchdog

Monday, June 4, 2007

Very Lucky

I am very happy to start my posts at this day.
This Day:
  1. My loyal friend Abbas told me that Mr:Nikesh Arora (President, EMEA Operations & Vice President, Google Inc) visits egypt and decide to open a new branch in egypt
  2. When I and Abbas know that we wish to work in this big company Allah help us
  3. I start to study natural language processing it has a very big relation with Google engine
But i have another bad news i am very annoyed because i have an exam and i can't study or understand any thing about this course , but i decide to execute our faculty protocol CPP (Copy Paste Protocol).

CPP is not Internet Protocol, it is a protocol for my faculty students.
CPP Steps:
When you don't know any thing about the course and have an exam you must do
  1. search for Sheets solutions and pervious exams.
  2. Copy solutions on your mind.
  3. Paste it in exam.