gpt4 book ai didi

java - Primefaces SelectCheckboxMenu 空值

转载 作者:行者123 更新时间:2023-12-01 12:46:17 25 4
gpt4 key购买 nike

我试图从 selectCheckboxMenu 中获取选定的值,但我在控制台中得到的只是空值。它也不适用于 selectOneMenu。这是我的 jsf 表单:

<h:form id="mmaster">
<p:dataTable
value="#{devicesBean.devices}"
var="dev"
widgetVar="dt"
border="1"
paginator="true"
paginatorPosition="top"
rows="10"
>
<f:facet name="header">Devices</f:facet>
<p:column headerText="UDN" sortBy="#{dev.deviceUDN}" filterBy="#{dev.deviceUDN}" filterMatchMode="contains" emptyMessage="No Devices Found">
<h:outputText value="#{dev.deviceUDN}" />
</p:column>
<p:column headerText="FriendlyName" sortBy="#{dev.deviceFriendlyName}" filterBy="#{dev.deviceFriendlyName}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceFriendlyName}" />
</p:column>
<p:column headerText="Model" sortBy="#{dev.deviceModel}" filterBy="#{dev.deviceModel}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceModel}" />
</p:column>
<p:column headerText="Manufacturer" sortBy="#{dev.deviceManufacturer}" filterBy="#{dev.deviceManufacturer}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceManufacturer}" />
</p:column>
<p:column headerText="Type" sortBy="#{dev.deviceType}" filterBy="#{dev.deviceType}" filterMatchMode="contains">
<h:outputText value="#{dev.deviceType}" />
</p:column>
<p:column headerText="Actions">
<p:selectCheckboxMenu value="#{devicesBean.selectAnnotations}">
<f:selectItems value="#{devicesBean.annotations}" />
</p:selectCheckboxMenu>
</p:column>
<p:column>
<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="@this">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>

我想知道 bean 的范围是否有问题,这是我的托管 bean:

@ManagedBean
public class DevicesBean implements Serializable {

private static final long serialVersionUID = 1L;
private List<Device> devices;
private List<String> annotations;
private List<String> selectAnnotations = new ArrayList<String>();
private Device device;

@EJB
IOntoProcessor iop;
@EJB
IDevicesDao idd;

public DevicesBean() {
}

@PostConstruct
public void init() {
setDevices(idd.getAllDevices());
setAnnotations(iop.getAllAnnotations());
}

public List<Device> getDevices() {
return devices;
}

public void setDevices(List<Device> devices) {
this.devices = devices;
}

public List<String> getAnnotations() {
return annotations;
}

public void setAnnotations(List<String> annotations) {
this.annotations = annotations;
}

public Device getDevice() {
return device;
}

public void setDevice(Device device) {
this.device = device;
}

public List<String> getSelectAnnotations() {
return selectAnnotations;
}

public void setSelectAnnotations(List<String> selectAnnotations) {
this.selectAnnotations = selectAnnotations;
}

public void doSave() {
System.out.println(selectAnnotations);
System.out.println(device);
selectAnnotations = new ArrayList<String>();
}

}

最佳答案

您正在尝试通过值为 Annotate 的按钮提交表单,该按钮已被指定为仅处理自身:

这只会处理按钮及其关联的表单参数,而不会处理表单中的其他元素。

<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="@this">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>

删除process="@this",或将其替换为process="@form"

<p:commandButton value="Annotate" action="#{devicesBean.doSave}" process="@form">
<f:setPropertyActionListener value="#{dev}" target="#{devicesBean.device}" />
</p:commandButton>

二,声明您的托管 bean 范围:@RequestScope@SessionScoped 都可以正常工作。

关于java - Primefaces SelectCheckboxMenu 空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24674192/

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