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