gpt4 book ai didi

jsf - 在jsf数据表中选择一行

转载 作者:行者123 更新时间:2023-12-02 04:21:44 25 4
gpt4 key购买 nike

这是我的表格:

<h:dataTable var="book" value="#{ordersBean.userOrders}"
binding="#{ordersBean.htmlDataTable}">
<h:column>
<f:facet name="header">order ID</f:facet>
<h:outputText value="#{book[0]}"/>
</h:column>
<h:column>
<f:facet name="header">Book Title</f:facet>
<h:outputText value="#{book[1]}"/>
</h:column>
<h:column>
<f:facet name="header">Cost</f:facet>
<h:outputText value="#{book[2]}"/>
</h:column>
<h:column>
<f:facet name="header">Remove Order</f:facet>
<h:commandButton action="#{ordersBean.deleteOrder}" image="resources/images/del.gif"/>
</h:column>
</h:dataTable>

我需要获取用户点击其删除订单图标的哪一行的订单ID,然后从DAO中删除该订单。

这是deleteOrder():

@ManagedBean
@SessionScoped
public class OrdersBean {

private List<Book> userOrders = new ArrayList<Book>();
private HtmlDataTable htmlDataTable;

@Transactional
public void deleteOrder() {
Book selectedBook = (Book) htmlDataTable.getRowData(); // class cast exception (168)
}

//For populating table
@Transactional
public List<Book> userAllOrders() {
userOrders = bookDao.getTitleCostQty(String.valueOf(currentUser.getId())).list();
return userOrders;
}

public HtmlDataTable getHtmlDataTable() {
return htmlDataTable;
}

public void setHtmlDataTable(HtmlDataTable htmlDataTable) {
this.htmlDataTable = htmlDataTable;
}
//getter/setters

但我收到此错误:

javax.servlet.ServletException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

javax.faces.el.EvaluationException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
com.obs.bean.OrdersBean.deleteOrder(OrdersBean.java:168)

最佳答案

您使用 JSF 2.2 吗?也许从 2.0 开始有效...

因此您可以在命令按钮中传递实际的书:

<h:commandButton actionListener="#{ordersBean.deleteOrder(book)}" ... />

并接收所选书籍作为 bean 内的参数:

public void deleteOrder(Book selectedBook) {
// ...
}

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

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