gpt4 book ai didi

jsf - 数据表行选择不起作用

转载 作者:行者123 更新时间:2023-12-02 14:24:07 24 4
gpt4 key购买 nike

我有一个数据表

<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.

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

编辑:-

我的托管 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;
}

}

index.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>

关于jsf - 数据表行选择不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18515585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com