【问题标题】:f:param and f:viewparam setter not calledf:param 和 f:viewparam 设置器未调用
【发布时间】:2012-07-01 04:27:21
【问题描述】:

我有一个 xhtml 页面,其中有一个带有 f:param 的输出链接

<h:outputLink value="#{formService.getStartFormData(v_process.id).formKey}"> Start <f:param name="processDefinitionKey" value="#{v_process.key}"></f:param> </h:outputLink>

在目标页面,我有视图参数

f:metadata>
        <!-- bind the key of the process to be started -->
        <f:viewParam name="processDefinitionKey" value="#{processList.processDefinitionKey}"/> 

    </f:metadata>

我的豆是

@Named
@RequestScoped
public class ProcessList{

private String processDefinitionKey ; 

@Inject
private RepositoryService repositoryService;

@Produces
@Named("processDefinitionList")
public List<ProcessDefinition> getProcessDefinitionList() {
return repositoryService.createProcessDefinitionQuery()
        .list();
}

public void setProcessDefinitionKey(String processDefinitionKey1) {
  System.out.println("setProcessDefinitionKey "+processDefinitionKey1);
this.processDefinitionKey = processDefinitionKey1;
}

public String getProcessDefinitionKey() {
  System.out.println("getProcessDefinitionKey______ "+processDefinitionKey);
return processDefinitionKey;
}


}

processDefinitionKey 为 null,setter 没有被调用,怎么回事? web.xml 或 faces-config.xml 中是否有任何配置要添加? 在同一个项目中,我使用 primefaces 和 spring security

这是整个页面

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="/WEB-INF/templates/template.xhtml">

<ui:define name="metadata">
    <f:metadata>
        <!-- bind the key of the process to be started -->
        <f:viewParam name="processDefinitionKey" value="#{processList.processDefinitionKey}" />
    </f:metadata>
</ui:define>

<ui:define name="content">      

谢谢你的回复,请这个没有用

【问题讨论】:

  • 我认为您缺少此方法的设置器:public List&lt;ProcessDefinition&gt; getProcessDefinitionList()。你可以试试吗?
  • @cacho:为什么在这种特殊情况下需要该属性的设置器?
  • @BalusC:因为我认为代码代表一个 JSF Java Bean,因此,它需要为每个属性都有一个 getter/setter,对吗?
  • @cacho:不。只输出值不需要设置器。此外,如果缺少的二传手真的是原因,你会得到一个PropertyNotWritableException,但这远不是这里的原因。
  • 我已经编辑了我的问题,我的页面中有 f:metadata,而不是模板页面 .config 文件或 spring security,primefaces 或 jsf 版本是否会产生影响?感谢您的回复,如果您有任何想法,请帮忙

标签: jsf el viewparams


【解决方案1】:

这是一个 JEE7 错误。 https://java.net/jira/browse/JAVASERVERFACES-2868 作为一种解决方法,我提出:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:oldf="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/template.xhtml">
<oldf:metadata>
    <oldf:viewAction action="#{chooseRoleBean.init()}" />
</oldf:metadata>

【讨论】:

  • 只需升级 JSF impl。
  • @BalusC JSF 2.2.1 似乎无法通过updatetool 获得。
【解决方案2】:

尝试更改命名空间,例如posted already here。在我的情况下(glassfish 4.0)和链接的情况下,它必须是

xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"

但是试试

xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"

这对我来说适用于 Tomcat。

如果有人知道为什么会这样,我会很高兴来到这里。第二个变体应该是正确的我read here

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 2013-10-27
    • 2012-07-31
    • 2013-12-18
    • 1970-01-01
    • 2013-09-20
    • 2011-07-31
    • 2014-02-15
    • 2015-08-26
    相关资源
    最近更新 更多