on 04-19-2007 8:45 AM
Hi All,
I am using JSPDynpage to access RFC from SAP. Here is the Code.
<u>JSP Page:</u>
<jsp:useBean id=" myBean" scope="request" class="com.sap.connector.RfcBean" />
<hbj:content id="myContext" >
<hbj:page title="PageTitle">
<hbj:form id="myFormId" >
<hbj:textView
text="Sample Text"
id="tv1"
design="HEADER2" >
</hbj:textView>
Hi!!!! hello world <%=myBean.getCW1()%> <%=myBean.getCW2()%>
<br>
<hbj:textView
text="<%=myBean.getCW2()%>"
id="tv1"
design="HEADER2"
encode="false">
</hbj:textView>
</hbj:form>
</hbj:page>
</hbj:content>
<u>Code for Java File:</u>
package com.sap.connector;
import javax.resource.cci.MappedRecord;
import javax.resource.cci.RecordFactory;
import com.sapportals.connector.connection.IConnection;
import com.sapportals.connector.execution.functions.IInteraction;
import com.sapportals.connector.execution.functions.IInteractionSpec;
import com.sapportals.connector.execution.objects.language.IFunction;
import com.sapportals.connector.execution.structures.IRecordSet;
import com.sapportals.connector.execution.structures.IStructureFactory;
import com.sapportals.connector.metadata.functions.IFunctionsMetaData;
import com.sapportals.htmlb.page.DynPage;
import com.sapportals.htmlb.page.PageException;
import com.sapportals.portal.htmlb.page.JSPDynPage;
import com.sapportals.portal.htmlb.page.PageProcessorComponent;
import com.sapportals.portal.ivs.cg.ConnectionProperties;
import com.sapportals.portal.ivs.cg.IConnectorGatewayService;
import com.sapportals.portal.ivs.cg.IConnectorService;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.runtime.PortalRuntime;
public class JSPPage extends PageProcessorComponent {
public DynPage getPage() {
return new JSPPageDynPage();
}
public static class JSPPageDynPage extends JSPDynPage {
private RfcBean myBean;
public void doInitialization() {
myBean = new RfcBean();
((IPortalComponentRequest) getRequest())
.getServletRequest()
.setAttribute(
"myBean",
myBean);
IPortalComponentRequest request =
(IPortalComponentRequest) this.getRequest();
// fill your bean with data here...
myBean.setCW1((String)"MURALI");
try {
//Alias is the name of the alias you defined in portal for SAP system
getSAPdata(getConnection(request, "P35"));
} catch (Exception e) {
e.printStackTrace();
}
this.setJspName("JSPPage.jsp");
}
public void doProcessAfterInput() throws PageException {
}
public void doProcessBeforeOutput() throws PageException {
}
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);
}
private void getSAPdata(IConnection client) throws Exception {
IInteraction interaction = client.createInteractionEx();
IInteractionSpec interactionSpec = interaction.getInteractionSpec();
interactionSpec.setPropertyValue("Name", "YKM_BROWSER");
RecordFactory recordFactory = interaction.getRecordFactory();
MappedRecord importParams = recordFactory.createMappedRecord("IMPORT_PARAMS");
MappedRecord exportParams =(MappedRecord) interaction.execute(interactionSpec, importParams);
myBean.setCW2((String)exportParams.get("PERSA"));
myBean.setCW1("Dummy Text");
client.close();
}
}
}
<u>Code for Bean FIle</u>
package com.sap.connector;
import java.io.Serializable;
public class RfcBean implements Serializable {
private String CW1;
private String CW2;
/**
* @return
*/
public String getCW1() {
return CW1;
}
/**
* @return
*/
public String getCW2() {
return CW2;
}
/**
* @param string
*/
public void setCW1(String string) {
CW1 = string;
}
/**
* @param string
*/
public void setCW2(String string) {
CW2 = string;
}
}
Now when I try to hardcode 'Sample Text' in JSP page, I dont see it in output.
The bean always give me Null for getCW1() and getCW2() even though I have hardcoded 'Dummy Text' in the java program. Can anyone help me out!!
I am accessing an RFC YKM_BROWSER which has only one export parameter PERSA. Hope my way of accessing this ouptut is correct in the code.
Regards
<b>Murali</b>
Hi,
i dont know if its just a typo in your post, but you are registering the bean under the key "myBean" and reading it from " myBean".
Is this fixed in your code?
Jan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.