3 August 2009
This tutorial is written for:
All
Note: The ZIP files are Flex Builder project archives and the NUGG files are SAP archives. The starter archives are the completed files from Part 8 of this tutorial series. The solution archives contain the completed code and assets associated with this tutorial, Part 9. The latter is provided to you to compare against your own completed code.
Welcome to Part 9 of this tutorial series. In this part, you will learn how to map Web Dynpro attributes to Flex ActionScript variables. You also learn to create a Flex Builder release build of the Rich Island and import it into the Web Dynpro application. Lastly, you learn how to create a Web Dynpro event in ActionScript to pass data to the Web Dynpro application from the rich island.
Note: Parts 1 through 6 focus on teaching Flex development to SAP developers. Part 7 teaches Flex developers how to create a Web Dynpro application. Parts 8 and 9 show both SAP and Flex developers how to integrate the Flex application as a Rich Island into the Web Dynpro application.
In Part 7 you created a Web Dynpro entity that contained inventory data for display in the Web Dynpro table UI element. In Part 8, you prepared the Flex application to receive that complex data as an ActionScript ArrayCollection object. However, remember that the table UI element has three columns of data for bin name, bin quantity and the number of parts necessary to create a wagon. In order to refer to the columns of data in the Web Dynpro context from the Flex ActionScript code, you will need to create an equivalent ActionScript variable for each of the column names. In this section, you create the ActionScript alias variables.
mappedColumnNameForBinTitlemappedColumnNameForBinQuantitymappedColumnNameForBinParts[Bindable]
public var mappedColumnNameForBinTitle:String;
[Bindable]
public var mappedColumnNameForBinQuantity:String;
[Bindable]
public var mappedColumnNameForBinParts:String;
In this section, you will map the three ActionScript alias variables that you created in the last section to the associated column names in the wagonInventory data of the Web Dynpro application.
Follow these steps:
You will select the location of the data in SAP by creating a binding to it. This binding will keep track of changes made to SHOP_FLOOR_DATA the same way a binding works in the Flex framework.
dataSource property to SHOP_FLOOR_DATA by clicking the Binding button to the right of the dataSource property.dataSource is wagonInventory.The name value refers to the wagonInventory ArrayCollection in ActionScript to which you are mapping to the Web Dynpro SHOP_FLOOR_DATA data.
You will create a mapping for each column in SHOP_FLOOR_DATA to the specific alias in ActionScript that you created earlier. Once mapped, the alias in ActionScript represents the column name in the Web Dynpro data source.
You will use mappedColumnNameForBinTitle when referencing the bin title data in ActionScript.
If prompted to save your changes, select yes.
You will embed the V_ISLANDFORSHOPFLOOR view into the ISLANDS_CONTAINER allowing you to display both the V_ISLANDFORSHOPFLOOR view containing the rich island and the V_MAIN view containing the table UI element at the same time.
Follow these steps:
You will now set additional mappings that represent the threshold values for changing the bin colors and the assembly rate in ActionScript.
The ID property REDWARNING, is an internal name used in the Web Dynpro application structure. This is similar to the component id property in the Flex framework. The name wagonRedWarningAmount references the public variable created in ActionScript and holds the threshold value for when the bin should turn red.
The wagonYellowWarningAmount references the public variable in ActionScript and holds the threshold value for when the bin should turn yellow.
wagonProductionRate references the public variable in ActionScript and holds the value for the speed at which the wagons are assembled.
Activating means to create new runtime objects which will include any changes you have made to the application. This is similar to recompiling an application in Flex Builder to see the changes made.
In the Flex application, the private variable that holds all of the data is _wagonInventory. It is an ArrayCollection data type with complex data passed from the Web Dynpro application (think of the table UI element). In the previous sections, you created alias variables in ActionScript that represent the column names (bin quantity, bin parts, bin title) for the Web Dynpro data. In this section, you will use the alias variables, and square bracket syntax, to access the specific data in the ArrayCollection. The square bracket syntax denotes a variable that needs to be evaluated. The alias variables will be evaluated to return the name of the associated Web Dynpro property.
calculateMaxWagonsPossibleFromInventory() function in the Script block.Quantity is retrieved from the _wagonInventory ArrayCollection and change the .Quantity string to [mappedColumnNameForBinQuantity]. There are two changes made in the function. _wagonInventory.getItemAt(x)[mappedColumnNameForBinQuantity]
Note that there is no period between the getItemAt() function and the alias variable notation. This is the syntax that must be used when using SAP mappings.
Parts are retrieved from the _wagonInventory ArrayCollection and change the .Parts string to [mappedColumnNameForBinParts]. There are two changes made in the function.timerEventHandler() function and change the variables referencing Quantity and Parts to [mappedColumnNameForBinQuantity] and [mappedColumnNameForBinParts]. There are two changes for Quantity and one for Parts in the function.BINTITLE, BINQUANTITY, and BINPARTS are the names of the columns in the Web Dynpro table UI element and mappedColumnNameForBinTitle, mappedColumnNameForBinQuantity, and mappedColumnNameForBinParts are the alias variable that were mapped to the columns for referencing in the Flex application.
The mapped alias variables are created in the main Flex application file and therefore not available in the BinComponent custom component. In this section, you could create a setter function in the BinComponent custom component to accept these alias variables values as properties and then apply them using square bracket syntax as you did previously. However, for brevity's sake, you will instead directly hard-code the column names from the Web Dynpro table UI element.
calculateQuantity() function in the Script block.Parts is retrieved from _wagonInventory and change the Parts string to BINPARTS. There are two changes to be made._wagonInventory.getItemAt(_binPosition).BINPARTS;
Note that when using the SAP column names you do not use the bracket syntax, because there is no alias that must be evaluated.
binColorHandler() function and change all the variables referencing Parts and Quantity to BINPARTS and BINQUANTITY. There are four changes for Quantity and one change for Parts.updateBinInventory() function and change the Quantity reference to BINQUANTITY.binTitle Label control and change the text property value referencing Title to BINTITLE.binData TextInput control and change the text property value referencing Quantity to BINQUANTITY.wagonInventory setter function.Call the binColorHandler() function to ensure the bins are updated when a change is made to the Web Dynpro table UI element.
The application will not work; however, you should not see any errors.
In this section, you will create a release build of the ShopFloorBins application. The release build is a SWF file that you will import into SAP and then test.
Follow these steps:
The Flex Rich Island is now displayed in the MIME folder of the Web Dynpro Component and is available for integration into the Web Dynpro application.
Follow these steps:
Follow these steps:
You cannot overwrite an existing application.
You should see the Flex Rich Island displayed below the table UI element in the application. Note that as the clock counts down the inventory in the bin decreases; however, the UI table element values never change. Change a bin amount. The clock time automatically adjusts. Change a bin quantity to zero in the Rich Island and you will see that the clock also changes to zero but, again, the Web Dynpro table UI element does not change. Now change the table UI element quantity where the bin inventory is zero in the Rich Island. You will see that the clock time adjusts and the bin inventory matches the UI table element value.
In your testing you have noticed that data only flows from the Web Dynpro component to the Rich Island. The Web Dynpro component has no awareness of data changes taking place in the Rich Island. In this section, you will create a Web Dynpro component event that will be used to notify the component of data changes within the Rich Island. The event you will create accepts as parameters the bin index and the corresponding data from the ArrayCollection. This event is triggered by data changes in the Rich Island, thus creating a two-way communication.
onEnter property. Select the button next to the field.When a change is made to the table UI element's title column, the onEnter event is triggered and the event is handled by the ONINPUTACTION method. In this case, the method has no code and simply relays the value of the change to any bound elements. You are allowed to make changes to the title column as an illustration that text can also be modified.
onEnter property to ONINPUTACTION.You will now create an event that listens for data changes from the Rich Island and calls a method that makes modifications to the table data.
You are creating a new method named ONNEWINVENTORY that is triggered by the onNewInventory event.
ONNEWINVENTORY and paste the following code in the editor that opens up. Save the changes after copying the code. Note: This ABAP code will accept the bin index and bin quantity from the Rich Island as parameters. Using the bin index the code will update the corresponding row of the SAP data with the new quantity. Check the SAP Developer's Network for resources about ABAP programming.
method ONACTIONONNEWINVENTORY .
*create local variables with their types
DATA lo_nd_shop_floor_data TYPE REF TO if_wd_context_node.
DATA lo_el_shop_floor_data TYPE REF TO if_wd_context_element.
DATA ls_shop_floor_data TYPE wd_this->element_shop_floor_data.
DATA lv_binQuantity TYPE wd_this->element_shop_floor_data-binquantity.
DATA lv_binNumber TYPE I.
* navigate from <CONTEXT> to <SHOP_FLOOR_DATA> via
lead selection
lo_nd_shop_floor_data = wd_context->get_child_node( name =
wd_this->wdctx_shop_floor_data ).
* assign the value from binPosition to local variable
lv_binNumber
lv_binNumber = wdevent->get_String('binPosition').
* increment lv_binNumber
lv_binNumber = lv_binNumber + 1.
* get datagrid data at index lv_binNumber
lo_el_shop_floor_data = lo_nd_shop_floor_data->get_element(
index = lv_binNumber ).
* do nothing if there is no data
IF lo_el_shop_floor_data IS INITIAL.
ENDIF.
* assign the value from newInventoryAmount to local variable lv_ binQuantity
lv_binQuantity = wdevent->get_String('newInventoryAmount').
* assign lv_binQuantity to BINQUANTITY in the shopfloor datagrid
lo_el_shop_floor_data->set_attribute(
name = 'BINQUANTITY'
value = lv_binQuantity ).
ENDMETHOD.
Now you will create the required parameters for the event.
The NEWVALUEIN ID is the internal Web Dynpro name of the parameter in the application structure. The newInventoryAmount name is the argument name you will use in ActionScript when passing the value to the Web Dynpro application. The value is used to update the Web Dynpro table UI element.
The name, binPosition, will contain the index of the row to update in the Web Dynpro table UI element.
In this section, you will dispatch an event from the Rich Island to the Web Dynpro component using the FlashIsland.fireEvent() method. This method is available in the FlashIsland library SWC that you imported into your SAP application in Part 8.
import sap.FlashIsland;
updateBinInventory() method and after the code in the function, use the fireEvent() method of the FlashIsland class to dispatch an event.FlashIsland.fireEvent();
This event takes three arguments: the component, the literal Web Dynpro event name that you created in the last section, and the parameters that are being updated.
FlashIsland.fireEvent() method, type this. The value, this, represent the source of the event which in this case is the application itself.
onNewInventory event that you created earlier in NetWeaver. Place double-quotes around the value.FlashIsland.fireEvent(this, "onNewInventory");
newInventoryAmount to reference the first piece of data required by the event and give it a value of binData.text. Separate the name and value with a colon.The value comes from the text property of the binData TextInput control.
binPosition with a value of _binPosition.Remember, newInventoryAmount and binPosition were the parameters you created in the Web Dynpro event.
FlashIsland.fireEvent(this, "onNewInventory",
{newInventoryAmount: binData.text, binPosition: _binPosition});
In order to see the changes you just made, you will need to replace the SWF rich island file in the Web Dynpro application.
You have a new SWF file and it will not overwrite the old SWF file so you must delete it.
You have made changes that you want used in the application.
You want to generate a new application. If you have not made changes to your application, you can just import a new SWF file without generating a new application version.
It is very important that you save the component, otherwise you will not see the application you just generated.
Use these steps to view updates to the Rich Island when asked, "Compile a release build SWF from Flex Builder, import it into SAP, and view it in a browser."
Change the data in a colored bin in the Rich Island and press Enter; note that the number you changed is now reflected in the Web Dynpro UI table element. Also note that the clock time adjusted but as it counts down, the table UI column values do not change.
You now need to synchronize the bin inventory quantity in the Web Dynpro UI table element with the clock countdown from the Rich Island. You will dispatch the FlashIsland event from the timerEventHandler() function in the Rich Island to the Web Dynpro component.
timerEventHandler() function in the Script block.partsLeftInBin local variable, create a new local variable named newQuantity and data type it to the uint class._productionRateCounter is a multiple of 6 but after the for loop, create another for loop that loops over the _wagonInventory ArrayCollection. Use the variable y to iterate.You want to use this loop to send events to SAP after all the changes have been made to the _wagonInventory ArrayCollection, otherwise the bin display will not appear to be in sync with the table UI element.
for (var y:uint = 0; y < _wagonInventory.length; y++)
{
}
_wagonInventory.getItemAt(y)[mappedColumnNameForBinQuantity] and assign it to the newQuantity variable. newQuantity = _wagonInventory.getItemAt(y)[mappedColumnNameForBinQuantity];
FlashIsland .fireEvent() event with the three arguments: this, "onNewInventory", {newInventoryAmount: newQuantity, binPosition: y}. The first argument, this, represents the application as the source of the event, the second argument represents the event name, and the last argument represents the data.
FlashIsland.fireEvent(this, "onNewInventory",
{newInventoryAmount: newQuantity, binPosition: y});
As the clock counts down, notice that the inventory changes are reflected in the UI table element. Change the naumber in any bin. You should see the clock time adjust and the UI table element change. When the clock reaches 0 or you change a bin to 0, note that the clock stops and the bin turns red.
In this tutorial you learned how to map Web Dynpro attributes to ActionScript variables and how to use these alias variables in ActionScript. You also learned how to create and use a Web Dynpro event to provide two-way communication between a Web Dynpro component and a Rich Island.
To review the concepts you've learned in Parts 8 and 9 of this tutorial series about creating Adobe Rich Islands for Web Dynpro applications, watch the following videos:
For your reference, here are all the parts in this series: