Archive

Archive for the ‘Web Dynpro’ Category

Web Dynpro Java – how to send email

October 25th, 2010 2 comments

The Javamail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. The JavaMail API is available as an optional package for use with Java SE platform and is also included in the Java EE platform.

Below two JAR file is needed to send emails in the web dynpro application:

mail.jar – 1.2
activation.jar – 1.0

You can download these jar files in oracle web site – www.oracle.com. For how to use the external library, please refer to Web Dynpro Java – use external library.

Below codesnip shows how to send email using JavaMail API. This logical can be called in any place of web dynpro application to send email notification. In the intranet environment, the SMTP server doesn’t require the authentication, but in the internet, the authentication is required. You need to add the authentication check logic according to your SMTP setting. The default SMTP port is 25.

Read more…

Web Dynpro Java – generate the excel file

October 25th, 2010 No comments

Download business data as a excel file is critical for business users to view,modify and manipulate the data freely. In this example, I use Apache POI to generate the excel file in web dynpro application.

The Apache POI Project’s mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. For more information, please visit the official home page – http://poi.apache.org/.

Current stable version of POI is 3.6, but it requires JDK 1.5 and higher version to use it. Because NW7.0 is based on JDK 1.4.2, I have to choose POI version 3.2.

For more information on how to use external library, please refer to my another post – Web Dynpro Java – use external library.

Read more…

Web Dynpro Java – use external library

October 25th, 2010 No comments

During the web dynpro development, the developer might need to utilize external libraries to realize some specific activities, such as generating excel files, sending emails. Generally there are two methods to adding the external library into the web dynpro application.

1. Package the external libraries into the web dynpro application

Below steps works well in NW7.0. I didn’t test it in NW CE7.1 and not sure whether it works or not in NW CE7.1.

Read more…

Web Dynpro – Download File

October 17th, 2009 4 comments

Download file is a common requirement in custom web dynpro application. As we all know, in web dynpro we cannnot direct enter html code. Everything is hidden behind the model which designed using NWDS. Web dynpro provides an UI element named ‘FileDownload‘. Below is the steps for how to use FileDownload in web dynpro.

Step 1. Create needed value node and value attribute.

Create a new value node named ‘Resource’ and an value attribute named ‘resource’. The value attribute has the type of ‘com.sap.ide.webdynpro.uielementdefinitions.Resource‘. Then bind this attribute to the FileDownload UI element.

resource

Step 2. Initialize the the value attribute.

You need to initialize the resource attribute before showing the FileDownload element. In a common case, the file content is read from the SAP backend system, like ERP, Solution Manager, etc. A function module should be created in the backend system. The remote function module stores the file content in an internal table with type RAW. The ABAP dictionary type RAW will be mapped to java build-in type binary when import the RFC into a web dynpro model.

Below code is used to initialize the resource attribute.

    //get the file content from backend system
    wdThis.wdGetProj_evalController().executeZ_Get_Doc_Content_Input(classID , objID);
 
    //put all the file content in a byte array.
    byte[] binFile = new byte[0];
    for(int n = 0; n <; wdContext.nodeFile_Content_Binary().size(); n++){
        binFile = concat(binFile, wdContext.nodeFile_Content_Binary().getFile_Content_BinaryElementAt(n).getLine());     
    }     
    //initialize the resource attribute 	
    if(wdContext.nodeE_File_Attr().size() >; 0){
	String filename = wdContext.nodeE_File_Attr().currentE_File_AttrElement().getFile_Name();
	String fileext = "";
	if(filename.lastIndexOf(".") >; 0){
	    fileext = filename.substring(filename.lastIndexOf(".") + 1 , filename.length());
	    fileext = fileext.toUpperCase();
    }
 
    //reset the file name
    filename = wdContext.nodeEt_Saeval_Str().currentEt_Saeval_StrElement().getTitle_Dbl() + "." + fileext.toLowerCase();
    wdContext.nodeGlobal_Variant().currentGlobal_VariantElement().setFilename(filename);
 
    ByteArrayInputStream bais = new ByteArrayInputStream(binFile);
 
    WDWebResourceType resourceType = WDWebResourceType.getWebResourceTypeForFileExtension(
							fileext);
 
    if(resourceType != null){
    wdContext.nodeResource().currentResourceElement().setResource(
			WDResourceFactory.createResource(
					bais,
					filename,
					WDWebResourceType.getWebResourceTypeForFileExtension(
						fileext),
					false));
    }

After completing above code, the FileDownload can be used to download file.

Web Dynpro – Message Handling

October 17th, 2009 No comments

In the ABAP program, we can use ABAP statement to show the error, warning or information message to the user. In Web dynpro for Java, It is also very convenience to handle the message.

Step 1. Add the message  in the message pool under your component.

There are for message types: standard, warning, error, text. If you want to add the parameter in the message text, you should put parameter holder like {0},{1}. After add the message to the message pool. The NWDS will automatic generate a java class like ‘IMessage<component name>’.

message

Step2. After add message, you can report the message using below Java code in the method.

  IWDMessageManager manager = wdComponentAPI.getMessageManager();
  //if some condition meets
  if(...){
  manager.reportMessage(IMessageProj_eval.MISS_PARAMETER,
			new Object[]{"Project Id"},
			true);
    return false;
  }

You can also create corresponding properties files for other language. The web dynpro will automatic choose the language according to the language setting in your browser.

Web Dynpro – Pop up a new window

October 17th, 2009 1 comment

In some case, we need to pop up a new window to show some more data. Here, I will introduce how to pop up a new window using web dynpro Java.

Step 1. Create a new window in your WD component.
window_s1

Step 2. Embeded a view or viewset in the widow.

Step 3. Create a new value node and value attribute.

This value node is used to store the reference to the window instance. The value attribute should be the type of ‘com.sap.tc.webdynpro.services.session.api.IWDWindow‘.

Step 4. Add code to pop up a new window in an action.

Add below code to your action to show your pop up window.

    //show the pop up window
	IWDWindowInfo windowInfo = wdComponentAPI.getComponentInfo().findInWindows("Download");
	IWDWindow myWindow = wdComponentAPI.getWindowManager().createModalWindow(windowInfo);
	wdContext.currentPopUpElement().setDownLoadWindow(myWindow);
	myWindow.setWindowSize(300 , 80);
	myWindow.setWindowPosition(WDWindowPos.CENTER);
	myWindow.show();

In the pop up window, there is a close button to close current pop up window. You should add below code to the close action.

	wdContext.nodePopUp().currentPopUpElement().getDownLoadWindow().destroyInstance();

Now everything is ready. You can use the pop up screen in your own web dynpro applicaiton. Enjoy it:-)

Web Dynpro – Use Icons

October 17th, 2009 No comments

In the web dynpro applicaition, we always find some very cool icons. This post will tell you how to use the SAP standard icons or your custom icons in the custom web dynpro applications.

1. Use SAP standard icons

First, find a list of SAP standard icons here.  This document contains all the icons,its bitmap name and description.

icons

Then, for lots of web dynpro UI elements, there is an attribute named imageSource,To  build the value for imageSource, we can use the format as shown  s_< lowercase of bitmap name>.gif.
For example, in above picture, there is an icon with bitmap name ‘F_MOCR’, in the imageSource, we should have value ‘~sapicons/s_f_mocr.gif‘. If run the web dynpro, you should see the corresponding image in your UI element.

2. Use Custom icons.

If the standard icons do not sufficient enough, you can also add your own image or icons.

First, put your images or icons under project fold like below: src->mimes->Components-><your component name>. If your component name fold does not exist, you can create one. Name of this fold comprises the package name and the component name. It should likes “com.xyz.helloworld“.

Then, you can directly use these image and icons in your UI elements.

Web Dynpro – Refresh the RFC Metadata Cache

September 12th, 2009 No comments

When developing web dynpro applications, we need to create two RFC destinations. One is used to retrieve RFM metadata and another one is used for retrieving transaction data. We can configure the JCo destination using web dynpro content administrator.

You can access the web dynpro tools using below URL patten: https://<your company domain>/webdynpro/welcome/Welcome.jsp

jco-dest

Read more…