You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrimeFaces Sheet列参数传递至JSF后台Bean异常问题

PrimeFaces Extensions Sheet列selectItems传参为null问题

问题详情

使用pe:sheetcolumn组件时,readonlyCell属性可正常将material.country参数传递至@ViewScoped后台Bean,但selectItems属性始终传递null值。相关代码如下:

<pe:sheetcolumn headerText="HTS Chapter" value="#{material.htsChapter}" colWidth="100" rendered="true" colType="dropdown" 
                readonlyCell="#{!itemActionsManagedBean.authCheckForEditForHtsChapter(material.country)}" 
                selectItems="#{itemActionsManagedBean.getMapItemsForHtsChapter(material.country)}"/>

环境版本:

  • JSF 2.2.1
  • PrimeFaces 12.0.0
  • PrimeFaces Extensions 12.0.5
  • Bean作用域:@ViewScoped

解决方案

1. 改用内部<f:selectItems>标签

selectItems作为列属性时,会在列初始化阶段求值,此时行级的material对象可能还未完成绑定,导致参数为null。将selectItems移至列内部的<f:selectItems>标签,使其在每行渲染时重新求值:

<pe:sheetcolumn headerText="HTS Chapter" value="#{material.htsChapter}" colWidth="100" rendered="true" colType="dropdown" 
                readonlyCell="#{!itemActionsManagedBean.authCheckForEditForHtsChapter(material.country)}">
    <f:selectItems value="#{itemActionsManagedBean.getMapItemsForHtsChapter(material.country)}"/>
</pe:sheetcolumn>

2. 验证ViewScoped Bean状态

检查@ViewScoped Bean是否存在序列化问题,或在请求回发时被意外重建。确保Bean的所有字段支持序列化,避免因Bean重建导致上下文数据丢失。

3. 调试参数接收逻辑

在Bean的getMapItemsForHtsChapter方法中添加日志,确认传入的参数值:

public List<SelectItem> getMapItemsForHtsChapter(String country) {
    System.out.println("传入的country参数:" + country);
    // 原有业务逻辑
}

同时排查JSF生命周期阶段,确认selectItems求值时,当前行的material对象已完成初始化。

4. 检查Sheet行数据绑定

确保pe:sheet的value属性绑定的列表中,每个material对象的country属性已正确赋值:

<pe:sheet value="#{itemActionsManagedBean.materials}" var="material">
    <!-- 列定义 -->
</pe:sheet>

确认materials列表在页面加载或回发时已完整加载,不存在空元素或未初始化country属性的对象。


内容的提问来源于stack exchange,提问作者Samet Dağ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 00:03:19