我想在primefaces datatable上執行行編輯。我從數據庫中獲取數據表的所有值。onEdit方法我只是試圖獲取正在編輯的行的主鍵值。當我嘗試編輯或取消編輯點擊蜱或十字標記時,我得到以下異常。我是JSF的新手,請幫助如何執行行編輯,它可以更新值到數據庫。Primefaces行編輯無法正常工作
例外,我得到
2013年8月22日上午03時56分56秒com.sun.faces.context.PartialViewContextImpl processPartial 信息:顯示java.lang.NullPointerException 顯示java.lang.NullPointerException 在org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:51) at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:40) at org.primefaces.component。 datatable.DataTableRenderer.decode(DataTableRenderer.java:57) at javax.faces.component.UIComp onentBase.decode(UIComponentBase.java:787) at org.primefaces.component.api.UIData.processDecodes(UIData.java:228) at com.sun.faces.context.PartialViewContextImpl $ PhaseAwareVisitCallback.visit(PartialViewContextImpl.java: 507) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at org.primefaces.component.api.UIData.visitTree(UIData.java:639) at javax.faces。 component.UIComponent.visitTree(UIComponent.java:1623) at javax.faces.component.UIForm.visitTree(UIForm.java:371) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) at com.sun.faces.context.PartialViewCont extImpl.processComponents(PartialViewContextImpl.java:377) 在com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) 在javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) 在javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931) at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) at com.sun.faces.lifecycle.Phase.doPhase( Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache。 catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core。 StandardContextValve.invoke(StandardContextValve.java:191) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 在org.apache.coyote.http11。 Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol $ Http11Con nectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489) at java.lang.Thread。在爲datatable.Now它正在運行(來源不明)
我的JSF代碼片段
<h:form id="lpcForm">
<div id="content">
<p:dataTable var="lpcData" value="#{lpcBean.lpcIdList}" id="lpcList"
editable="true" scrollable="true" scrollWidth="1110"
tableStyle="table-layout:auto; width:1130px;" scrollHeight="330"
styleClass="datatable">
<p:ajax event="rowEdit" listener="#{lpcBean.onEdit}" />
<p:ajax event="rowEditCancel" listener="#{lpcBean.onCancel}" />
<p:column selectionMode="multiple" style="width:5%" />
<p:column headerText="LPC ID" style="width:20%">
<h:outputText value="#{lpcData.LPCID}" />
</p:column>
<p:column headerText="First Name" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.name_First}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lpcData.name_First}" style="width:100%"
label="firstName" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Last Name" style="width:24%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.name_Last}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lpcData.name_Last}" style="width:100%"
label="lastName" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.email_Address}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lpcData.email_Address}" style="width:100%"
label="emailAddress" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Region" style="width:24%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.region}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{lpcData.region}">
<f:selectItems value="#{lpcBean.regions}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State" style="width:24%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.homeState}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{lpcData.homeState}">
<f:selectItems value="#{lpcBean.mainStates}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Profit Center" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.profitCenter}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lpcData.profitCenter}" style="width:100%"
label="profitCenter" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Active" style="width:24%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lpcData.active_LPC}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{lpcData.active_LPC}">
<f:selectItems value="#{lpcBean.activeLpcs}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
我的Managed Bean的片段
@RequestScoped
@ManagedBean
public class LpcBean implements Serializable {
private List<LPC>lpcItems=new ArrayList<LPC>();
public static LPC[] selectedRows;
public static LPC itemSelect;
private LpcDataModel lpcIdList;
Connection connection;
Statement selectStmt1,selectStmt2,selectStmt3,selectStmt4;
private List<String> nameList;
private String selectedLpcName;
private String selectedItem;
private List<String> regions=new ArrayList<String>();
private List<String>mainStates=new ArrayList<String>();
private List<String>activeLpcs=new ArrayList<String>();
public LpcBean() {
System.out.println("inside the constructor");
lpcIdList = new LpcDataModel(lpcItems);
getLpcFields();
}
public List<LPC> getLpcItems() {
return lpcItems;
}
public void setLpcItems(List<LPC> lpcItems) {
this.lpcItems = lpcItems;
}
public LPC[] getSelectedRows() {
return selectedRows;
}
public void setSelectedRows(LPC[] selectedRows) {
LpcBean.selectedRows = selectedRows;
}
public LpcDataModel getLpcIdList() {
return lpcIdList;
}
public void setLpcIdList(LpcDataModel lpcIdList) {
this.lpcIdList = lpcIdList;
}
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
public List<String> getNameList() {
return nameList;
}
public void setNameList(List<String> nameList) {
this.nameList = nameList;
}
public String getSelectedLpcName() {
return selectedLpcName;
}
public void setSelectedLpcName(String selectedLpcName) {
this.selectedLpcName = selectedLpcName;
}
public void getLpcFields() {
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://cvgapp106I/dev2_LPSR");
System.out.println("connected to the database");
selectStmt1 = connection.createStatement();
ResultSet rs1 = selectStmt1.executeQuery("select * from LPC order by LPCID");
while(rs1.next()){
lpcItems.add(new LPC(rs1.getString("LPCID"),rs1.getString("Name_First"),
rs1.getString("Name_Last"),rs1.getString("Email_Address"),rs1.getString("Region"),
rs1.getString("HomeState"),rs1.getString("ProfitCenter"),rs1.getString("Active_LPC")));
}
selectStmt2=connection.createStatement();
ResultSet rs2=selectStmt2.executeQuery("Select * from Tbl_state");
while(rs2.next())
{
mainStates.add(rs2.getString("State"));
}
selectStmt3=connection.createStatement();
ResultSet rs3=selectStmt3.executeQuery("Select * from Tbl_Regional_Managers");
while(rs3.next())
{
regions.add(rs3.getString("Location"));
}
selectStmt4=connection.createStatement();
ResultSet rs4=selectStmt4.executeQuery("Select * from YesNo");
while(rs4.next())
{
activeLpcs.add(rs4.getString("YesNo_Key"));
}
}
catch (Exception e)
{
//System.out.println("Error Data : " + e.getMessage());
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void setRegions(List<String> regions) {
this.regions = regions;
}
public void setMainStates(List<String> mainStates) {
this.mainStates = mainStates;
}
public void setActiveLpcs(List<String> activeLpcs) {
this.activeLpcs = activeLpcs;
}
public List<String> getRegions() {
return regions;
}
public List<String> getMainStates() {
return mainStates;
}
public List<String> getActiveLpcs() {
return activeLpcs;
}
public void onEdit(RowEditEvent event) {
String lpcId=(String) ((LPC) event.getObject()).getLPCID();
System.out.println("EMAIL ID:"+lpcId);
}
public void onCancel(RowEditEvent event) {
System.out.println("inside on cancel");
}
}
哪一個是你的PF版本?你是否嘗試過使用不太複雜的表格(例如單個可編輯列)?您是否嘗試更改由您填充的列表的數據庫連接? –