2

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

<context-param>

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

    <param-value>aristo</param-value>
</context-param>

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

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

汽车.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;
        }
}

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);  
    }  
} 

表.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>

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>

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

4

2 回答 2

13

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

<head> and </head>

进入

<h:head> and </h:head>

有效 :)

于 2012-12-05T12:06:44.383 回答
2

您必须将主题 jar 放在 WebContent/WEB-INF/lib 文件夹中,我不知道您是如何部署项目的,所以您可能也必须将 primefaces jar 放在那里,这样它就会在部署的项目。

jar 就位后,您必须编辑 web.xml 文件以指示您将使用的主题。以 Redmond 为例:

<context-param>

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

    <param-value>redmond</param-value>
</context-param>
于 2012-12-03T18:59:01.810 回答