Wednesday, September 23, 2015

How to create instance from generic type

It’s easy to explain this in code.

  public <T> void myMethod(List<T> list) {
T t;
// t = new T(); // This is basically what you want,
// but will cause compile error.
}

Strictly speaking, you can NOT create instances of type parameters. But you can reach the same goal by using reflection and one more parameter.

  public <T> void myMethod(List<T> list, Class<T>cls) {
T t;
// t = new T(); // This is what you want to do
// but will cause compile error.
try {
t = cls.newInstance(); // use reflection to create instance
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}

This is how to invoke the method.

  List<String> myList = new ArrayList<>();
myMethod(myList,String.class);

Tuesday, September 15, 2015

Asynchronous Spring MVC – Hello World Example

Asynchronous processing is supported since Servlet 3.0. Spring MVC makes asynchronous processing even simpler. Here is a hello world level demo on how to do that using Spring MVC.

Basically there are 2 things need to do:

  1. configure web.xml to turn on async support
  2. return Callable instance  instead of what you mostly return, String/Model/ModelAndView  etc, from a controller’s method.

Let’s suppose you know how to setup a maven managed Spring MVC project in Eclipse. If you don’t , here is the tutorial

0. What you need

JDK 1.7+

Maven 3.2.1

1. Maven  pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.shengwang.demo</groupId>
<artifactId>spring-mvc-asynchronous-basic</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>spring-mvc-asynchronous-basic Maven Webapp</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-framework.version>4.1.6.RELEASE</spring-framework.version>

<!-- Logging -->
<logback.version>1.1.2</logback.version>
<slf4j.version>1.7.7</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-framework.version}</version>
</dependency>

<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<finalName>spring-mvc-asynchronous-basic</finalName>
<!-- Use Java 1.7 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

In maven pom.xml, dependencies like Spring MVC and logging has been added. Also JDK version is set to 1.7


2. configure web.xml to support async


Use <async-supported>true</async-supported> to turn on async support for servlets and filters. Use <dispatcher>ASYNC</dispatcher> for filter-mapping  if any.

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Demo for mvc hello world config</display-name>


<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- turn on async support for servlet -->
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

3. Define java class


First is the service class, just sleep 3 seconds to mimic a slow task.

package com.shengwang.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class HelloService {
Logger logger = LoggerFactory.getLogger(HelloService.class);

public String doSlowWork() {
logger.info("Start slow work");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("finish slow work");
// return "forward:/another"; // forward to another url
return "index"; // return view's name
}
}

The hello service does nothing except sleep a few seconds then return view's name.


The controller look like below.

package com.shengwang.demo;

import java.util.concurrent.Callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class HelloController {
Logger logger = LoggerFactory.getLogger(HelloController.class);

@Autowired
HelloService helloService;

@RequestMapping("/helloAsync")
public Callable<String> sayHelloAsync() {
logger.info("Entering controller");

Callable<String> asyncTask = new Callable<String>() {

@Override
public String call() throws Exception {
return helloService.doSlowWork();
}
};

logger.info("Leaving controller");
return asyncTask;
}
}

The method sayHelloAsync return a Callable instance.


4. Configure Spring MVC


Compare to the basic hello world Spring mvc configuration in tutorial on “How to setup Spring MVC project with maven in Eclipse”, the difference is the task executor setup for async tasks.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="com.shengwang.demo" />

<!-- ================================== -->
<!-- 0. Set up task executor for async -->
<!-- ================================== -->
<mvc:annotation-driven>
<mvc:async-support default-timeout="30000" task-executor="taskExecutor"/>
</mvc:annotation-driven>
<!-- modify the parameters of thread pool -->
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5"/>
<property name="maxPoolSize" value="50"/>
<property name="queueCapacity" value="10"/>
<property name="keepAliveSeconds" value="120"/>
</bean>

<!-- ================================== -->
<!-- 1. mapping static resources -->
<!-- ================================== -->
<mvc:resources location="/static-resources/css/" mapping="/css/**" cache-period="3600"/>
<mvc:resources location="/static-resources/img/" mapping="/img/**" cache-period="3600"/>
<mvc:resources location="/static-resources/js/" mapping="/js/**" cache-period="3600"/>


<!-- ================================== -->
<!-- 2. view resolver for JSP -->
<!-- ================================== -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

In real project, the task executor must be explicitly setup instead of using the default SimpleAsyncTaskExecutor, which can not be used in production. As Spring document says:



It is highly recommended to configure this property since by default Spring MVC uses SimpleAsyncTaskExecutor.


5. Run the async web app


Run the project and access http://localhost:8080/spring-mvc-asynchronous-basic/helloAsync, the log from console looks like below


image


The controller thread(http-bio-8080-exec-7) exits immediately, but another MVC mangaged thread(taskExecutor-1) takes 3 seconds to finish the slow work. Although the controller thread finishes very fast, the connection keeps open, browser doesn’t get response until 3 seconds later, all threads finish.

Monday, September 14, 2015

How to setup Spring MVC project with maven in Eclipse

There article shows how to create a spring MVC project with maven in Eclipse. The eclipse comes with an internal maven-archetype-webapp for webapps, but is somehow a little bit out of date. The project created by that needs some extra work to make it workable.

In this demo a maven managed Spring MVC helloworld  webapp is created in Eclipse. This demo doesn’t try to show how to use Spring MVC, but focus on how to set up the development environment in Eclipse.

0. What you need

  • JDK 1.7 +
  • Eclipse IDE for Jave EE (version 4.4 Luna)
  • Maven 3.2.1

1. Create a maven project in Eclipse

Create a new maven project.

image

Make sure choose the archetype maven-archetype-webapp

image

Then next until finish. You may notice that the new created project has errors. In Eclipse IDE, it has red crosses like below.

image

Don’t worry about that, we will deal with the errors step by step until it becomes a runnable one.

2. Configure the project

There are several things need to be changed for the eclipse created project.

2.1 Configure maven pom.xml

Since this is a maven managed project, the JDK version need to be set in pom.xml, not in Eclipse. The dependency Spring MVC is also added to pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.shengwang.demo</groupId>
<artifactId>spring-mvc-helloworld</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>spring-mvc-helloworld Maven Webapp</name>
<url>http://maven.apache.org</url>

<dependencies>
<!-- Use Spring MVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>

<build>
<finalName>spring-mvc-helloworld</finalName>
<!-- Use Java 1.7 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

After pom.xml saved and use Alt-F5 to update the maven project, Eclipse still complain about an error for the project like below.


It’s a error about “javax.servlet.http.HttpServlet” was not found on the Java Build Path.


image


Don’t worry, The class should be provided by the Servlet containers, such as Tomcat, we need to do more configuration for the running environment of the project. So let deal with it now.


2.2 Configure Dynamic Web Module for project


It’s a little bit tricky to change Dynamic Web Module version in Eclipse, first you need to unset the default old version 2.3 in project facets, then set it again with new version 3.0 or higher. Direct change the version number will cause an error in Eclipse like this.


image


So let do it in the correct way, unset the old one, then set it again with new version.


Right click on the project name – > choose properties. Uncheck the Dynamic Web Module 2.3, then hit OK to confirm.


image


Again, right click on the project name – > choose properties. Check the Dynamic Web Module 3.0, Also set specify a runtime server for the our helloworld webapp.


image


Now our helloworld Spring MVC web app don’t have any errors in Eclipse.


image


2.3 Add java directory


The wizard created project don’t have directory for java code, we need to create this directory by hand. Like other maven project,  /src/main/java is the folder need to be created to put the java code.

Now if you continue to proceed this tutorial, configure web.xml and dispatcher-servlet.xml, you will end up with a spring mvc project with configuration in XML file. If you prefer to have a spring mvc project with java-based configuration, you can skip the rest of this article and jump to another tuorial on Java-based Spring mvc configuration - without Spring security


2.4  basic web.xml configuration


Change the default /src/main/webapp/WEB-INF/web.xml to the basic configuration below .

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<display-name>Demo for mvc hello world config</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- specify location of spring config, don't use default --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

The version="3.0" means using servlet version 3.0. the Spring configuration file is name "dispatcher-servlet.xml" in classpath, usually means /src/main/resources/dispatcher-servlet.xml. Just remember don't use the default value for contextconfigLocation, which will be /src/main/webapp/WEB-INF by default, to avoid hitting rocks when doing integration test later.


2.5 basic spring configuration


Add a new file /src/main/resources/dispatcher-servlet.xml. In the same directory as web.xml, the basic spring configuration looks like below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package="com.shengwang.demo" />

<mvc:annotation-driven/>

<!-- ================================== -->
<!-- 1. mapping static resources -->
<!-- ================================== -->
<mvc:resources location="/static-resources/css/" mapping="/css/**" cache-period="3600"/>
<mvc:resources location="/static-resources/img/" mapping="/img/**" cache-period="3600"/>
<mvc:resources location="/static-resources/js/" mapping="/js/**" cache-period="3600"/>


<!-- ================================== -->
<!-- 2. view resolver for JSP -->
<!-- ================================== -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

Change the base package to your own. In this demo it’s com.shengwang.demo. The static resources directory can be any directories relative to /src/main/webapp


Now the project looks like this.

image

Since this article focuses on how to setup project and development environment for spring mvc with maven in Eclipse. The spring mvc coding part, such controllers and business logic are omitted. Now your maven managed Spring MVC project is setup in Eclipse, ready for some java code and run.


Happy coding!

Friday, September 11, 2015

Using log MDC in multi-thread - Hello World example

The slf4j has MDC which will  delegate to underlying logging system's MDC implementation.  The most popular logging systems are log4j and logback. They both support MDC. So the most common way to use MDC (or logging system) is through slf4j API. In this demo, logback is used as underline logging system.

What can MDC(Mapped Diagnostic Context) do for me?

MDC is a map like structure, it can save information you want to output to the log, so you don’t need add that information to every logger.info(…) as parameter. For example, in an web application, you want every log output contain http request source IP. The IP string don’t need to be added to every logger call , or passed back and forth between controller and service layers. You should save that IP in the MDC, and use %X{IP} in log configuration to add that value to every line of your log output.

BTW, MDC is thread-safe. No worrying for concurrency.

MDC in multi-thread environment

In multi-thread environment, if the child is create with the basic Thread + Runnable way, the child thread will automatically inherit parent’s MDC. But if  using executor as thread management. The MDC inheritance is not  warranted, as the logback document said:

A copy of the mapped diagnostic context can not always be inherited by worker threads from the initiating thread. This is the case when java.util.concurrent.Executors is used for thread management.

In this hello world demo, there are 2 threads. The main thread will create a child thread using package java.utils.concurrent instead of the old style Thread way to show how to keep MDC context inheritance.

0. What you need

  • JDK 1.7
  • Maven 3.2.1
  • SLF4J 1.7.7
  • Logback 1.1.2

1. Configure the maven pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.shengwang.demo</groupId>
<artifactId>slf4j-logback-mdc</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>slf4j-logback-mdc</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

Add dependencies for slf4j and logback in pom.xml

2. Define the Java class


There are 2 classes in this demo. First the Child.java.

package com.shengwang.demo;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class Child implements Runnable {
private Logger logger = LoggerFactory.getLogger(Child.class);

// contextMap is set when new Child() is called
private Map<String,String> contextMap = MDC.getCopyOfContextMap();

public void run() {
MDC.setContextMap(contextMap); // set contextMap when thread start
logger.info("Running in the child thread");
}
}

The Child.java is very simple, just implements the Runnable interface. One thing need to mention is how the MDC context is passed from parent thread to child thread. The Child object instance is created in parent thread, when new Child() is call immediately before executor create new thread. So the parent’s MDC context is duplicated to a variable called contextMap, then set back to MDC in child thread at the begin of run() method.


The Parent.java with main()

package com.shengwang.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class Parent {
private Logger logger = LoggerFactory.getLogger(Parent.class);
private ExecutorService executorService = Executors.newCachedThreadPool();

public Parent() {
// Mimic Web app, save common info in MDC
MDC.put("IP", "192.168.1.1");
}

public void runMultiThreadByExecutor() throws InterruptedException {
logger.info("Before start child thread");

executorService.submit(new Child());
logger.info("After start child thread");

executorService.shutdown();
executorService.awaitTermination(1, TimeUnit.SECONDS);
logger.info("ExecutorService is over");
}

public static void main(String[] args) throws InterruptedException {
Parent parent = new Parent();
parent.runMultiThreadByExecutor(); //MDC OK
}
}

In Parent class, ExecutorService from java.util.concurrency package is used to create a new child thread.  In parent’s constructor , String “192.168.1.1” has been put in MDC with key “IP”. The key/value can be any String. MDC works just like an ordinary Map<String,String>. It will be used in logback’s patten layout shown below.


3. Configure logging system to use values in MDC


In logback, the value can be get using "%X{KEY}" in appender’s pattern. So in this demo, it should be "%X{IP}". Here is the logback.xml for this demo.

<configuration>
<!-- to screen -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- screen output pattern -->
<pattern>%d{HH:mm:ss.SSS} [%X{IP}] [%thread] %-5level [%F:%L] - %msg %n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

Everything is almost done now. Let's review the directory structure for our maven project.


image


4. Run the demo


image


As we can see from the output, the information in MDC has been added to all output lines from both parent and child threads.

Thursday, September 10, 2015

How to invoke an object’s private method in Java

The private methods are designed not accessible from outside. But sometimes we want to call it directly, for example in unit testing. Java actually provides ways to call private method with the help of reflection, java.lang.reflect.Method

PowerMock, a widely used mock library also provide helper class to make it easy  in JUnit test cases. (PowerMock indeed wraps the reflection for you)

In this demo, there is a HellowWorld class under test.

package com.shengwang.demo;

public class HelloWorld {

private String sayHello(String name) {
return = "Dear " + name;
}
}

The private method sayHello will be tested in JUnit test case.


1. Method-1 Using reflection directly


  1. 1 What you need

  • JDK  (no third party library is required )

  1.2 Invoke private method in testcase

package com.shengwang.demo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;


public class HelloWorldByReflectionTest {

@Test
public void testPrivateMethod() {
try {
HelloWorld helloWorld = new HelloWorld();
Method method;
// get reflected method
method = HelloWorld.class.getDeclaredMethod("sayHello",new Class[] { String.class });
// change accessiblity
method.setAccessible(true);
// invoke the method
assertEquals("Dear Tom", method.invoke(helloWorld, "Tom"));
} catch (NoSuchMethodException | SecurityException |
IllegalAccessException | IllegalArgumentException |
InvocationTargetException e) {
e.printStackTrace();
fail();
}
}
}

2. Method-2 Using PowerMock


  2. 1 What you need

  • Mockito
  • PowerMock

PowerMock usually need to work with either Mockito or EasyMock, you can choose anyone. In this demo Mockito is used.

2.2 Add Maven dependencies


Add dependencies to the maven pom.xml

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>

  2.3 Invoke private method in testcase

package com.shengwang.demo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.powermock.reflect.Whitebox.invokeMethod;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ HelloWorld.class })
public class HelloWorldByPowerMockTest {
@Test
public void testPrivateMethod() {
String result;
try {
HelloWorld helloWorld = new HelloWorld();
result = invokeMethod(helloWorld, "sayHello", "Tom");
assertEquals("Dear Tom", result);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}

The org.powermock.reflect.Whitebox.invokeMethod from PowerMock is imported at the beginning and used to invoke private method.

Tuesday, September 1, 2015

HTML Tags for JavaServer Faces (JSF)

The HTML Tags in for JSF is mostly used tags when writing JSF page. They are listed here for quick reference. The table comes from oracle JEE7 documents here.

Tag

Functions

Rendered As

Appearance

h:column

Represents a column of data in a data component

A column of data in an HTML table

A column in a table

h:commandButton

Submits a form to the application

An HTML <input type=value> element for which the type value can be"submit", "reset", or "image"

A button

h:commandLink

Links to another page or location on a page

An HTML <a href> element

A link

h:dataTable

Represents a data wrapper

An HTML <table> element

A table that can be updated dynamically

h:form

Represents an input form (inner tags of the form receive the data that will be submitted with the form)

An HTML <form> element

No appearance

h:graphicImage

Displays an image

An HTML <img> element

An image

h:inputFile

Allows a user to upload a file

An HTML <input type="file"> element

A field with a Browse... button

h:inputHidden

Allows a page author to include a hidden variable in a page

An HTML <input type="hidden">element

No appearance

h:inputSecret

Allows a user to input a string without the actual string appearing in the field

An HTML <input type="password">element

A field that displays a row of characters instead of the actual string entered

h:inputText

Allows a user to input a string

An HTML <input type="text"> element

A field

h:inputTextarea

Allows a user to enter a multiline string

An HTML <textarea> element

A multirow field

h:message

Displays a localized message

An HTML <span> tag if styles are used

A text string

h:messages

Displays localized messages

A set of HTML <span> tags if styles are used

A text string

h:outputFormat

Displays a formatted message

Plain text

Plain text

h:outputLabel

Displays a nested component as a label for a specified input field

An HTML <label> element

Plain text

h:outputLink

Links to another page or location on a page without generating an action event

An HTML <a> element

A link

h:outputText

Displays a line of text

Plain text

Plain text

h:panelGrid

Displays a table

An HTML <table> element with <tr>and <td> elements

A table

h:panelGroup

Groups a set of components under one parent

A HTML <div> or <span> element

A row in a table

h:selectBooleanCheckbox

Allows a user to change the value of a Boolean choice

An HTML <input type="checkbox">element

A check box

h:selectManyCheckbox

Displays a set of check boxes from which the user can select multiple values

A set of HTML <input> elements of type checkbox

A group of check boxes

h:selectManyListbox

Allows a user to select multiple items from a set of items all displayed at once

An HTML <select> element

A box

h:selectManyMenu

Allows a user to select multiple items from a set of items

An HTML <select> element

A menu

h:selectOneListbox

Allows a user to select one item from a set of items all displayed at once

An HTML <select> element

A box

h:selectOneMenu

Allows a user to select one item from a set of items

An HTML <select> element

A menu

h:selectOneRadio

Allows a user to select one item from a set of items

An HTML <input type="radio">element

A group of options

Powered by Blogger.

About The Author

My Photo
Has been a senior software developer, project manager for 10+ years. Dedicate himself to Alcatel-Lucent and China Telecom for delivering software solutions.

Pages

Unordered List