Entering content frame

Procedure documentation Creating Dynamic Texts and Completing the Application

 

ResultView displays a picture and text that correspond to the vehicle type chosen by the user. You realize this dynamic screen change in the onPlugRentIn() method.

Do not define any dynamic interface texts for international applications in the source code. It is extremely difficult to extract these texts and make them non-language-specific.

Web Dynpro gives you the option of saving dynamic texts in the message pool. The text elements in the message pool are saved automatically to an xlf file. This isolates the texts in groups, which makes the translation process easier.

This graphic is explained in the accompanying text

You also have the (more difficult) option of extracting the implemented language-specific texts from the source code or saving them directly in a *.properties files. For more information, see Structure linkExternalizing Strings or Structure linkInternationalization Service.

In the following procedure, you save these language-specific texts in the message pool and define how they are extracted by the source code.

 

Procedure

Defining Dynamic Language-Specific Texts in the Message Pool

...

       1.      Open the message pool for LanguagesComp.

       2.      Add new texts to the message pool by choosing This graphic is explained in the accompanying text for each new text. The table shows you the properties of each new text:

Message Key

Message Type

Message Text

text_E

text

You have chosen an economy class car.

text_F

text

You have chosen a first class car.

text_B

text

You have chosen a business class car

text_C

text

You have chosen a cabriolet.

text_V

text

You have chosen a van.

 

Extracting New Texts from the Message Pool in the Program Code

You can now use the onPlugInResult() method to extract the new texts from the message pool.

...

       1.      Open ResultView and switch to the Implementation tab page.

       2.      Add the following source code to the method onPlugInResult():

onPlugInResult()

public void onPlugInResult(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String vehicleType )

{

   //@@begin onPlugInResult(ServerEvent)

   String text, image;

 

   MessageManager msg = (MessageManager) wdComponentAPI  

                                         .getMessageManager();

 

   if (vehicleType.equals("E")) {

      //text = "You have chosen an economy class car.";

      text = wdComponentAPI.getTextAccessor()

                  .getText("text_E");

      image = "Economy.jpg";

   } else if (vehicleType.equals("F")) {

      //text = "You have chosen a first class car.";

      text = wdComponentAPI.getTextAccessor()

                  .getText("text_F");

      image = "Firstclass.jpg";

   } else if (vehicleType.equals("B")) {

      //text = "You have chosen a business class car ";

      text = wdComponentAPI.getTextAccessor()

                  .getText("text_B");

      image = "Business.jpg";

   } else if (vehicleType.equals("C")) {

      //text = "You have chosen a cabriolet.";

      text = wdComponentAPI.getTextAccessor()

                  .getText("text_C");

      image = "Cabrio.jpg";

   } else { //Van

      //text = "You have chosen a van.";

      text = wdComponentAPI.getTextAccessor()

                  .getText("text_V");

      image = "Van.jpg";

   }

  

   wdContext.currentContextElement().setText(text);

   wdContext.currentContextElement().setImage(image);

 

   //@@end

}

This graphic is explained in the accompanying text

The pictures are included in the TutWD_Languages_Init project. You can access them in the Package Explorer by choosing TutWD_Languages_Init ® src ® mimes ® Components ® com.sap.tut.wd.languages.LanguagesComp.

       3.      Save the current status of the metadata.

 

Result

You have created a complete example application from the TutWD_Languages_Init project. You can now start and run the application.

 

Next step:

Translating Text Resources into Other Languages

 

 

Leaving content frame