我在 jsf primefaces 中开发 Web 应用程序,我在从dataTable
这是我的 xhtml 代码
<p:contextMenu for="table">
<p:menuitem value="Allocate" actionListener="#{allocation.allocate}" update="msg"/>
</p:contextMenu>
<p:dataTable id="table" var="batch" value="#{allocation.batchInfoList}" rowKey="#{batch.id}"
selection="#{allocation.batchInfo}" selectionMode="single">
<p:column headerText="Tan">
<h:outputText value="#{batch.tan}" />
</p:column>
<p:column headerText="Username">
<h:outputText value="#{batch.users.curator}" />
</p:column>
<p:column headerText="Status">
<h:outputText value="#{batch.status}" />
</p:column>
</p:dataTable>
这是我的操作代码
package com.cation.action;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.cation.bean.BatchInfo;
import com.cation.bean.Users;
import com.cation.controller.CationController;
public class Allocation {
private String batchName;
private String curator;
private String tanNumber;
private List<BatchInfo> batchInfoList;
private List<String> batchList = new ArrayList<String>();
private List<Users> usersList = new ArrayList<Users>();
private BatchInfo batchInfo = new BatchInfo();
private CationController cationController = new CationController();
public String getBatchName() {
return batchName;
}
public void setBatchName(String batchName) {
this.batchName = batchName;
}
public List<BatchInfo> getBatchInfoList() {
return batchInfoList;
}
public void setBatchInfoList(List<BatchInfo> batchInfoList) {
this.batchInfoList = batchInfoList;
}
public List<String> getBatchList() {
return batchList;
}
public void setBatchList(List<String> batchList) {
this.batchList = batchList;
}
public List<Users> getUsersList() {
return usersList;
}
public void setUsersList(List<Users> usersList) {
this.usersList = usersList;
}
public String getCurator() {
return curator;
}
public void setCurator(String curator) {
this.curator = curator;
}
public String getTanNumber() {
return tanNumber;
}
public void setTanNumber(String tanNumber) {
this.tanNumber = tanNumber;
}
public BatchInfo getBatchInfo() {
return batchInfo;
}
public void setBatchInfo(BatchInfo batchInfo) {
this.batchInfo = batchInfo;
}
@SuppressWarnings("unchecked")
public Allocation() {
try {
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = request.getSession();
usersList = (List<Users>) session.getAttribute("allUsers");
batchList = cationController.getAllBatch();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String handleBatch() {
try {
batchInfoList = new ArrayList<BatchInfo>();
batchInfoList = cationController.getBatchByName(batchName);
} catch (Exception e) {
e.printStackTrace();
}
return "allotInput";
}
public void allocate() {
System.out.println(batchInfo);
}
}
我的问题是当通过右键单击事件从数据表中选择行值并选择分配时,它调用该方法但对象返回为空。我不确定我是否已正确地将代码放入 xhtml 中的数据表标记中。
谁能帮我解决这个问题。只是为了获取选定的行值或它的对象。