Mehmet Ethem SULAN :: PrimeFaces :: Setting up PrimeFaces Eclipse Indigo configuration

Mac ile PrimeFaces ve Eclipse Indigo ayarlarını yapmaya çalıştım.

1.PrimeFaces.jar dosyasını WEB-INF –> lib altına atıp sağ tıklayıp Add to build path demeniz lazım.
2. web.xml içinde ne varsa silin ve aşağıdakini yapıştırın.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>Primefaces</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
 <context-param>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>server</param-value>
 </context-param>
 <context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
 </context-param>
 <context-param>
  <param-name>com.sun.faces.expressionFactory</param-name>
  <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
 </context-param>
 <context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>
  <param-value>Development</param-value>
 </context-param>
 <context-param>
  <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
  <param-value>true</param-value>
 </context-param>
</web-app>

3. PrimeFaces kullanabilmek için

xmlns:p="http://primefaces.org/ui"

satırı aşağıdaki gibi eklemeniz lazım.

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

4.Ben index.jsp sayfasını sildim ve projeyi index.xhtml sayfasını sağ tıklayıp Debug As –> Debug on server seçeneğini tıklamanız yeterlidir.
Birinci formda “ajax ile inputu yaz” buttonuna tıklandığında ajax ile girilen değerleri h:outputLabel e yazıyor.
Ikinci formda ise girilen değerleri hello.xhtml sayfasında gösteriyor.


index.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<title>Title</title>
</h:head>
<h:body>

<h1>Form 1</h1>
	<h:form>
		<p:panel>
			<h:panelGrid columns="2">
				<h:inputText value="#{test.name}"></h:inputText>
				<h:outputLabel id="lblName" value="#{test.name}"></h:outputLabel>
				
				<h:inputText value="#{test.address}"></h:inputText>
				<h:outputLabel id="lblAddress" value="#{test.address}"></h:outputLabel>
		
				<p:commandButton value="Ajax Ile Inputları Yaz" update="lblName,lblAddress"/>
			</h:panelGrid>
		</p:panel>
	</h:form>
<h1>Form 2</h1>
	<h:form>
		<p:panel>
			<h:panelGrid columns="1">
					<h:inputText value="#{test.name}"></h:inputText>
					<h:inputText value="#{test.address}"></h:inputText>
					<h:commandButton action="#{test.getPageName()}" value="Open Hello Page"></h:commandButton>
			</h:panelGrid>
		</p:panel>
	</h:form>
</h:body>
</html>

hello.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<h:head>
	<title>Hello Page</title>
</h:head>

<h:body>
	<h:form>
		<h:outputLabel value="#{test.name}"></h:outputLabel><br/>
		<h:outputLabel value="#{test.address}"></h:outputLabel>
	</h:form>

</h:body>
</html>

Test.java

package com.test;

public class Test {
	
	private String name;
	private String address;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	

	public String getPageName(){
		return "hello";
	}
}

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">
	<managed-bean>
		<managed-bean-name>test</managed-bean-name>
		<managed-bean-class>com.test.Test</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<navigation-rule>
		<display-name>index.xhtml</display-name>
		<from-view-id>/index.xhtml</from-view-id>
		<navigation-case>
			<from-outcome>hello</from-outcome>
			<to-view-id>/hello.xhtml</to-view-id>
		</navigation-case>
	</navigation-rule>

</faces-config>

Download PrimeFacesHelloWorld.zip

Comments

There are 3 comments for this post.

  1. aziz on Nisan 30, 2012 1:02 pm

    Türkçe karakterleri nasıl tanıtabiliriz?

  2. Aydın on Haziran 25, 2012 10:28 am

    Merhaba Ethem bey,

    Sizden widget konusuyla ilgili bir yardım isteyeceğim, mümkünse eğer bana eposta adresinizi verebilir misiniz?
    Teşekkürler…

  3. Ahmet B. on Eylül 18, 2012 3:58 pm

    @Aziz
    Tüm karakterleri tanıtabilirsin.Bunun için aşşağıda ki gibi bir servlet filter yazıp web.xml de tanımlaman yeterli olacaktır.Arapça, çince ,japonca vs tüm karakterleri filtreleyebilirsin.

    import java.io.IOException;

    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;

    public class CharacterEncodingFilter implements Filter {

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp,
    FilterChain filterChain) throws IOException, ServletException {
    req.setCharacterEncoding(“UTF-8”);
    resp.setCharacterEncoding(“UTF-8”);

    filterChain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }
    }

Write a Comment

Let me know what you think?