enterprise java beans in interactive forms.pdf

11
 Enterpris e Java Bea ns i n Interactiv e Forms SDN Communi ty Contribution (This i s no t an offi cial SAP document.) Disclaimer & Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held li able for any damages caused by us ing or misusing the information, code or methods suggested in this document, and anyone usi ng these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. © 2005 SAP AG The SAP Developer Network: http://sdn.sap.com 1

Upload: sumitml8871

Post on 08-Oct-2015

18 views

Category:

Documents


0 download

DESCRIPTION

Enterprise Java Beans in Interactive Forms

TRANSCRIPT

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    1/11

    Enterprise Java Beans in InteractiveForms

    SDN Community Contribution

    (This is not an offi cial SAP document.)

    Disclaimer & Liability Notice

    This document may discuss sample coding or other information that does not include SAP official interfacesand therefore is not supported by SAP. Changes made based on this information are not supported and canbe overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or methodssuggested in this document, and anyone using these methods does so at his/her own risk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content ofthis technical article or code sample, including any liability resulting from incompatibility between the contentwithin this document and the materials and services offered by SAP. You agree that you will not hold, or seekto hold, SAP responsible or liable with respect to the content of this document.

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 1

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    2/11

    Enterprise Java Beans in InteractiveForms

    Appl ies To:

    SAP Technology, SAP Web AS 7.00, Adobe Interactive Forms

    Summary

    This article explains how to access an Enterprise Java Beans (EJB) from an Interactive Form (Adobe PDF)used in a Web Dynpro application.

    By : Sangeeta Bhandari

    Company: SAP Labs India Pvt. Ltd.

    Date: 06 Sep 2005

    Table of Contents

    Applies To:........................................................................................................................................2

    Summary ..........................................................................................................................................2

    Table of Contents .............................................................................................................................2

    Prerequisite ......................................................................................................................................2

    10-Step How-to.................................................................................................................................3

    Author Bio.......................................................................................................................................11

    Prerequisite

    This project uses the sample Quick Car Rental Application. This project has an EJB called"QuickOrderProcessorBean" that has three methods:

    viewActiveBookings(),

    saveBooking()

    cancelBooking()

    We will be calling each of these methods from our Web Dynpro application, take input, and display the outputin the Interactive Form.

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 2

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    3/11

    Enterprise Java Beans in InteractiveForms

    10-Step How-to

    1. Create a new Web Dynpro Project with an Interactive Form.

    2. To resolve bean classes at design time: Add a project reference to HelperClasses andQuickCarRentalEJB to the Java Build Path in Project Properties.

    3. To resolve bean classes at runtime: Add a sharing reference namedsap.com/QuickCarRentalApplication to the Web Dynpro Reference in the project properties.

    4. Context: Create the following context nodes and attributes.

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 3

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    4/11

    Enterprise Java Beans in InteractiveForms

    The attribute pdfSource should have the data type binary. All other attributes should be of data typestring. The properties of the Interactive Form are dataSource=booking, pdfSource=pdfSource.

    5. Initialization: In the wdDoInit() of the view say, EJBView, add the following lines:

    I Pr i vat eEJ BVi ew. I Booki ngNode bNode = wdCont ext . nodeBooki ng( ) ;

    for ( int i = 0; i < 1; i ++) { I Pri vat eEJ BVi ew. I Booki ngEl ementbEl e = bNode. cr eat eBooki ngEl ement ( ) ;

    bEl e. set I d(" " ) ;

    bEl e. set Vehi cl eType( "" ) ;

    bEl e. set Pi ckupLocat i on( "" ) ;

    bEl e. set Dr opof f Locat i on( "" ) ;

    bEl e. set Dat eFrom( "" ) ;

    bEl e. set Dat eTo( "" ) ;

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 4

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    5/11

    Enterprise Java Beans in InteractiveForms

    bEl e. set Pr i ce( "") ;

    bNode. addEl ement ( bEl e) ;

    }

    try {

    I ni t i al Cont ext ctx = new I ni t i al Context ( ) ;

    Qui ckOr der Pr ocessorLocal Home l ocal Home =

    ( Qui ckOr derPr ocessor Local Home) ct x. l ookup(

    "l ocal ej bs/ sap. com/ Qui ckCar Rent al Appl i cat i on/ Qui ckOr der Processor Bean") ;

    Qui ckOr der ProcessorLocal l ocal = l ocal Home. cr eat e( ) ;

    Qui ckBooki ngModel [ ] r esul t = l ocal . vi ewAct i veBooki ngs( ) ;

    f or mat Booki ngs( r esul t ) ;

    } catch ( Except i on e) {

    wdComponentAPI . get MessageManager ( ) . r epor t Except i on(

    "except i on i s : " + e. t oSt r i ng( ) ,true) ;

    e. pr i nt St ackTr ace( ) ;

    }

    I Pr i vat eEJ BVi ew. I Booki ngNode bNode1 = wdCont ext . nodeBooki ng( ) ;

    for ( int j = 0; j < Const ant s. LOCATI ON. l engt h; j ++)

    {

    I Pr i vat eEJ BVi ew. I Booki ngEl ement bEl e1 = bNode. cr eat eBooki ngEl ement ( ) ;

    bEl e1. set Dr opof f Locat i on( Const ant s. LOCATI ON[ j ] ) ;

    bEl e1. set Pi ckupLocat i on( Const ant s. LOCATI ON[ j ] ) ;

    bNode1. addEl ement ( bEl e1) ;

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 5

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    6/11

    Enterprise Java Beans in InteractiveForms

    }

    6. Calling method viewActiveBookings() actually implementing some part of it.

    private void f ormatBooki ngs( Qui ckBooki ngModel [ ] booki ngs) {

    Dat eFormat dat eFormat = Dat eFormat . get Dat eI nst ance( Dat eFormat . MEDI UM) ;

    I Pr i vat eEJ BVi ew. I DataNode dNode = wdCont ext . nodeData( ) ;

    for ( int i = 0; i < booki ngs. l engt h; i ++) {

    I Pri vat eEJ BVi ew. I Dat aEl ement dEl e =

    dNode. cr eat eDataEl ement ( ) ;

    dEl e. set I d( booki ngs[ i ] . get Booki ngI d( ) ) ;

    dEl e. set Vehi cl eType( booki ngs[ i ] . get Vehi cl eType( ) ) ;

    dEl e. set Pi ckupLocat i on( booki ngs[ i ] . get Pi ckupLocat i on( ) ) ;

    dEl e. set Dr opof f Locat i on( booki ngs[ i ] . get Dr opof f Locat i on( ) ) ;

    dEl e. set Dat eFrom( booki ngs[ i ] . get Dat eFrom( ) ) ;

    dEl e. set Dat eTo( booki ngs[ i ] . get Dat eTo( ) ) ;

    dEl e. set Pr i ce( booki ngs[i ] . get Pr i ce( ) ) ;

    dNode. addEl ement ( dEl e) ;

    }

    7. In the Adobe LiveCycle Designer:

    a. Click Edit from the context menu of the Interactive Form.b. Drag and Drop a Subform from the Standard Library.c. Set its type to Flow Content and the Flow Direction to Table on the Object tab.d. Insert another subform in the above subform, and set its type to Flow Content and the Flow

    Direction to Table Row.e. On the binding tab for this subform, check the checkbox for "Repeat subform for each Data

    Item", and in Min Count you can specify at a time how many rows you want to display.

    f. Now place your UI elements for the Data View into this subform.g. Format these UI elements as required. Set the default binding on the Object tab.

    8. Calling method saveBooking():

    The above table will display the existing Reservations. Now add a new subform for addingreservations. Bind the UI elements with the attributes of the Booking context node. Add a Submit toSAP button, and in its event handler add the following code:

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 6

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    7/11

    Enterprise Java Beans in InteractiveForms

    try {

    I ni t i al Cont ext ctx = new I ni t i al Context ( ) ;

    Qui ckOr der Pr ocessorLocal Home l ocal Home =

    ( Qui ckOr derPr ocessor Local Home) ct x. l ookup(

    "l ocal ej bs/ sap. com/ Qui ckCar Rent al Appl i cat i on/ Qui ckOr der Processor Bean") ;

    Qui ckOr der ProcessorLocal l ocal = l ocal Home. cr eat e( ) ;

    l ocal . saveBooki ng(

    wdCont ext . cur r ent Booki ngEl ement ( ) . getVehi cl eType( ) ,

    wdCont ext . curr ent Booki ngEl ement ( ) . getDateFr om( ) ,

    wdCont ext . cur r ent Booki ngEl ement ( ) . getDat eTo( ) ,

    wdCont ext . cur r ent Booki ngEl ement ( ) . getPi ckupLocat i on( ) ,

    wdCont ext. cur r ent Booki ngEl ement ( ) . get Dr opof f Locat i on( ) ) ;

    } catch ( Except i on e) {

    wdComponentAPI . get MessageManager ( ) . r epor t Except i on(

    "except i on i s : " + e. t oSt r i ng( ) ,true) ;

    e. pr i nt St ackTr ace( ) ;

    }

    wdCont ext . nodeDat a( ) . i nval i dat e( ) ;

    try {

    I ni t i al Cont ext ctx = new I ni t i al Context ( ) ;

    Qui ckOr der Pr ocessorLocal Home l ocal Home =

    ( Qui ckOr derPr ocessor Local Home) ct x. l ookup("l ocal ej bs/ sap. com/ Qui ckCar Rent al Appl i cat i on/ Qui ckOr der Processor Bean") ;

    Qui ckOr der ProcessorLocal l ocal = l ocal Home. cr eat e( ) ;

    Qui ckBooki ngModel [ ] r esul t = l ocal . vi ewAct i veBooki ngs( ) ;

    f or mat Booki ngs( r esul t ) ;

    } catch ( Except i on e) {

    wdComponent API . getMessageManager( ) . r eport Except i on( "except i on i s: " + e. t oSt r i ng( ) ,true) ;

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 7

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    8/11

    Enterprise Java Beans in InteractiveForms

    e. pr i nt St ackTr ace( ) ;

    }

    wdCont ext . cur r ent Booki ngEl ement ( ) . set I d( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . setVehi cl eType( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . set Pi ckupLocat i on( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . set Dr opof f Locat i on( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . setDat eFrom( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . setDat eTo( "" ) ;

    wdCont ext . cur r ent Booki ngEl ement ( ) . set Pri ce( "" ) ;

    9. Calling method cancelBooking(): Add a checkbox for a table row and bind it to the checkDeleteattribute of the data context node. Add a Check Fields button to Cancel Reservations. In its eventhandler, add the following code:

    St r i ng s="Check ";

    I Pr i vat eEJ BVi ew. I DataNode dNode = wdCont ext . nodeDat a( ) ;

    try {

    I ni t i al Cont ext ctx = new I ni t i al Context ( ) ;

    Qui ckOr der Pr ocessorLocal Home l ocal Home =

    ( Qui ckOr derProcessor Local Home) ct x. l ookup(

    "l ocal ej bs/ sap. com/ Qui ckCar Rent al Appl i cat i on/ Qui ckOr der Processor Bean") ;

    Qui ckOr der ProcessorLocal l ocal = l ocal Home. cr eat e( ) ;

    for ( int i = 0; i < dNode. si ze( ) ; i ++) {

    I WDNodeEl ement e=dNode. get El ement At ( i ) ;

    St r i ng s1=( St r i ng) e. get At t r i but eVal ue( "checkDel et e") ;

    if (s1!=null&&s1. equal s( "1") )

    {

    s=s+s1+"( "+( St r i ng) e. get At t r i but eVal ue( " i d") +") ";

    l ocal . cancel Booki ng( ( St r i ng) e. get At t r i but eVal ue( "i d") ) ;

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 8

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    9/11

    Enterprise Java Beans in InteractiveForms

    }

    else

    s=s+"0";

    }

    } catch ( Except i on e) {

    wdComponentAPI . get MessageManager ( ) . r epor t Except i on(

    "except i on i s : " + e. t oSt r i ng( ) ,true) ;

    e. pr i nt St ackTr ace( ) ;

    }

    wdCont ext. nodeDat a( ) . i nval i dat e( ) ;

    try {

    I ni t i al Cont ext ctx = new I ni t i al Context ( ) ;

    Qui ckOr der Pr ocessorLocal Home l ocal Home =

    ( Qui ckOr derProcessor Local Home) ct x. l ookup(

    "l ocal ej bs/ sap. com/ Qui ckCar Rent al Appl i cat i on/ Qui ckOr der Processor Bean") ;

    Qui ckOr der ProcessorLocal l ocal = l ocal Home. cr eat e( ) ;Qui ckBooki ngModel [ ] r esul t = l ocal . vi ewAct i veBooki ngs( ) ;

    f or mat Booki ngs( r esul t ) ;

    } catch ( Except i on e) {

    wdComponentAPI . get MessageManager( ) . r epor t Except i on(

    "except i on i s : " + e. t oSt r i ng( ) ,

    true) ;

    e. pr i nt St ackTr ace( ) ;

    }

    10. Build, Deploy, and Run the application.

    Screenshot of the QuickCarRental application:

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 9

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    10/11

    Enterprise Java Beans in InteractiveForms

    Screenshot of the QuickCarRental Application inside an Interactive Form in Web Dynpro.

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 10

  • 5/19/2018 Enterprise Java Beans in Interactive Forms.pdf

    11/11

    Enterprise Java Beans in InteractiveForms

    Author Bio

    Sangeeta Bhandari has been working as a QM Specialist in NetWeaver Operations Teams in SAP LabsIndia, Bangalore since June, 2005. She has also worked with the same team for 1 year as an intern whilestudying. She has been working with Web Services, Interactive Forms based on Adobe software, WebDynpro, J2EE with SAP NetWeaver Developer Studio. She is also working with Enterprise Portal.

    2005 SAP AG The SAP Developer Network: http://sdn.sap.com 11