我有一个包含几个数据列的数据表和一个带有复选框的列。检查一些复选框,然后提交整个表格。我的bean中的模型已更新,我可以看到检查了哪个复选框(行)。 但我不得不改变设计,现在我正在使用子表。 (所以我可以分组一些信息)。现在,当我提交表单时,模型不会更新。因此,在循环数据表值时,所有复选框都是false,而我在页面上检查了一些。我该如何解决这个问题?
我正在使用primefaces 3
我在loadreports中填写superlist。当点击按钮时,我调用downloadZip,然后循环遍历超级列表以查看是否选中了复选框,然后我可以将文档添加到zip文件中。
这是我的豆子
public ArrayList<HashMap<String, Object>> getSuperList() throws MWSException {
getLog().debug("getSuperList()");
if (superList == null) {
loadReports();
}
return superList;
}
private void loadReports() throws MWSException {
DocumentManager dm = new DocumentManager(getWA().getMwsProxy());
IMWSDocument[] list = dm.getDocumentHistory(getWS().getUser(), getWS().getUser().getCustomerPartnerId(),
WebConstants.BUSINESSPARTNER, WebConstants.PUBLISHSTRATEGYENUMIDS, dateFrom, dateTo, null, null, template);
ArrayList<Object> typeObject = new ArrayList<Object>();
superList = new ArrayList<HashMap<String, Object>>();
Set<Integer> setType = new HashSet<Integer>();
HashMap<String, Object> tempType = new HashMap<String, Object>();
String tempTypeName = "";
Integer tempTypeId = null;
for (IMWSDocument d : list) {
if (type == null || d.getTypeId().equals(type)) {
if (!setType.contains(d.getTypeId())) {
if (setType.size() > 0) {
tempType = new HashMap<String, Object>();
tempType.put("typeName", tempTypeName);
tempType.put("typeId", tempTypeId);
tempType.put("typeObject", typeObject);
superList.add(tempType);
typeObject = new ArrayList<Object>();
}
setType.add((Integer) d.getTypeId());
tempTypeName = d.getType();
tempTypeId = d.getTypeId();
HashMap<String, Object> temp = new HashMap<String, Object>();
temp.put("checked", false);
temp.put("id", d.getId());
temp.put("name", d.getName());
temp.put("dateCreated", d.getDateCreated());
temp.put("fileName",
d.getDirPath().substring(d.getDirPath().lastIndexOf("/") + 1, d.getDirPath().length()));
temp.put("typeId", d.getTypeId());
temp.put("type", d.getType());
temp.put("templateId", d.getTemplateId());
temp.put("template", d.getTemplate());
typeObject.add(temp);
} else {
HashMap<String, Object> temp = new HashMap<String, Object>();
temp.put("checked", false);
temp.put("id", d.getId());
temp.put("name", d.getName());
temp.put("dateCreated", d.getDateCreated());
temp.put("fileName",
d.getDirPath().substring(d.getDirPath().lastIndexOf("/") + 1, d.getDirPath().length()));
temp.put("typeId", d.getTypeId());
temp.put("type", d.getType());
temp.put("templateId", d.getTemplateId());
temp.put("template", d.getTemplate());
typeObject.add(temp);
}
}
}
tempType = new HashMap<String, Object>();
tempType.put("typeName", tempTypeName);
tempType.put("typeId", tempTypeId);
tempType.put("typeObject", typeObject);
superList.add(tempType);
rowCount = superList.size();
}
public void DownloadZip(ActionEvent event) throws IOException, MWSException {
int BUFSIZE = 4096;
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
String tempPath = SiteConfig.getInstance().get("file.dir.temp");
// RFC says 'attachment'. Unfortunately, IE has a typo so we set "attachement"
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"reports.zip\"");
DocumentManager dm = new DocumentManager(getWA().getMwsProxy());
// Stream to the requester.
byte[] buf = new byte[BUFSIZE];
File tempdir = new File(tempPath + File.separator + getWS().getUser().getSignOn() + "_" + new Date().getTime());
tempdir.mkdir();
File tempFile = new File(tempdir.getPath() + File.separator + "reports_temp.zip");
ServletOutputStream sos = response.getOutputStream();
FileOutputStream fos = new FileOutputStream(tempFile);
ZipOutputStream out = new ZipOutputStream(fos);
InputStream is = new FileInputStream(tempFile);
try {
// Create the ZIP file
// String outFilename = "outfile.zip";
// Compress the files
for (HashMap<String, Object> item : superList) {
for (Object reportItem : ((ArrayList<Object>) item.get("typeObject"))) {
HashMap<String, Object> report = ((HashMap<String, Object>) reportItem);
if ((Boolean) report.get("checked")) {
//this is always false.
....
这是jsf页面
<p:dataTable id="reportlisttable" var="listItem" value="#{reportList.superList}" cellpadding="0" cellspacing="0"
rowClasses="row1,row2" styleClass="data" headerClass="header" columnClasses="col" width="100%"
emptyMessage="#{msg.all_lists_no_records_found}" paginator="true" rows="10" rowsPerPageTemplate="5,10,20,50,100"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} #{msg.all_lists_numberOfRowsDisplayed_label} {RowsPerPageDropdown}">
<p:subTable var="report" value="#{listItem.typeObject}">
<f:facet name="header">
#{listItem.typeName}
</f:facet>
<p:column id="column_select" >
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<h:selectBooleanCheckbox name="selectColumn" value="#{report.checked}" />
</p:column>
<p:column id="id" sortBy="#{report.id}">
<f:facet name="header">
<h:outputText value="#{msg.reportlist_id}" />
</f:facet>
<h:outputText value="#{report.id}"/>
</p:column>
<p:column id="date" sortBy="#{report.dateCreated}" parser="date">
<f:facet name="header">
<h:outputText value="#{msg.reportlist_date}" />
</f:facet>
<h:outputText value="#{report.dateCreated}">
<mw:convertDateTime />
</h:outputText>
</p:column>
<p:column id="name" sortBy="#{report.name}" >
<f:facet name="header">
<h:outputText value="#{msg.reportlist_reportname}" />
</f:facet>
<h:outputText value="#{report.name}"/>
</p:column>
</p:subTable>
</p:dataTable>
<t:div id="download">
<h:panelGrid columns="2" >
<t:graphicImage url="${path.staticRootUrl}images/arrow_compare.gif" hspace="15"/>
<p:commandButton value="${msg.reportlist_download}" actionListener="#{reportList.DownloadZip}" styleClass="button" ajax="false"/>
</h:panelGrid>
</t:div>