Jsf p:按钮示例没有';t读取示例中传递的参数

Jsf p:按钮示例没有';t读取示例中传递的参数,jsf,primefaces,Jsf,Primefaces,p:button将参数传递到下一页的在线示例有效 但是,当我在本地运行同一个示例时,会看到输出网页: You've been redirected to this bookmarkable page with button.ViewParameter you've passed is "" 未读取传递的参数 这是我的代码: pom.xml: <!DOCTYPE xml> <project xmlns="https://maven.apache.org/xsd"

p:button
将参数传递到下一页的在线示例有效

但是,当我在本地运行同一个示例时,会看到输出网页:

You've been redirected to this bookmarkable page with button.ViewParameter you've passed is "" 
未读取传递的参数

这是我的代码:

pom.xml:

<!DOCTYPE xml>
<project xmlns="https://maven.apache.org/xsd" 
    xmlns:xsi="http://www.w3.org/TR/xmlschema-1"
    xsi:schemaLocation="https://maven.apache.org/xsd 
    https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mkyong.core</groupId>
    <artifactId>primefaces</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>primefaces Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>Prime Repo</name>
            <url>http://repository.primefaces.org</url>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>8.0.RC2</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.20</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.20</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>2.0.SP1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.10</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
目录:

按钮可以工作,但传递的参数“productId”未被读取。

链接上的示例没有POM或web.xml示例,我必须自己创建它们,没有primefaces经验。

您的productDetail.xhtml缺少一个重要部分。如果您在github中查看的完整源代码,您将看到页面中缺少的一段重要代码:

<f:metadata>
    <f:viewParam name="productId" value="#{productDetailView.productId}" />
</f:metadata> 

这就是在url中提取参数并将其放入对象的方法

另请参见


您的意思是您的版本会导致此错误?showcase工作区参数的读取方式与exampleOk不同,但请在不使用lombok的情况下尝试。不是说它可以让它工作,而是它的依赖性减少了(而且只有两行代码将被添加),我现在在没有lombok的情况下重新尝试了,结果是一样的。顺便说一句,在运行JavaEE服务器(而不是servlet引擎)时,大多数pom都不需要,并且您的web.xml可以更干净地与新的jsf版本(如2.2及以上)配合使用为什么primefaces示例没有报告所有代码?(我现在觉得)我没有“/WEB-INF/template.xhtml”不知道。。。showcase有点“动态”(这很酷,因为执行内容的实际来源是您看到的),但可能是元数据需要位于html中的特定位置,因此(不幸的是)不可见。而且不需要模板。一切都可以不做。在完整的应用程序和这样的展示网站中,这是一件(很棒的)事情应用xhtml后,我得到一个错误:productDetail.xhtml@13,64 value=“#{editor.productId}”:目标不可访问,标识符[editor]解析为Null,在web中。xml不存在id。
<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">

    <h:head>
    </h:head>

    <h:body>
        <p:button outcome="productDetail" value="Bookmark" icon="pi pi-star" style="margin-right:20px;">
            <f:param name="productId" value="10" />
        </p:button>

        <p:button outcome="productDetail" value="With Icon" icon="pi pi-star" style="margin-right:20px;">
            <f:param name="productId" value="20" />
        </p:button>

        <p:button outcome="productDetail" icon="pi pi-star" style="margin-right:20px;" title="Icon Only">
            <f:param name="productId" value="30" />
        </p:button>

        <p:button outcome="productDetail" value="Bookmark" icon="pi pi-star" disabled="true" style="margin-right:20px;">
            <f:param name="productId" value="40" />
        </p:button>
    </h:body>
</html>
<p>You've been redirected to this bookmarkable page with button.
        ViewParameter you've passed is <strong>"#{editor.productId}"</strong>
</p>
package com.jsf.editor;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

import lombok.Data;

@Data
@Named("editor")
@RequestScoped
public class EditorBean {

    private String productId;

}
<f:metadata>
    <f:viewParam name="productId" value="#{productDetailView.productId}" />
</f:metadata>