数据表行选择不起作用

2023-12-29

我有一个数据表

<p:dataTable id="db"
    value="#{notificationBox.notificationsList}"
    var="notificationForm" 
    rows="15"
    emptyMessage="${msgs.getMessage('table.empty.message')}"
    paginator="true" 
    paginatorPosition="bottom"
    rowKey="#{notificationForm}"
    selection="#{notificationBox.notification}" 
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} ( ${notificationBox.notificationsList.size()} ${msgs.getMessage('table.records')} )"
    selectionMode="single" 
    tableStyle="height:430px">

    //Rest of the code

在这里,如果我选择任何行,我将进行 ajax 调用(与 primefaces 即时行选择示例相同)。 Ajax 位于 Datatable 内部。

<p:ajax event="rowSelect" listener="#{notificationBox.onRowSelect}"   
    oncomplete="carDialog.show();" />

我的支持 Bean 类 -

private List<NotificationForm> notificationsList;
public NotificationForm notification;
public void onRowSelect(SelectEvent event) {
    LOGGER.info("Here. +"+notification);
}

//Setter and Getters.

问题是,如果我选择任何行,“通知”将为空。我无法进一步处理。请帮忙。也欢迎任何替代方法。

Edit:-

我的托管 Bean 范围 -

<managed-bean>
    <managed-bean-name>notificationBox</managed-bean-name>
    <managed-bean-class>com.comviva.workflow.ui.notification.NotificationBox</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
        <property-name>notificationDao</property-name>
        <value>#{notificationDaoService}</value>
    </managed-property>
    <managed-property>
        <property-name>userInfoDao</property-name>
        <value>#{userInfoDaoProxy}</value>
    </managed-property>
</managed-bean>

你有你的p:dataTable包裹在一个h:form标签?这实际上对我有用:

通知框(@ViewScoped)

package com.mycompany;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.event.SelectEvent;

@ManagedBean
@ViewScoped
public class NotificationBox {

    public class NotificationForm {

        Integer notificationId;

        String name;

        public NotificationForm(Integer id, String nam) {
            notificationId = id;
            name = nam;
        }

        public String getName() {
            return name;
        }

        public Integer getNotificationId() {
            return notificationId;
        }

        @Override
        public String toString() {
            return "NotificationForm [notificationId=" + notificationId
                    + ", name=" + name + "]";
        }
    }

    private List<NotificationForm> notificationsList;

    public NotificationForm notification;

    public NotificationBox() {
        notificationsList = Arrays.asList(new NotificationForm(1, "Form1"),
                new NotificationForm(2, "Form2"));
    }

    public NotificationForm getNotification() {
        return notification;
    }

    public List<NotificationForm> getNotificationsList() {
        return notificationsList;
    }

    public void onRowSelect(SelectEvent event) {
        System.out.println(event.getObject());
    }

    public void setNotification(NotificationForm notification) {
        this.notification = notification;
    }

}

索引.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<h:head>
</h:head>

<h:body>

    <h:form>
        <p:dataTable id="db" value="#{notificationBox.notificationsList}"
            var="notificationForm" rows="15"
            emptyMessage="${msgs.getMessage('table.empty.message')}"
            paginator="true" paginatorPosition="bottom"
            rowKey="#{notificationForm.notificationId}"
            selection="#{notificationBox.notification}"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} ( ${notificationBox.notificationsList.size()} ${msgs.getMessage('table.records')} )"
            selectionMode="single" tableStyle="height:430px">

            <p:ajax event="rowSelect" listener="#{notificationBox.onRowSelect}" />

            <p:column>
        #{notificationForm.name}
        </p:column>
        </p:dataTable>
    </h:form>
</h:body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

数据表行选择不起作用 的相关文章

随机推荐

  • jQuery .load() 不适用于我的图像

    我有一些代码试图在图像加载完成后运行 我使用以下 jQuery 代码 myimageid load function alert Image Loaded 但是弹出窗口永远不会出现 我无法让 load 函数工作 有人遇到过这个问题吗 如果你
  • 从列表中删除的随机样本

    我的列表中有数据 例如 L 3 4 5 1 4 5 1 2 3 1 2 3 我需要随机采样 2 的大小 所以我想使用 import random t1 random sample set L 2 现在 T1 是随机提取的值的列表 但我想从我
  • 正确使用io包中的stdout函数

    dart 中 io 包中的 stdout 函数的正确用法是什么 我写了这样一个脚本 import dart io void main print Hello World stdout 我得到以下输出 firen firen VirtualB
  • 使用 ajax 监听器时 Primefaces 对话框框架不工作

    我正在尝试使用 Primefaces 4 对话框框架打开对话框 public void openDialog String viewName RequestContext getCurrentInstance openDialog view
  • 用GDB读取寄存器指向的内存

    如果我知道内存位置 有没有办法从 GDB 查看内存内容 也就是说 我正在调试我为操作系统课程编写的 x86 汇编程序 现在 我正在尝试使用 C 和 Gas GNU 汇编程序 为 x86 上的 Linux 编写一个用户级线程库 我分配了自己的
  • PHPStorm 中未定义的类 DateTime

    我想使用类DateTime but PHPStorm我这么说 Undefined class DateTime 我的 PHP 版本是5 5 9 1 我使用的是 PHPStorm 版本2016 1我正在与Yii2 framework 如果它能
  • 在 R 中对整齐数据同时执行多个 t.test

    我有一个如下所示的数据集 id samediff factor value 1 S give 3 1 S impact 4 2 S give 2 2 S impact 5 3 D give 1 3 D impact 4 4 D give 3
  • 如何向 Kivy For Android 添加模块?

    我在 Android 设备上安装了 Kivy 但 help modules 显示未安装 PIL 模块 我怎样才能添加它 编辑 我的意思是 我安装了 kivy launcher 并编写了一个小型测试应用程序 它可以工作 现在 如果我的应用程序
  • 当我单击 li 标签时,它会获取数据值,但是当我插入它时,它具有空值

    单击时我得到 li 标签数据值 现在我需要使用插入回数据库的值 但它在我的数据库中显示空值 但我使用 console log 它显示了价值 如何获取值并插入数据库 mymoviemanagement php movie 的值为 null i
  • 如何在 PHP 中设置 cookie 然后重定向?

    进行一些处理后 我想为用户输入设置一个 cookie 值 然后将它们重定向到新页面 但是 cookie 尚未设置 如果我注释掉重定向 则 cookie 设置成功 我认为这是某种标题问题 对于这种情况 最好的解决方法是什么 if form s
  • 不同大小类别的不同表视图单元格行高?

    如何更改此 UITableViewController 自定义类以动态更改表视图单元格的高度 我为 iPad 和 iPhone 尺寸类别指定了不同的字体大小 这是之前与 rdelmar 讨论的延续 import CREWFoodWaterL
  • 计算POST内容长度

    如何计算内容长度 例如 POST Upload HTTP 1 1 Host test lan User Agent Shockwave Flash Connection Keep Alive Cache Control no cache A
  • 操作栏抽屉切换自定义图标

    我正在尝试使用操作栏抽屉切换 但我希望它显示的不仅仅是菜单图标 我希望它在自定义菜单图标的右上角显示通知计数 但我仍然希望操作栏抽屉式开关在需要时显示后退箭头 因此 我首先尝试查看是否可以在操作栏抽屉切换上显示自定义布局 包含菜单图标的图像
  • Guid.NewGuid() VS Random.Next() 的随机字符串生成器

    我和我的同事正在讨论使用哪种方法来自动生成用户 ID 和帖子 ID 以在数据库中进行识别 一个选项使用 Random 的单个实例 并采用一些有用的参数 以便它可以重用于各种字符串生成情况 即从 4 位数字 pin 到 20 位字母数字 id
  • 如何使用JPA或HQL动态排序多对多关系?

    我有一个这样的映射 ManyToMany cascade CascadeType PERSIST JoinTable name product product catalog joinColumns JoinColumn name prod
  • 访问 Android 上先前安装创建的文件 - 范围存储 Android 11

    我正在使用 LibGDX 开发一个带有预设管理器的音乐应用程序 该管理器使用 LibGDX 的 FileHandle 来管理文件和目录 在我更新到 Android 11 API 30 之前 此功能一直运行良好 现在由于 Android 新的
  • Ruby OptionParser:隐藏命令选项的帮助文本

    Ruby OptionParser 将根据此描述自动为您生成帮助屏幕 http ruby about com od advancedruby a optionparser htm 有没有办法删除命令选项的帮助文本 我可以使用隐藏命令 而是使
  • 访问 Ruby 中受保护的方法

    我正在尝试在 Ruby 中为自己使用访问修饰符 我有 class Person def initialize first name last name age first name first name last name last nam
  • 全球之前一切都是开玩笑?

    我需要使用 React 测试库和 Jest 在测试中模拟不同的窗口大小 目前我必须拥有这个beforeAll在每个测试文件中 import matchMediaPolyfill from mq polyfill beforeAll gt m
  • 数据表行选择不起作用

    我有一个数据表