intro to sap netweaver java

78
JSPs, Resources & Internationalization Leland Bartlett & Lavanya Devarajan

Upload: leland-bartlett

Post on 28-Nov-2014

2.977 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Intro To Sap Netweaver Java

JSPs, Resources & Internationalization

Leland Bartlett & Lavanya Devarajan

Page 2: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 2

WelcomeWelcomeWelcomeWelcome

!Target audience:" Anyone interested in understanding how to integrate Java Server Pages, other

resources (HTML, JavaScript and Applets), re-use classes and resources and the basics of internationalization.

!Skills Needed" Familiar with HTML, Java Server Pages" Familiar with Java Programming Concepts

Page 3: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 3

Using Java Server Pages

Using Resources

Internationalization

AgendaAgendaAgendaAgenda

Re-Using Resources & Classes

Page 4: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 4

Using Java Server Pages

Using Resources

Internationalization

Unit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & Internationalization

Re-Using Resources & Classes

Page 5: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 5

Using Java Server PagesUsing Java Server PagesUsing Java Server PagesUsing Java Server Pages

! JSPs & Java iView runtime

! JSPs & HTMLB

! Methods for JSP integration

Page 6: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 6

JSPsJSPsJSPsJSPs & Java iView runtime& Java iView runtime& Java iView runtime& Java iView runtime

myjsp.jsppublic class _sapportalsjsp_myjsp extends AbstractPortalComponent implements INonCachablePortalComponent{public void doContent(IPortalComponentRequest componentRequest,

IPortalComponentResponse aResponse) {

HttpServletRequest request = componentRequest.getServletRequest();JSPResponse response = new JSPResponse(aResponse);JspFactoryImpl factory = new JspFactoryImpl();…

The Java iView Runtime(PRT) provides support for Java Server Pages by compiling the JSPs to Portal Components (standard JSPs are compiled to HttpServlets). Compiled JSPs can be found under:

%TOMCAT_HOME%\webapps\irj\WEB-INF\plugins\portal\resources\<component name>\work

Note:

In order to compile the generated JSP pages at run-time the PRT needs the tools.jar file of the JDK. By default tools.jar is retrieved with the system property java.home defined by the JDK. If tools.jar is not in the java.home folder the property "jsp.addclasspath" in the file "workplace.properties" can be used to define the location of the tools.jar file.

%TOMCAT_HOME%\webapps\irj\WEB-INF\plugins\portal \system\properties

Compiled to AbstractPortalComponent

Page 7: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 7

JSPs & Java iView runtime JSPs & Java iView runtime JSPs & Java iView runtime JSPs & Java iView runtime ImpImpImpImplicit Objects

Original Request object.javax.servlet.http.HttpServletRequestrequestrequest

out

session

pageContext

response

componentRequest

JSP iView Object

javax.servlet.jsp.JspWriterout

Specific Portal implementation.

javax.servlet.http.HttpSessionsession

Not fully supportedjavax.servlet.jsp.PageContextpageContext

The Portal Component Response.

com.sapportals.portal.prt.IPortalComponentResponse

response

The Portal Component Request.

com.sapportals.portal.prt.IPortalComponentRequest

---

CommentsClass

Similar standard JSP

Object

Only available on Error Page.

Java.lang.Throwableexceptionexception

javax.servlet.ServletConfigconfigconfig

Directives: page, include supportedhttp://localhost:8080/irj/resources/com.sapportals.pdk.documentation.HowToDevelopMyPortalComponent/docs/JSP_Support.html

Page 8: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 8

Using Java Server PagesUsing Java Server PagesUsing Java Server PagesUsing Java Server Pages

! JSPs & Java iView runtime

! JSPs & HTMLB

! Methods for JSP integration

Page 9: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 9

JSPs & HTMLBJSPs & HTMLBJSPs & HTMLBJSPs & HTMLB

.JavaTextView t = new TextView();t.setText("Hello World!");

JSP:<hbj:textView text="Hello World"/>

Wrap components with custom JSP tags !

Page 10: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 10

JSPs & HTMLB JSPs & HTMLB JSPs & HTMLB JSPs & HTMLB Important Stuff!!!!

The physical location of the HTMLB tag library:" %TOMCAT_HOME%\ webapps\irj\services\htmlb\taglib

Using the Taglib Provided by Portal servicesAll JSP that are compiled into a Portal Component can use tag libraries provided by the PRT services (e.g. HTML-Business for Java (HTMLB)).

" The tag library definition file must be referenced in the property file of the Portal Component. $ tagLib.value =/SERVICE/htmlb/taglib/htmlb.tld

" Within the JSP file itself the tab library needs to be referenced$ At the beginning of the JSP file that is using the tag library the custom tag library

definition property has to be declared:$ <%@ taglib uri="tagLib" prefix="hbj" %>

Examples 1. Entries in property file default.properties to use the HTMLB service and tag

library:

2. Beginning of JSP file that is using HTMLB tags

Page 11: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 11

JSPs & HTMLBJSPs & HTMLBJSPs & HTMLBJSPs & HTMLB

<%@taglib uri="tagLib" prefix="hbj" %> <hbj:content id="myContext" > <hbj:page title="Hello World"> <hbj:form> <hbj:textView id="welcome"> <% welcome.setText("Hello World"); %> </hbj:textView> </hbj:form> </hbj:page> </hbj:content>

Hello world Hello world Hello world Hello world …………Using JSPsUsing JSPsUsing JSPsUsing JSPs

Page 12: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 12

Using Java Server PagesUsing Java Server PagesUsing Java Server PagesUsing Java Server Pages

! JSPs & Java iView runtime

! JSPs & HTMLB

! Methods for JSP integration

Page 13: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 13

Methods for JSP integrationMethods for JSP integrationMethods for JSP integrationMethods for JSP integration

! JSPDynpage

! JSPNative

Page 14: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 14

JSPDynPageJSPDynPageJSPDynPageJSPDynPage

! JSPDynpage Model

! Usage of Beans

! Example

Page 15: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 15

DynPageExtends PageProcessorComponent

JSPDynPage ModelJSPDynPage ModelJSPDynPage ModelJSPDynPage Model

AbstractPortalComponent implements IPortalComponent Interface

public abstract class PageProcessorComponent extends AbstractPortalComponent

PageProcessorComponent is the base class for Htmlb component that want to use the DynPage programming model within the Portal Runtime

JSPDynPage is a special implementation to enable usage of a DynPage in combination with JSPs in the Portal environment.

First step is to define a class that works as loader class - it inherits from the PageProcessorComponent. The created loader class executes the method getPage() and returns a unique value of the JSP DynPage

AbstractPortalComponentImplements

IPortalComponent Interface

PageProcessorComponentExtends AbstractPortalComponent

Introducing JSPDynPage Model

JSPDynPageExtends DynPage

Page 16: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 16

JSPDynpageJSPDynpageJSPDynpageJSPDynpage ModelModelModelModel

Request

doProcessAfterInput

JSPDynPage

PageProcessorComponent

doInitialization

doProcessBeforeOutput

Page 17: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 17

JSPDynPageJSPDynPageJSPDynPageJSPDynPage

! JSPDynpage Model

! Usage of Beans

! Example

Page 18: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 18

Usage of BeanUsage of BeanUsage of BeanUsage of Bean

For complex applications, it is suitable to separate not only the logic from the view, but also the data from the logic.

This leads to a Model-View-Controller architecture:

JspDynPage(Controller)

Data Bean (Model) JSP (View)

Request

Response

Page 19: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 19

Usage of BeanUsage of BeanUsage of BeanUsage of Bean

Bean The bean concept - reusable components that can be used in more than one software package - plays an important role in the portal component development. Portal components can use the beans to store and retrieve data. The JSP as well as the servlet (JSPDynPage, AbstractPortalComponent, DynPage, Native servlet) have read and write access to the bean so the bean can be used to transfer data between the JSP and the servlet.

Bean

%JSPDynPage and JSP data exchange using a Bean%A bean is used to get and set "dynamic" data. The JSPDynPage usually provides the bean with data and the JSP reads the data. The functionality of the basic example is extended by an input field that allows user input. The user input is stored in a bean and than displayed as text by a JSP program.

Following steps are necessary

%create a bean

%initialize the bean

%Access the bean in the JSP program (where bean data is required)

Page 20: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 20

Usage of BeanUsage of BeanUsage of BeanUsage of Bean

In a JSP page, one can access Java Bean objects using the tag

<jsp:useBeanid="object name"scope="application|session|request|page"class="class name" />

where" id is the name of the bean object in the compiled JSP" scope can be

$ application -> the bean is stored in the associated component profile object$ session -> the bean is stored in the associated HttpSession or

IPortalComponentSession object$ request -> the bean is stored in the associated HttpServletRequest object$ page -> the bean is stored in the associated javax.servlet.jsp.PageContext

object" class is the fully qualified classname of the bean

Page 21: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 21

JSPDynPageJSPDynPageJSPDynPageJSPDynPage

! JSPDynpage Model

! Usage of Beans

! Example

Page 22: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 22

ExampleOneExampleOneExampleOneExampleOne

Bean

2) OnSubmit

1) Initial form is displayed

3) Sends info to bean

4) Receives info from bean

5) Renders results

Page 23: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 23

ExampleOneExampleOneExampleOneExampleOne Parts

processForm.java (extends the JSPDynPage)

" Supplies the logic and calls the required JSP file" Handles the Event" Populates the bean with user input

Form.jsp " GUI Form for the end user to enter data

Result.jsp" Retrieves the data from the bean" Displays the data

DynPageNameBean.java" Allows to “Set” and “Get data

Page 24: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 24

ExampleOneExampleOneExampleOneExampleOne

Form.jsp

Result.jsp

processForm(Controller)

DynPageNameBean

Page 25: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 25

Writing the CodeWriting the CodeWriting the CodeWriting the Code

Note the location of the JSPs

Page 26: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 26

Writing the CodeWriting the CodeWriting the CodeWriting the Code Setting VariablesSetting VariablesSetting VariablesSetting Variables

;

Variables defined to evaluate which JSP file to process

Variables to store data

Page 27: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 27

Writing the CodeWriting the CodeWriting the CodeWriting the Code doInitialization

Sets the variable state to the value of INITITAL_STATE: Which had a static value of 0.

Page 28: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 28

Writing the CodeWriting the CodeWriting the CodeWriting the Code doProcessBeforeOutput

=INITIAL_STATE

Default location: private\pagelet

Page 29: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 29

Writing the CodeWriting the CodeWriting the CodeWriting the Code Form.JSP

FirstName

LastName

Email

Page 30: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 30

Writing the CodeWriting the CodeWriting the CodeWriting the Code HTMLB

Page 31: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 31

Writing the CodeWriting the CodeWriting the CodeWriting the Code Button

Page 32: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 32

Writing the CodeWriting the CodeWriting the CodeWriting the Code doProcessAfterInput

1

2

3

4

Page 33: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 33

Writing the CodeWriting the CodeWriting the CodeWriting the Code doProcessBeforeOutput

State=WELCOME_STATE

Page 34: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 34

Writing the CodeWriting the CodeWriting the CodeWriting the Code Result.JSP

Page 35: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 35

Writing the CodeWriting the CodeWriting the CodeWriting the Code The Bean

Sent here after the processForm reads the data inputed by the use and extracted from the input fields. This stores the data until it is requested for either examination or output.

Page 36: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 36

Writing the CodeWriting the CodeWriting the CodeWriting the Code Profile

Page 37: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 37

ExampleOne Recap

Page 38: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 38

Methods for JSP integrationMethods for JSP integrationMethods for JSP integrationMethods for JSP integration

! JSPDynpage

! JSPNative

Page 39: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 39

JSPNativeJSPNativeJSPNativeJSPNative

Profile

ComponentType=jspnativeJSP=Name of the JSP FiletagLib=/SERVICE/htmlb/taglib/htmlb.tldServicesReference=htmlb

&JSPNative:

A Portal Component is simply written as one JSP which is compiled to a Portal Component at runtime. Set the profile property ComponentType to jspnative

In the .par file, the JSP should be located under private\jsp\

(If folder JSP does not exist previously, it needs to be created)

Page 40: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 40

Using Java Server Pages

Using Resources

Unit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & Internationalization

Internationalization

Re-Using Resources & Classes

Page 41: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 41

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

Resources can either be basic resources like applets, scripts, images, static pages or more complex resources like xml files or even java properties files. If you want to use resources in your Portal component, you have to declare in your component where to find the resources with the help of methods from the IResource interface (Portal Runtime API)

Here are some supported resource types and their default scopes & extensions :

SCRIPT (Public) (.js)

STATIC_PAGE (Public) (.html)

APPLET (Public)

IMAGE (Public) (.gif)

JSP (Private) (.jsp)

XML (Private) (.xml)

PROFILE (Private) (.properties)

How to use resources:

Fetch the resource from the IPortalComponentRequest interface. This returns an Iresource object. Now you can add it to the response by calling the IPortalComponentResponse.addResource(IResource) method.

Page 42: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 42

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

Recommended file structure for Resources:

applet*

* Indicates that folder names can be custom names

Where are they stored when .par file is deployed?

Private: %TOMCAT_HOME%\webapps\irj\WEB-INF\plugins\portal\resources\<.par name>\

Public: %TOMCAT_HOME%\webapps\irj\resources\<.par name>\

Private

Public

images*html*

scripts*

profiles jsp (jspnative approach)pagelet (JspDynpage approach)xml*

Generated Web URL for Public Resources:http://localhost:8080/irj/resources/<par file name> /<Folder Name>/<File name>

You can use any folder names for those under the public folder. The Generated web url is purely for your information, you don’t need to know this as you will be using the iresourcemethods as you will see in the following slides.

Page 43: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 43

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

! Using Images & HTML Pages

! Using JavaScript

! Using Applets

! JSP again!

Page 44: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 44

Images: Under the Public folder, place your images (.gif) in any folder. Let us say we have an image under the following location:

public

images

garfield.gif

How to access it?

IResource garfield = componentrequest.getResource(IResource.IMAGE,"images/garfield.gif"); orIResource garfield = componentrequest.getResource(IResource.IMAGE,"images/garfield"); //since default extension is .gif

componentresponse.addResource(garfield);

orImage logo;

logo=new Image(garfield.getResourceInformation().getURL(req),"Logo");

myForm.addComponent(logo);

HTML: Under the Public folder, place your HTML (.html) in any folder. Let us say we have an HTML Page under the following location:

public

html

simple.html

Similarly, IResource myhtml= componentrequest.getResource(IResource.STATIC_PAGE,"html/simple.html");

componentresponse.addResource(myhtml);

Using Images & HTML PagesUsing Images & HTML PagesUsing Images & HTML PagesUsing Images & HTML Pages

Page 45: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 45

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

! Using Images & HTML Pages

! Using JavaScript

! Using Applets

! JSP again!

Page 46: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 46

Using JavaScriptUsing JavaScriptUsing JavaScriptUsing JavaScript

Some Methods:

1. Under the Public folder, create a folder say, scripts and place your .js file.

2. Create an HTMLB fragment and add to the class

3. Use <script></script> tags in JSP

Let us say we have a .js file named myscript.js containing a function runme()

IResource jsResource = componentRequest.getResource(IResource.SCRIPT, "script/myscript.js");

componentresponse.addResource(jsResource);

1. .js file in scripts folder

Page 47: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 47

Using JavaScriptUsing JavaScriptUsing JavaScriptUsing JavaScript

2. Create an HTMLFragment element (HTMLB element)String frag= new String(" <SCRIPT language=JavaScript>");

frag = frag + " function runme(siteName,userName,pwd){";

frag = frag+…

frag = frag + "}";

frag = frag + "</SCRIPT>";

HTMLFragment hf=new HTMLFragment(frag);//Special container for raw HTML. Note that using this class //might cause Browser dependencies

myForm.addComponent(hf);

3. Use <script> tags in JSP

<script>

function runme(){

}

</script>

Page 48: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 48

Using JavaScriptUsing JavaScriptUsing JavaScriptUsing JavaScript

If you want to access HTMLB elements via JavaScript, we recommend that you create you HTMLB elements in JSP and use Method 3

How to invoke the JavaScript function?Use htmlb elements that have onclient… methods- Button, Link, Drop Down List box

Mybutton.setOnClientClick(“runme()“)

or

via jsp<hbj:button id=“Mybutton" text="Click!" onClientClick=“runme()"/>

Or <script>runme();</script>

Page 49: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 49

Using JavaScriptUsing JavaScriptUsing JavaScriptUsing JavaScript

How to access HTMLB elements?

HTMLB provides access to the HTML IDs that are generated during runtime. After retrieving the IDs, you can generate your JavaScript by setting the correct IDs at runtime.

% Declare String variables at the start of the JSP that will hold the HTML IDs of the components you wish to access from JavaScript

% Use a method of the HTMLB com.sapportals.htmlb.rendering.PageContext class: pageContext.getParamIdForComponent(com.sapportals.htmlb.Componentcomponent). This method returns a String, and this String is the generated ID value for the given component.

% Write the script and use this generated ID to identify you HTMLB element% Invoke the script

Example: <%String compid="";%>

<hbj:inputField id="InputName" type="string" maxlength="100">

<% compid=myContext.getParamIdForComponent(InputName);%>

</hbj:inputField>

<hbj:button id="button1" text="Type&Click!" onClientClick="runme()"/>

Needs to be placed before </hbj:unputField>, to access

this inputField component

<script>

function runme() {

var myval=document.getElementById('<%=compid%>').value;

alert("You typed: "+myval); }

</script>

Page 50: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 50

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

! Using Images & HTML Pages

! Using JavaScript

! Using Applets

! JSP again!

Page 51: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 51

Using AppletsUsing AppletsUsing AppletsUsing Applets

How to access it?IResource myapplet= req.getResource(IResource.APPLET,"applet/");

String myurl=myapplet.getResourceInformation().getURL(req);

componentresponse.write("<applet name=\"ChompText\" archive=\"ChompText.zip\" codebase=\""+myurl+"\" code=\"ChompText.class\" width=250 height=55>");

componentresponse.write("<param name=\"text\" value=\"Java Boutique\">");

componentresponse.write("<param name=\"textcolor\" value=\"0000FF\">");

componentresponse.write("<param name=\"bgcolor\" value=\"FFFFFF\">");

componentresponse.write("</Applet>");

Under the Public folder, place your applet classes (..jar, .zip) in any folder. Let us say we have an applet ChompText.zip under the following location:

public

applet

ChompText.zip

zz

Page 52: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 52

Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

! Using Images & HTML Pages

! Using JavaScript

! Using Applets

! JSP again!

Page 53: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 53

Under the Private folder, place your JSPs (.jsp) in any folder. Let us say we have a jsp under the following location:

private

jsp

private.jsp

How to access it?IResource myjsp= componentrequest.getResource(IResource.JSP,"jsp/private.jsp");

componentrequest.dispatchRequest(myjsp,componentresponse);

orcomponentresponse.addResource(myjsp);

Using JSPsUsing JSPsUsing JSPsUsing JSPs

Note: JSPs as Web URLS is Not reccommended

Page 54: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 54

Using Java Server Pages

Using Resources

Unit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & Internationalization

Internationalization

Re-Using Resources & Classes

Page 55: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 55

ReReReRe----Using Resources & ClassesUsing Resources & ClassesUsing Resources & ClassesUsing Resources & Classes

! Re-Using Resources

! Re-Using Classes

Page 56: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 56

ReReReRe----Using ResourcesUsing ResourcesUsing ResourcesUsing Resources

You can reuse the resources from an existing .par file. You need to know the name of the .par file that contains the resources.

You can then get the resource from the componentrequest

Example:

IResource myimage= componentrequest.getResource(“SimpleExample.default",IResource.IMAGE,"images/SAPPortals_opt2.gif");

componentresponse.addResource(myimage);

Page 57: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 57

ReReReRe----Using Resources & ClassesUsing Resources & ClassesUsing Resources & ClassesUsing Resources & Classes

! Re-Using Resources

! Re-Using Classes

Page 58: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 58

ReReReRe----Using ClassesUsing ClassesUsing ClassesUsing Classes

How to re-use existing classes / External Libraries?

Method One

You have some classes (.jar file) in the lib folder of a .par file (A) that you want to use in another .par file (B)

You don't have to package the .jars again in the lib folder.

In the default.properties of the .par file (A) containing the .jar files, make the following entry:

SharingAccess=shared

This determines access to the package using the SharingReference property.

In the default.properties of the .par file (B), make the following entry:

SharingReference= .par file (A) name

This declares references to par file (A). This creates a sharing dependency, which requires that the .par file

(A) be uploaded beforehand in the PDK/Portal. For more than one reference, the list of package names must

be separated by a comma.

Page 59: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 59

ReReReRe----Using Classes Using Classes Using Classes Using Classes Some More Alternatives

How to re-use existing classes?Method Two

'Package as a Portal Service (Not in the scope of this class)

Method Three 'Include in class-path (Not Reccomended)

In the PDK, you can copy the .jar files to <Tomcat_home>\lib\apps. This will be loaded by the Portal runtime.

Migration to Enterprise Portal:Upload the .par file and create Java iView based on Master. Make sure you add the External libraries to the Servlet Engine's class-path

Tip for SAPJ2EE EngineCopy the .jar files to <SAPJ2EE_Home>\alone\additional-lib. Use the Config tool, Click on "alone" and edit the Java parameters.Example:-classpath".;.\system-lib\boot.jar;.\system-lib\jaas.jar;.\additional-lib\yourexternallib.jar;" This is a good step to follow if you are using any of the libraries in <SAPJ2EE_Home>\alone\additional-lib.

Disadvantages:

&Extra steps to be performed while migrating to other Enterprise Portals

&Classes are visible for all iViews

&Version conflicts can occur

Page 60: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 60

Using Java Server Pages

Using Resources

Unit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & InternationalizationUnit: JSPs, Resources & Internationalization

Internationalization

Re-Using Resources & Classes

Page 61: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 61

InternationalizationInternationalizationInternationalizationInternationalization

! Methodology

! Example

Page 62: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 62

MethodologyMethodologyMethodologyMethodology

Language support for Java iViews is by use of Java resource bundles. The Java iView runtime

provides API that allow an iView to communicate with the resource bundle containing the text to

display in the iView.

Know the ISO88559-1 Country Codes for language wanted to translate" Know the languages Enterprise Portal supported

Localization files need to exist under the folder private/classes

For each language wanted to translate a localization_xx.properties file needs to be created" German: localization_de.properties" Spanish: localization_es.properties" Default Language: localization.properties

If you want to name your translation files something else other than localization_xx.properties, there

must be a reference to it in the default.properties file.

Example: ExampleOne_de.properties, ExampleOne_es.properties

Specify localization file name in default.properties

ResourceBundleName=ExampleOne

Page 63: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 63

MethodologyMethodologyMethodologyMethodology

For Translating Strings

Access the language resource in your code

<% Import java.util.ResourceBundle; %>

<% ResourceBundle res = componentRequest.getResourceBundle();%>

<%Send_Button.setText(res.getString(“button.send"));%>

Sample Entry in localization_de.properties

button.send=Senden

For translating Personalization Parameter Names use the Description attribute

Any String

Page 64: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 64

Language SettingsLanguage SettingsLanguage SettingsLanguage Settings

To run the iView in a different language in the PDK, the following needs to be done

Locate the file workplace.properties

<Tomcat_Home>\webapps\irj\WEB-INF\plugins\portal\system\properties

Look for

request.mandatorylanguage=en

Remove it this entry (or comment #)

Now restart tomcat.

Change the Language for Internet Explorer (or)" The language has to be one that is supported by the portal

Change the user locale in Kmusers.properties

Precedence

1. Locale of the PDK (if specified in workplace.properties)

2. Locale of the user (if specified in kMusers.properties)

3. Locale of the client ( [i.e. if set up in (e.g.) IE under Tools/Internet Options/Languages...])

Page 65: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 65

Language SettingsLanguage SettingsLanguage SettingsLanguage Settings

Forcing a language in PDK• If the desired effect is for the PDK to be displayed in a particular language regardless of browser settings or user

setting then the • Workplace.properties

• request.mandatorylanguage=ISO Language requirement

If the entry in workplace.properties is removed:

• Language of Browser• PDK is displayed initially with this language• If language not supported, PDK defaults to English

• User Locale• Language changes based on logged on user’s locale in KMusers.properties• If no user locale is specified, then browser language is displayed

Example

Browser Setting = Spanish (es)

User Locale= German (de)

Results:" PDK HomePage= SpanishUser logs on" PDK = German" IView = German (If no specific localization file exists for german, the iView runs in the default

localization)

Page 66: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 66

Forcing PDK Mandatory LanguageForcing PDK Mandatory LanguageForcing PDK Mandatory LanguageForcing PDK Mandatory Language

To change the mandatory language for the PDK, this needs to be set. Note! It takes precedence

If you want the PDK to render content in the language of the browser or the language of the user, the variable described hereneeds to be commented out

Locate the file workplace.properties

<Tomcat_Home>\webapps\irj\WEB-INF\plugins\portal\system\properties

Page 67: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 67

User LocaleUser LocaleUser LocaleUser Locale

<Tomcat_Home>\webapps\irj\WEB-INF\plugins\portal\services\usermanagement\data

In the kmusers.properties file there is a list of the PDK users

Page 68: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 68

Language Setting in IELanguage Setting in IELanguage Setting in IELanguage Setting in IE

Page 69: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 69

InternationalizationInternationalizationInternationalizationInternationalization

! Methodology

! Example

Page 70: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 70

ExampleExampleExampleExample

Internationalize ExampleOne" The languages we will use are Spanish, German, English (default)" We will “Internationalize” the initial form Form.jsp.

$ Labels$ Text for the button

Page 71: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 71

ExampleOneExampleOneExampleOneExampleOne Form.jsp

Page 72: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 72

“Internationalize” Form.jsp: “Internationalize” Form.jsp: “Internationalize” Form.jsp: “Internationalize” Form.jsp: Labels

Uselabel_FirstName.setText(res.getString(“label.firstName”))But you need to place it before the closing tag of <hbj: label…>

This will be the string we will use in the localization file

Page 73: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 73

“Internationalize” Form.jsp: “Internationalize” Form.jsp: “Internationalize” Form.jsp: “Internationalize” Form.jsp: Button

Page 74: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 74

Localization FilesLocalization FilesLocalization FilesLocalization Files

" First we need to create a localization file (for a default language, say English) named localization.properties

" Create the localization.properties, localization_xx.properties, under the src folder of project. When you compile/create .par, the localization file will move to the right location under private/classes.

Page 75: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 75

Localization FilesLocalization FilesLocalization FilesLocalization Files

localization.properties

Page 76: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 76

Localization FilesLocalization FilesLocalization FilesLocalization Files

In order to access a String in German, Spanish and a default representation (say English),you would have the following structure:

label.firstName=Given Namelabel.lastName=Family Namelabel.email= Rapid Mailbutton.send=Fire it off!

label.firstName=Vornamelabel.lastName=Nachnamelabel.email= e-mail Adressebutton.send=Senden

label.firstName=il primo nomelabel.lastName=l'ultimo nomelabel.email= correo electrónicobutton.send=mande

Page 77: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 77

SummarySummarySummarySummary

You now know:

! Different methods to Integrate JSPs

! How to use resources such as JavaScripts, HTML & Applets

! How to re-use resources and classes

! How to use Language resource bundles to perform Internationalization

Page 78: Intro To Sap Netweaver Java

SAP AG 2002, Title of Presentation, Speaker Name 78

" No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

" Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

" Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered trademarks of Microsoft Corporation.

" IBM®, DB2®, DB2 Universal Database, OS/2®, Parallel Sysplex®, MVS/ESA, AIX®, S/390®, AS/400®, OS/390®, OS/400®, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere®, Netfinity®, Tivoli®, Informix and Informix® Dynamic ServerTM are trademarks of IBM Corporation in USA and/or other countries.

" ORACLE® is a registered trademark of ORACLE Corporation.

" UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.

" Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® and other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.

" HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

" JAVA® is a registered trademark of Sun Microsystems, Inc.

" JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.

" MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.

" SAP, SAP Logo, R/2, R/3, mySAP, mySAP.com and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are trademarks of their respective companies.

Copyright 2002 SAP AG. All Rights Reserved