Skip to Content
0
Former Member
Oct 28, 2005 at 06:41 AM

Error when working with TableView using JCA

23 Views

Hi sdns,

I am getting an iview rutnime error when working with Tableview using JCA. Here i am putting all my code, go thorugh it and tell me if any error is there.One more thing is Usermappping and all properties are set to system object.

Now you can throught he code which is followed by error also.

<u>Java file.</u>

public class DisplayComponent extends PageProcessorComponent {

public DynPage getPage() {

return new DisplayComponentDynPage();

}

public static class DisplayComponentDynPage extends JSPDynPage {

private JCATviewBean bean;

public void doInitialization() {

IPortalComponentProfile profile =

((IPortalComponentRequest) getRequest())

.getComponentContext()

.getProfile();

Object o = profile.getValue("myBean");

if (o == null || !(o instanceof JCATviewBean)) {

bean = new JCATviewBean();

profile.putValue("myBean", bean);

} else {

bean = (JCATviewBean) o;

}

// fill your bean with data here...

IPortalComponentRequest request =

(IPortalComponentRequest) this.getRequest();

doJca(request);

}

public void doProcessAfterInput() throws PageException {

}

public void doProcessBeforeOutput() throws PageException {

this.setJspName("Report.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, "MyIDES");

} 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

bean.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);

}

}

}

}

<u>Bena file</u>

package com.sap.JCA.bean;

import java.util.Vector;

import com.sapportals.connector.execution.structures.IRecordSet;

import com.sapportals.htmlb.table.DefaultTableViewModel;

import com.sapportals.htmlb.table.TableViewModel;

public class JCATviewBean {

public DefaultTableViewModel model;

public TableViewModel getModel() {

return this.model;

}

public void setModel(DefaultTableViewModel model) {

this.model = model;

}

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));

}

}

<b>JSP File:</b>

<%@ taglib uri="tagLib" prefix="hbj" %>

<jsp:useBean id="myBean" scope="application" class="com.sap.JCA.bean.JCATviewBean" />

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<hbj:form id="myFormId" >

<br>

<hbj:textView id = "tv1" text = "<b>TableView Example Using JCA</b> <br>"/>

<hbj:tableView

id="myTableView1"

model="myBean.model"

design="ALTERNATING"

headerVisible="true"

footerVisible="true"

fillUpEmptyRows="true"

navigationMode="BYLINE"

selectionMode="MULTISELECT"

headerText="TableView example1"

visibleFirstRow="1"

visibleRowCount="30"

width="500 px"

/>

</hbj:form>

</hbj:page>

</hbj:content>

<b>Error when Executing this component:</b><u></u>

Portal Runtime Error

<b>An exception occurred while processing a request for :

iView : N/A

Component Name : N/A

com/sapportals/portal/htmlb/page/PageProcessorComponent.

Exception id: 12:21_28/10/05_0173_94105150

See the details for the exception ID in the log file</b>

If anybody find the error please reply to this post.

Regards,

sireesha.