gpt4 book ai didi

java - Primefaces 数据表不起作用

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

当我运行下面的代码时,Apache Tomcat 日志显示:

在 com.swc.rc.recu.UtilsRecu 类型中找不到属性“recuClientes”

网页返回未找到记录。

有什么建议吗?

这是电话

<p:outputPanel>
<h:form>
<p:dataTable var="rec" value="#{rc.recu}">
<p:column headerText="recu">

<h:outputText value="#{rec.deudor}" />


</p:column>
</p:dataTable>
</h:form>
</p:outputPanel>

这是来源,我可以使用它,不是吗?

@XmlTransient
public Collection<Procs> getProcsCollection() {
return procsCollection;
}

public void setProcsCollection(Collection<Procs> procsCollection) {
this.procsCollection = procsCollection;
}

这是托管Bean..

@ManagedBean(name = "rc")
@SessionScoped
public class UtilsRecu {

private Clientes cliente=new Clientes();

private List <Procs> recu=new LinkedList<Procs>();



public void recuClientes(){

recu=(List<Procs>) cliente.getProcsCollection();

}

public void setRecu(List<Procs> recu) {

this.recu= recu;
}

public List<Procs> getRecu() {
recuClientes();
return recu;
}


}

谢谢你..

最佳答案

您遇到的异常不是由目前显示的 Facelets 代码引起的。这是由于 #{rc.recuClientes} 的错误使用造成的同一页面的其他地方。也许您已将其简单地放置在模板文本中,如下所示

#{rc.recuClientes}

并希望它能在加载时执行该方法。但事实并非如此。它将被解释为一个值表达式,因此它将寻找一个 getter 方法 getRecuClientes()它返回一些可以打印到输出的东西。但由于这样的 getter 方法不存在,因此将抛出您所面临的“未找到属性”异常。

鉴于此方法执行一些业务逻辑(填充列表),它应该由某些操作组件调用,例如 <h:commandButton> .

<h:form>
<h:commandButton value="Submit" action="#{rc.recuClientes}" />
</h:form>

或者,如果您打算在初始 GET 请求期间调用它,则只需使用 @PostConstruct 对其进行注释即可。无需在 View 中的任何位置引用它。

@PostConstruct
public void recuClientes() {
recu = (List<Procs>) cliente.getProcsCollection();
}

这样它将在 bean 构造后直接调用。

顺便说一下,这个转换是一种代码味道。在设计良好的代码中,您不应该需要在此特定构造中进行强制转换。

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

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