I am trying to do Insert Operation in a table. I display exiting records in a datatable and details are displayed in a panelGrid below the dataTable on selecting each row. panelGrid with blank inputText boxes are shown when user click NEW button. User Submits the new record and dataTable is refreshed.
On submit, I am getting error :
Nov 22, 2011 5:02:22 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: Argument Error: Parameter targetClass is null
java.lang.NullPointerException: Argument Error: Parameter targetClass is null
Code is Given below:
<p:outputPanel header="MyTable Records" rendered="true" id="panel_MyTable">
<p:dataTable id="table_MyTable" value="#{myBean.records}" var="dataMyTable" onRowSelectUpdate="details_MyTable" selection="#{myBean.currentRec}" update="submitButton">
<p:column>
<f:facet name="header">
<h:outputLabel value="Label 1" />
</f:facet>
<h:outputLabel value="#{dataMyTable.Field1}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Label 2" />
</f:facet>
<h:outputLabel value="#{dataMyTable.Field2}"/>
</p:column>
<f:facet name="footer">
<p:commandButton value="New" image="ui-icon ui-icon-add" actionListener="#{myBean.prepareForInsertAction}" update="details_myTable,submitButton" />
</f:facet>
</p:dataTable>
</p:outputPanel>
<h:panelGrid id="details_MyTable">
<h:outputLabel value="Label 1"/>
<p:inputText readonly="#{myBean.editMode ? false : true}" value="#{myBean.editMode ? myBean.newRec.Field1 : myBean.currentRec.Field1}" />
<h:outputLabel value="Label 2"/>
<p:inputText readonly="#{myBean.editMode ? false : true}" value="#{myBean.editMode ? myBean.newRec.Field2 : myBean.currentRec.Field2}" />
</h:panelGrid>
<p:commandButton id="submitButton" actionListener="#{myBean.createAction}" value="Submit" update="table_MyTable,details_MyTable" rendered="#{myBean.editMode ? true : false}"/>
@ManagedBean(name="myBean")
@ViewScoped
public class MyBean
{
public static List<MYTABLE> records;
MYTABLE currentRec;
Boolean editMode=false;
public MyBean(){
records = MYTABLE_CRUD.getAllRecs();
currentRec = new MYTABLE();
}
public void prepareForInsertAction(){
newRec = new MYTABLE();
editMode = true;
}
public void setCurrentRec(MYTABLE v_currentRec) {
this.currentRec = v_currentRec;
editMode = false;
}
}
Those
valueattributes are not right:Those values can be retrieved, but new values cannot be set. The following syntax will work:
(note that I improved the
readonlyattribute evaluation as well)But much better is to use just one and same property for both edit modes and use the edit mode value in the action method to determine how to deal with it:
with e.g.