The online example of a p:button passing a parameter to next page works
https://www.primefaces.org/showcase/ui/button/button.xhtml
But when I run this same example locally gives at me the output web page:
You've been redirected to this bookmarkable page with button.ViewParameter you've passed is ""
The passed parameter is not read.
This is my code:
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>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-app xmlns:xsi="http://www.w3.org/TR/xmlschema-1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID" version="4.0">
<display-name>PrimeFaces Web Application</display-name>
<!-- Change from "Development" to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<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>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
index.xhtml:
<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>
ProductDetail.xhtml:
<p>You've been redirected to this bookmarkable page with button.
ViewParameter you've passed is <strong>"#{editor.productId}"</strong>
</p>
EditorBean.java:
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;
}
Directories:

The buttons works but the parameter "productId" passed isn't read.
The example on link doesn't have an example of POM or web.xml, I had to create them myself with no primefaces experience.
Your productDetail.xhtml is missing an important part. If you check the full source of productDetail.xhtml in github, you'll see an important piece of code that is missing in your page:
<f:metadata>
<f:viewParam name="productId" value="#{productDetailView.productId}" />
</f:metadata>
This is what picks up the param in the url and puts it in the object.
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With