setRowKey is throwing null pointer exceptiion-- JSF
995928Mar 10 2013 — edited Mar 10 2013I am trying to pickup the selected row from extendeddatatable and print in different panel. When action invoked and setting the rowkey i am seeing nullpointer exception. Please see my code below.
AT line table.setRow(key) is throwing null pointer in the method "takeSelection". Please help me to resolve this. thanks.
package com.managedbean;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.richfaces.model.selection.*;
import java.util.Iterator;
import org.richfaces.model.ExtendedTableDataModel;
import org.richfaces.component.UIExtendedDataTable;
public class TestMbean {
private String errMsg;
private String actionMsg;
private ArrayList<String> tabledata;
private Vector<GetUserInfo> userInfo;
private String name;
private String selectedUser;
private SimpleSelection selection = new SimpleSelection();
public UIExtendedDataTable table; // = new UIExtendedDataTable();
private GetUserInfo userInfoSub;
private int keyValue;
public int getKeyValue() {
return keyValue;
}
public void setKeyValue(int keyValue) {
this.keyValue = keyValue;
}
public String getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(String selectedUser) {
this.selectedUser = selectedUser;
}
public SimpleSelection getSelection() {
return selection;
}
public void setSelection(SimpleSelection selection) {
this.selection = selection;
}
public String setSelectUserFromCommand()
{
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXX-----I am here XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
//setSelectedUser((userInfo.get(getSelectedUserNum().intValue())).getUserFirstName());
return null;
}
public String submitRequest(){
System.out.println("hellooooooooo" + name);
if(name.equals("Pavan")){
userInfo = new Vector<GetUserInfo>();
GetUserInfo ui1 = new GetUserInfo("Pavan","Yenduri","Silver Maple CRT Brampton");
GetUserInfo ui2 = new GetUserInfo("Krishna","Yenduri","Silver Maple CRT Mississauga");
GetUserInfo ui3 = new GetUserInfo("Jaya","Yenduri","Silver Maple CRT India");
GetUserInfo ui4 = new GetUserInfo();
ui4.setUserFirstName("Suman");
ui4.setUserLastName("Tammana");
ui4.setUserAddress("Guntur India");
userInfo.add(ui1);
userInfo.add(ui2);
userInfo.add(ui3);
userInfo.add(ui4);
for(int i =1; i<200; i++){
System.out.println("Preparing User Info" + name);
userInfo.add(new GetUserInfo(concatenateDigits("Pavan",i),"Yenduri","Silver Maple CRT Brampton"));
}
// System.out.println("tabledata list" + tabledata.size());
return "welcome";
}
else{
errMsg = "Invalid Login";
actionMsg = "Dial Call center for more inforamtion";
return "failure";
}
}
/* public String takeSelection() {
// setSelectedCapital(null);
//table = new UIExtendedDataTable();
System.out.println("In Take Selection Method");
Iterator<Object> iterator = getSelection().getKeys();
System.out.println("In Take Selection Method 1");
while (iterator.hasNext()){
System.out.println("In Take Selection Method 2");
//Object key = iterator.next();
System.out.println("In Take Selection Method 3");
//if(key != null)
//{
System.out.println("In Take Selection Method 3A");
//table.setRowKey(key);
//System.out.println("In Take Selection Method 4");
//if (table.isRowAvailable()) {
//System.out.println("Key Value = "+((Integer) iterator.next()).toString());
setUserInfoSub(userInfo.get(((Integer) iterator.next()).intValue()));
//setKeyValue((Integer) iterator.next()).intValue());
//}
//}
}
return null;
} */
public String takeSelection() {
// setSelectedCapital(null);
System.out.println("In Take Selection Method");
Iterator<Object> iterator = getSelection().getKeys();
System.out.println("In Take Selection Method 1");
while (iterator.hasNext()){
System.out.println("In Take Selection Method 2");
Object key = iterator.next();
System.out.println("In Take Selection Method 3");
if(key != null)
{
System.out.println("In Take Selection Method 3A");
table.setRowKey(key);
//System.out.println("In Take Selection Method 4");
if (table.isRowAvailable()) {
//System.out.println("Key Value = "+((Integer) iterator.next()).toString());
//setKeyValue((Integer) iterator.next()).intValue());
setUserInfoSub((GetUserInfo) table.getRowData());
}
}
}
return null;
}
public GetUserInfo getUserInfoSub() {
return userInfoSub;
}
public void setUserInfoSub(GetUserInfo userInfoSub) {
this.userInfoSub = userInfoSub;
}
public String concatenateDigits(String x,int i)
{
StringBuilder sb = new StringBuilder(x);
return(sb.append(i)).toString();
}
public Vector<GetUserInfo> getUserInfo() {
return userInfo;
}
public void setUserInfo(Vector<GetUserInfo> userInfo) {
this.userInfo = userInfo;
}
public String getErrMsg() {
return errMsg;
}
public ArrayList<String> getTabledata() {
return tabledata;
}
public void setTabledata(ArrayList<String> tabledata) {
this.tabledata = tabledata;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public String getActionMsg() {
return actionMsg;
}
public void setActionMsg(String actionMsg) {
this.actionMsg = actionMsg;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}