jsf - Primefaces 主题配置

标签 jsf jsf-2 primefaces

我正在研究 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);  
    }  
} 

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>

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

最佳答案

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

<head> and </head>

进入

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

成功了:)

关于jsf - Primefaces 主题配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13689731/

相关文章:

java - JSF-2 应用程序中的服务器端计时器

jsf-2 - 文件下载后更新组件

ajax - 无法捕获 JSF 2 应用程序上的 ajax 错误

javascript - 如何在p :message of primefaces中打印javascript警报消息

javascript - jQuery 时钟在 jsf 1.2 中不工作

jsf - <h :message> unable to find component in <ui:repeat>

java - Cookie 未被读取

java - <f :convertNumber> use the right number separator when using patterns to format currency?

css - 在右边放置一个命令按钮

primefaces - 第二次单击primefaces下载时读取错误