私はprimfacesデータテーブルで行編集を実行しようとしています.データベースからデータテーブルのすべての値を取得しています.onEditメソッドでは、編集中の行の主キー値を取得しようとしています.編集または編集をキャンセルしようとすると目盛りまたは十字マークをクリックすると、次の例外が発生します。私はJSFの初心者です。値をデータベースに更新できる行編集の方法を教えてください。
私が得る例外
2013 年 8 月 22 日 3:56:56 AM com.sun.faces.context.PartialViewContextImpl processPartial INFO: java.lang.NullPointerException java.lang.NullPointerException at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java) :51) org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:40) で org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:57) で javax.faces.component で。 UIComponentBase.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) com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) org.primefaces.component.api.UIData.visitTree(UIData.java:639) で javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) で javax.faces.component.UIForm.visitTree(UIForm) .java:371) で javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) で javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) で com.sun.faces.context.PartialViewContextImpl で。 com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) の processComponents(PartialViewContextImpl.java:377) javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) の javax.faces.component .UIViewRoot.processDecodes(UIViewRoot.java:931) com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) で com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) で javax.faces.webapp.FacesServlet.service で(FacesServlet.java:593) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) org.apache. org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 127) org.apache.catalina.core.StandardEngineValve の org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) で。org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) の invoke(StandardEngineValve.java:109) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) の org.apache .coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) で org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) で java.lang.Thread.run(Unknown)ソース)
私の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>
私のマネージド 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");
}
}