我想创建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;
}
}
我想使用此代码
private List<MyData> selectedDataList;
时,Netbeans给了我一个错误。 MyData
找不到类。如何解决此错误?最好的祝愿
最佳答案
您的项目/工作区中是否有MyData
类?
如果没有实现...如果存在,将其导入
万一您从某个示例中获取了代码,请仔细检查您没有忘记任何内容...