gpt4 book ai didi

java - 如何使用选择按钮创建 JSF 表

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

我想创建每行都有全选按钮和复选框的 JSF 表。我找到了这个源代码example 。在这个 JSF 表教程之后,我发现这个 JSF 表带有选择行 example 。我尝试修改代码,但在 Netbeans 中出现错误,我不知道如何修复:

import java.io.Serializable;
import java.math.BigDecimal;
import javax.enterprise.context.SessionScoped;
// or import javax.faces.bean.SessionScoped;
import javax.inject.Named;
/* include SQL Packages */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import javax.annotation.Resource;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
// or import javax.faces.bean.ManagedBean;

import org.glassfish.osgicdi.OSGiService;

@Named("SessionsController")
@SessionScoped
public class Sessions implements Serializable {

public Sessions() {
}

private Map<Long, Boolean> selectedIds = new HashMap<Long, Boolean>();
private List<MyData> selectedDataList;

/* Call the Oracle JDBC Connection driver */
@Resource(name = "jdbc/Oracle")
private DataSource ds;

private static final ArrayList<SessionArray> sessionList =
new ArrayList<SessionArray>(Arrays.asList(
new SessionArray("A0001", "Intel CPU",
new BigDecimal("700.00"), 1),
new SessionArray("A0002", "Harddisk 10TB",
new BigDecimal("500.00"), 2),
new SessionArray("A0003", "Dell Laptop",
new BigDecimal("11600.00"), 8),
new SessionArray("A0004", "Samsung LCD",
new BigDecimal("5200.00"), 3),
new SessionArray("A0005", "A4Tech Mouse",
new BigDecimal("100.00"), 10)));

public ArrayList<SessionArray> getSessionList() {

return sessionList;

}

public String deleteAction(SessionArray session) {

sessionList.remove(session);
return null;
}

public static class SessionArray {

String orderNo;
String productName;
BigDecimal price;
int qty;

public SessionArray(String orderNo, String productName,
BigDecimal price, int qty) {
this.orderNo = orderNo;
this.productName = productName;
this.price = price;
this.qty = qty;
}

public String getOrderNo() {
return orderNo;
}

public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public int getQty() {
return qty;
}

public void setQty(int qty) {
this.qty = qty;
}
}

//select all button code

public String getSelectedItems() {

// Get selected items.
selectedDataList = new ArrayList<MyData>();
for (MyData dataItem : dataList) {
if (selectedIds.get(dataItem.getId()).booleanValue()) {
selectedDataList.add(dataItem);
selectedIds.remove(dataItem.getId()); // Reset.
}
}

// Do your thing with the MyData items in List selectedDataList.

return "selected"; // Navigation case.
}

public Map<Long, Boolean> getSelectedIds() {
return selectedIds;
}

public List<MyData> getSelectedDataList() {
return selectedDataList;
}

}

当我想使用此代码时,Netbeans 给了我一个错误 private List<MyData> selectedDataList;MyData找不到类。我该如何修复这个错误?

最美好的祝愿

最佳答案

您的项目/工作空间中是否有类MyData...

如果没有实现它...如果它存在,则导入它

如果您从某些示例中获取了代码,请仔细检查您是否忘记了任何内容...

关于java - 如何使用选择按钮创建 JSF 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9991342/

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