Primefaces主题配置

Ger*_*llo 2 jsf primefaces jsf-2

我正在研究Primefaces用户指南中的primefaces主题. https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/primefaces/primefaces_users_guide_3_3.pdf at pag.457您可以阅读:"下载主题后,配置PrimeFaces以使用它

<context-param>

    <param-name>primefaces.THEME</param-name>

    <param-value>aristo</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

我应该把它放在哪里?进入我正在开发的网页文件?我选择了Redmond主题的jar文件并将其导入我的Eclipse Dynamic Web项目,但我没有看到任何改进.

我测试的Primefaces示例是:https://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml

Car.java

import java.util.Date;

public class Car {

        private String model;
        private int year;
        private String manufacturer;
        private String color;

        public Car(String model, int year, String manufacturer, String color) {
                this.model = model;
                this.year = year;
                this.manufacturer = manufacturer;
                this.color = color;
        }

        public String getModel() {
                return model;
        }

        public void setModel(String model) {
                this.model = model;
        }

        public int getYear() {
                return year;
        }

        public void setYear(int year) {
                this.year = year;
        }

        public String getManufacturer() {
                return manufacturer;
        }

        public void setManufacturer(String manufacturer) {
                this.manufacturer = manufacturer;
        }

        public String getColor() {
                return color;
        }

        public void setColor(String color) {
                this.color = color;
        }
}
Run Code Online (Sandbox Code Playgroud)

TableBean.java

package classi;

import java.io.Serializable;  
import java.util.ArrayList;  
import java.util.List;  
import java.util.UUID;  
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;


@ManagedBean(name="tableBean")
@SessionScoped
public class TableBean implements Serializable
{  
    private final static String[] colors;  

    private final static String[] manufacturers;  

    private List<Car> carsSmall;  
    static {  
        colors = new String[10];  
        colors[0] = "Black";  
        colors[1] = "White";  
        colors[2] = "Green";  
        colors[3] = "Red";  
        colors[4] = "Blue";  
        colors[5] = "Orange";  
        colors[6] = "Silver";  
        colors[7] = "Yellow";  
        colors[8] = "Brown";  
        colors[9] = "Maroon";  

        manufacturers = new String[10];  
        manufacturers[0] = "Mercedes";  
        manufacturers[1] = "BMW";  
        manufacturers[2] = "Volvo";  
        manufacturers[3] = "Audi";  
        manufacturers[4] = "Renault";  
        manufacturers[5] = "Opel";  
        manufacturers[6] = "Volkswagen";  
        manufacturers[7] = "Chrysler";  
        manufacturers[8] = "Ferrari";  
        manufacturers[9] = "Ford";  
    }  



    public TableBean() {  
        carsSmall = new ArrayList<Car>();  

        populateRandomCars(carsSmall, 9);  
    }  

    private void populateRandomCars(List<Car> list, int size) {  
        for(int i = 0 ; i < size ; i++)  
            list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));  
    }  

    public List<Car> getCarsSmall() {  
        return carsSmall;  
    }  

    private int getRandomYear() {  
        return (int) (Math.random() * 50 + 1960);  
    }  

    private String getRandomColor() {  
        return colors[(int) (Math.random() * 10)];  
    }  

    private String getRandomManufacturer() {  
        return manufacturers[(int) (Math.random() * 10)];  
    }  

    private String getRandomModel() {  
        return UUID.randomUUID().toString().substring(0, 8);  
    }  
} 
Run Code Online (Sandbox Code Playgroud)

table.xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:form>  
    <p:dataTable var="car" value="#{tableBean.carsSmall}">  
        <p:column headerText="Model">  
            <h:outputText value="#{car.model}" />  
        </p:column>  

        <p:column headerText="Year">  
            <h:outputText value="#{car.year}" />  
        </p:column>  

        <p:column headerText="Manufacturer">  
            <h:outputText value="#{car.manufacturer}" />  
        </p:column>  

        <p:column headerText="Color">  
            <h:outputText value="#{car.color}" />  
        </p:column>  
    </p:dataTable>  
</h:form>  
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

web.xml中

<?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_DataTable</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>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>redmond</param-value>
  </context-param>
  <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)

项目结构的屏幕截图 http://i.imgur.com/tgrMH.png

Ger*_*llo 13

一位用户告诉我,我必须编辑

<head> and </head>
Run Code Online (Sandbox Code Playgroud)

<h:head> and </h:head>
Run Code Online (Sandbox Code Playgroud)

有效 :)