tailieunhanh - Bắt đầu với IBM Websphere smash - p 14

112 Chapter 5 Global Context In this case, we’ve created an empty list and posted an element to the list stored in the tmp zone. Next, we append a new list to the stored list using a zget. zget Method To retrieve variables placed in the global context, we use the zget method: Object zget(String location [, Object defaultValue ]); The zget method retrieves the list in the particular global context location. Optionally, you can provide a default value for the list being retrieved. If a default is not provided and the location is not found, a null is returned (see Listing ). Listing zget. | 112 Chapter 5 Global Context In this case we ve created an empty list and posted an element to the list stored in the tmp zone. Next we append a new list to the stored list using a zget. zget Method To retrieve variables placed in the global context we use the zget method Object zget String location Object defaultvalue The zget method retrieves the list in the particular global context location. Optionally you can provide a default value for the list being retrieved. If a default is not provided and the location is not found a null is returned see Listing . Listing zget to Retrieve a List from the Global Context slist zget app stringList array ilist zget app integerList Here we are retrieving our string list with a default empty ArrayList and our integer list with no default. We can also retrieve individual elements from our list by again using the key notation see Listing . Listing zget to Retrieve an Element from a List in the Global Context s zget app stringList 0 i zget app integerList 0 This code retrieves the first element of each list. zdelete Method To remove a list from the global context we use zdelete boolean zdelete String location boolean deleteChildren The zdelete method deletes the specified location removing any values stored there see Listing . Listing zdelete to Delete a List from the Global Context zdelete app stringList zdelete app integerList Here we delete both of the lists we ve previously created and updated. The optional deleteChildren parameter works the same as the object usage of this method. As with zput we can delete single elements from our list by specifying the key in the location see Listing . Download from Accessing the Global Context 113 Listing zdelete to Retrieve an Element from a List in the Global Context zdelete app stringList 0 zdelete app integerList 1 The first zdelete removes the first element of the string list and the second zdelete removes the second element of

TỪ KHÓA LIÊN QUAN