cancel
Showing results for 
Search instead for 
Did you mean: 

Rettriving changed data from <hbj:TableView>

Former Member
0 Kudos
68

Hi,

I have created a TableView, with 10 rows and 3 columns. All these fields are Input Fields, as set inside the TableViewBean. I am having problems retrieving the data from the JSP.

Here is the code for the TableViewBean model creation:


public void setModel(String[][] table) {
	String[] colNames = { "Username", "CostCentreGroup", "ReadWriteAccess" };
	model = new DefaultTableViewModel(table, colNames);
	
	model.setKeyColumn(1);
	
	TableColumn column = model.getColumn("Username");
	column.setTitle("Username");
	column.setType(TableColumnType.INPUT);
	
	column = model.getColumn("CostCentreGroup");
	column.setTitle("Cost Centre/Group"); 
	column.setType(TableColumnType.INPUT);
	
	column = model.getColumn("ReadWriteAccess");
	column.setTitle("Read/Write Access");
	column.setType(TableColumnType.INPUT);
	setExtab(table);
}

Here is the code for the JSP:


 <hbj:tableView
	id="myTableViewAdd"
	model="tvaBean.model"
	design="ALTERNATING"
	headerVisible="TRUE"
	footerVisible="TRUE"
	fillUpEmptyRows="TRUE"
	navigationMode="BYPAGE"
	selectionMode="NONE"
	visibleRowCount="10">
	 <% myTableViewAdd.useRowSelection(tvaBean.getOldTableView()); %>
</hbj:tableView>
<hbj:button
	id="add"
	text="Add Exception"
	onClick="onAddTableRows" />

Inside the Java, I have tried to retrieve the data that I enter on the screen, but I keep getting null pointer errors. When I retrieve the model from the bean, I get information, but just the old table, not the one that I had just modified on the screen.

I hope this is clearer than mud...

Cheers,

Kevin

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

figured it out...

Kevin

Former Member
0 Kudos

Hi Kevin,

Can you post what you did to get it to work? I'm having some issues with an iView that I'm developing using tableview as well...

Thanks a bunch

Umair

Former Member
0 Kudos

Hey Umair,

sorry for taking so long to get back... I was on vacation.

This is what I ended up doing.

JSP:


<hbj:tableView
	id="myTableView"
	model="tvBean.model"
	design="ALTERNATING"
	headerVisible="TRUE"
	footerVisible="TRUE"
	fillUpEmptyRows="FALSE"
	navigationMode="BYPAGE"
	selectionMode="MULTISELECT"
	visibleRowCount="10"
	visibleFirstRow="<%=tvBean.getVisibleFirstRow()%>"
	onNavigate="onDetailTableNavigate">
	<% myTableView.useRowSelection(tvBean.getOldTableView()); %>
	<% myTableView.setUserTypeCellRenderer(new TableViewCellRenderer()); %>
</hbj:tableView>

And in my bean:


public void setModel(String[][] table) {
	String[] colNames = { "Username", "CostCentreGroup", "ReadWriteAccess" };
	model = new DefaultTableViewModel(table, colNames);

	model.setKeyColumn(1);

	TableColumn column = model.getColumn("Username");
	column.setTitle("Username");
	column.setType(TableColumnType.TEXT);
	column.setEncode(true);
		
	column = model.getColumn("CostCentreGroup");
	column.setTitle("Cost Centre/Group"); 
	column.setType(TableColumnType.INPUT);
		
	column = model.getColumn("ReadWriteAccess");
	column.setTitle("Read/Write Access");
	column.setType(TableColumnType.USER);
	setExtab(table);
}

And lastly, when you want to update R/3 with values that you have changed in your tableView, add the following to your event:


//get table from session
TableView tv = (TableView) this.getComponentByName("myTableView");
updateTableContent(tv.getVisibleFirstRow(), tv.getVisibleLastRow());

and this method outside the event:


public void updateTableContent(int firstrow, int lastrow) {

	int lastrow_model = lastrow;
	if (lastrow_model > tvBean.getModel().getRowCount()) {
		lastrow_model = tvBean.getModel().getRowCount();
	}

	int loopcount = 0;
	for (int i = firstrow; i <= lastrow_model; i++) {
		loopcount = loopcount + 1;

		AbstractDataType data_box = context.getDataForComponentId("myTableView", "Username", loopcount);
		if (data_box != null)
			tvBean.getModel().setValueAt(data_box, i, 1);

		AbstractDataType data_mil = context.getDataForComponentId("myTableView", "CostCentreGroup", loopcount);
		if (data_mil != null)
			tvBean.getModel().setValueAt(data_mil, i, 2);

		AbstractDataType data_inf = context.getDataForComponentId("myTableView", "ReadWriteAccess", loopcount);
		if (data_inf != null)
			tvBean.getModel().setValueAt(data_inf, i, 3);
	}
}

Phew, I hope this helps.

Cheers,

Kevin

Former Member
0 Kudos

thanks Kevin,

this is great...hope you had a wonderful vacation

Umair

andjelka_radjen
Participant
0 Kudos

Kevin,

Can you please put the code for you BEAN in here too. Thanks, Angie.

Former Member
0 Kudos

Hi Angie,

This is the main code of the bean. The rest of it is just get and set methods.


public ReadWriteBean(String[][] header, String[][] body) {
	int numrows = 0;
	//+1 to the size so the number of columns includes the BSP App name column
	int size = header.length + 1;
	setRwSize(size);
	String[] colNames = new String[size];
	TableColumn column;

	for (int j = 0; j < size; j++) {
		colNames[j] = columnName;
	}

	model = new DefaultTableViewModel(body, colNames);

	model.setKeyColumn(1);

	column = model.getColumn(colNames[0]);
	column.setTitle("Your title");
	column.setType(TableColumnType.TEXT);
	column.setEncode(false);

	for (int j = 1; j < size; j++) {
		column = model.getColumn(colNames[j]);
		column.setTitle("more titles"));
		column.setType(TableColumnType.USER);
	}
	setModel(model);
	setAuth(body);
}

Hope this helps...

Kevin