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中提取参数并将其放入对象的方法
另请参见
<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>