首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >素数面主题配置

素数面主题配置
EN

Stack Overflow用户
提问于 2012-12-03 18:51:32
回答 2查看 16.4K关注 0票数 2

我正在学习primefaces用户指南上的Primefaces主题。3.pdf在帕格。457您可以读到:“一旦下载了主题,配置PrimeFaces来使用它

代码语言:javascript
复制
<context-param>

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

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

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

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

Car.java

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-03 18:59:01

您必须将主题jar放在WebContent/WEB/lib文件夹中,我不知道您是如何部署该项目的,因此您也必须将primefaces放在那里,以便将其放在已部署的项目中。

在jar就位之后,您必须编辑您的web.xml文件,以指示您将使用哪个主题。雷德蒙德的一个例子是:

代码语言:javascript
复制
<context-param>

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

    <param-value>redmond</param-value>
</context-param>
票数 2
EN

Stack Overflow用户

发布于 2012-12-05 12:06:44

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

代码语言:javascript
复制
<head> and </head>

转到

代码语言:javascript
复制
<h:head> and </h:head>

它奏效了:)

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13689731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档