无法将String作为参数JSF 2.3传递

时间:2018-08-13 12:37:48

标签: jsf primefaces omnifaces viewparams jsf-2.3

我正在使用JSF 2.3FacesContext context = FacesContext.getCurrentInstance(); ExternalContext extContext = context.getExternalContext(); String redirected = extContext.encodeActionURL(context.getApplication().getViewHandler().getActionURL(context, url)); URIBuilder builder = new URIBuilder(redirected); builder.addParameter("action", "A") extContext.getFlash().setKeepMessages(true); extContext.redirect(builder.toString()); ,我将String作为参数传递,但它为空! java:

......
<f:metadata>
    <f:viewParam name="action" value="#{mybean.action}" />
</f:metadata>
.......

XHTML:

<f:viewParam name="id" value="#{mybean.id}" converter="javax.faces.Long" />

当我在以下示例Long下传递Boolean或Long时,它工作正常:

{{1}}

1 个答案:

答案 0 :(得分:1)

我添加了OmniFaces库,并且效果很好:

pom.xml:

<dependency>
   <groupId>org.omnifaces</groupId>
   <artifactId>omnifaces</artifactId>
   <version>3.1</version>
</dependency>

XHTML:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
//Add this tag
    xmlns:o="http://omnifaces.org/ui">

......
<f:metadata>
    <o:viewParam name="action" value="#{mybean.action}" />
</f:metadata>
.......