我想创建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
类。我如何解决这个错误?
祝福
答案 0 :(得分:2)
您的项目/工作区中是否有课程MyData
...
如果没有实现...如果存在,请将其导入
如果您从某个示例中获取代码,请仔细检查您是否忘记了任何内容......