cancel
Showing results for 
Search instead for 
Did you mean: 

Beginer-Problem with onNavigation

Former Member
0 Kudos

Hi together,

I have copied from here a example of calling a bapi and fill a table via ConnectionFactory.

I have a problem with the event onNavigation. The showing of the next page or next line didn't work.

I build another with JCo that works fine. Here is my code perhaps someone have an idea:

<b>Display.java</b>

public class Display extends PageProcessorComponent {

  private int visibleRow = 1;
  TableBean myBean;
	 
  public DynPage getPage(){
	return new DisplayDynPage();
  }
 
//  public static class DisplayDynPage extends JSPDynPage{
	public class DisplayDynPage extends JSPDynPage{ 
		 
	private TableBean myBean = null;
  
	public void doInitialization(){
	  IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();
	  Object o = profile.getValue("myBean");
	  if(o==null || !(o instanceof TableBean)){
		myBean = new TableBean();
		profile.putValue("myBean",myBean);
	  } else {
		  myBean = (TableBean) o;
	  }
	  
	  // fill your bean with data here...
	  IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
	  doJca(request);
	}
 
	public void doProcessAfterInput() throws PageException {
	}
	
	public void onNavigation(Event event) {
		if (event instanceof TableNavigationEvent) {
			TableNavigationEvent tne = (TableNavigationEvent) event;
			visibleRow = tne.getFirstVisibleRowAfter();
			if (myBean != null) {
				myBean.setVisibleRow(new Integer(visibleRow).toString());
			}
		}
	}	
 
	public void doProcessBeforeOutput() throws PageException {
	  this.setJspName("display.jsp");
	}
    
	private IConnection getConnection(
				IPortalComponentRequest request,
				String alias)
				throws Exception {
				IConnectorGatewayService cgService =
					(IConnectorGatewayService) PortalRuntime
						.getRuntimeResources()
						.getService(
						IConnectorService.KEY);
				ConnectionProperties prop =
					new ConnectionProperties(
						request.getLocale(),
						request.getUser());
				return cgService.getConnection(alias, prop);
 
			}
			
	public void doJca(IPortalComponentRequest request) {
 
	  IConnectionFactory connectionFactory = null;
	  IConnection client = null;
	  String rfm_name = "BAPI_COMPANYCODE_GETLIST";
 
	  try {	
 
		try {
			//pass the request & system alias
			//Change the alias to whatever the alias is for your R/3 system
			client = getConnection(request, "SAP_R3_SalesService");
		} catch (Exception e) {
				  System.out.println(
					  "Couldn't establish a connection with a target system.");
				  return;
		}
			
		/* 
		 * Start Interaction
		 * */
		IInteraction interaction = client.createInteractionEx();
		IInteractionSpec interactionSpec = interaction.getInteractionSpec();
		interactionSpec.setPropertyValue("Name", rfm_name);
 
		/*
		 * CCI api only has one datatype: Record
		 * */
		RecordFactory recordFactory = interaction.getRecordFactory();
		MappedRecord importParams = recordFactory.createMappedRecord("CONTAINER_OF_IMPORT_PARAMS");
 
		IFunctionsMetaData functionsMetaData = client.getFunctionsMetaData();
		IFunction function = functionsMetaData.getFunction(rfm_name);
 
		if (function == null) {
			System.out.println(
			"Couldn't find " + rfm_name + " in a target system.");
		  return;
		}
 
		/*
		 * How to invoke Function modules
		 * */
		System.out.println("Invoking... " + function.getName());
		MappedRecord exportParams = (MappedRecord) interaction.execute(interactionSpec, importParams);
 
 
		/*
		 * How to get structure values
		 * */
		IRecord exportStructure = (IRecord) exportParams.get("RETURN");
		String columnOne = exportStructure.getString("TYPE");
		String columnTwo = exportStructure.getString("CODE");
		String columnThree = exportStructure.getString("MESSAGE");
 
		System.out.println("  RETURN-TYPE    = " + columnOne);
		System.out.println("  RETURN-CODE    = " + columnTwo);
		System.out.println("  RETURN-MESSAGE =" + columnThree);
 
		/*
		 * How to get table values
		 * */
		IRecordSet exportTable = (IRecordSet) exportParams.get("COMPANYCODE_LIST");
 
		exportTable.beforeFirst(); // Moves the cursor before the first row. 
		while (exportTable.next()) {
		  String column_1 = exportTable.getString("COMP_CODE");
		  String column_2 = exportTable.getString("COMP_NAME");
		  System.out.println("  COMPANYCODE_LIST-COMP_CODE = " + column_1);
		  System.out.println("  COMPANYCODE_LIST-COMP_NAME = " + column_2);
		}
		//create the tableview mode in the bean
		myBean.createData(exportTable);
 
		/*
		 * Closing the connection
		 * */
		client.close();
 
	  } catch (ConnectorException e) {
		//app.putValue("error", e);
		System.out.println("Caught an exception: n" + e);
	  } catch (Exception e) {
		System.out.println("Caught an exception: n" + e);
	  }
 
	}
  }
}

The Bean:

public class TableBean implements Serializable {

	private String visibleRow = "1";
	private String selectedRows;
	private DefaultTableViewModel model; 
 
	public TableViewModel getModel() {
		return this.model;
	}
 
	public void setModel(DefaultTableViewModel model) {
		this.model = model;
	}
	
	// <b>get/setVisibleRow for tableView</b>
	public String getVisibleRow() {
		return this.visibleRow;
	}

	public void setVisibleRow(String visibleRow) {
		this.visibleRow = visibleRow;
	}	
	

	public void createData(IRecordSet table) {
		//this is your column names
		Vector column = new Vector();
		column.addElement("Company Code");
		column.addElement("Company Name");
 
		//all this logic is for the data part.
		Vector rVector = new Vector();
		try {
			table.beforeFirst();
			while (table.next()) {
				Vector data = new Vector();
				data.addElement(table.getString("COMP_CODE"));
				data.addElement(table.getString("COMP_NAME"));
				rVector.addElement(data);
 
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//this is where you create the model
		this.setModel(new DefaultTableViewModel(rVector, column));
 
	} 
 
}

The .jsp

<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="application" class="com.test.TableBean" />
<hbj:content id="myContext" >
  <hbj:page title="PageTitle">
   <hbj:form id="myFormId" >
   
   
  <hbj:tableView 
    id="myTableView1" 
    model="myBean.model" 
    design="ALTERNATING" 
    headerVisible="true" 
    footerVisible="true" 
    fillUpEmptyRows="true" 
    navigationMode="BYLINE" 
    selectionMode="MULTISELECT" 
    headerText="TableView example 1" 
    onNavigate="onNavigation" 
    visibleFirstRow="<%= myBean.getVisibleRow() %>" 
    visibleRowCount="10" 
    width="500 px" 
    />
 
   </hbj:form>
  </hbj:page>
</hbj:content>

Regards Thomas

Accepted Solutions (0)

Answers (1)

Answers (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Thomas,

probably many people will get shocked when reading this amount of implementation data which they might check against any error.

As a general advise, strip down your implementation, removing anything not needed to reproduce your problem. Often, by doing so, you will analyze the problem by yourself this way. And if not, you're still able to post a small amount of implementation data where the chances raise that someone will try to check the code (for now it looks small enough that one doesn't has to investigate too much time).

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

as you can see - I have marked this topic as solved by myself some hours later.

Thank you for your teaching about writing a topic. When I search in the forum I can see often that someone tell a question and other people asking for the code.

It's difficult to strip down the question and the code, in the case if I have no idea where the mistake is.

Hope this helps to understand.

Thomas

detlev_beutner
Active Contributor
0 Kudos

Hi Thomas,

> tell a question and other people asking for the code

Yes, of course, no question. Code helps to eliminate an error, but less code - helps more...

> It's difficult to strip down the question

> and the code, in the case if I have no idea

> where the mistake is.

Exactly that's the reason why you should start this way, for you will have a good chance to find out just the portion where the mistake is in. And - as written - even if not, you've done half the work otherwise maybe three people would do in parallel trying to help you (if you find three people trying to go through that many lines of code).

I don't know if you've ever opened a bug report at SUN, for example. They just would reject such a report. And even if it may be some work to locate the problem exactly, I have sympathy for such a procedure, for this is the part the questioner can do.

In the end, it helps you to understand, maybe to solve the issue, and if you don't solve it that way, it helps you to find more people willing to attend to this problem.

> I have marked this topic as solved

> by myself some hours later

Would be great to tell others what the error has been, so that also other people are able to learn from your experience.

Best regards

Detlev