WebSphere Application Server

JSR-352 (Java Batch) Post #22: Substitution Syntax Continued: Defaults

By David Follis posted Wed November 28, 2018 10:21 AM

  

This post is part of a series delving into the details of the JSR-352 (Java Batch) specification. Each post examines a very specific part of the specification and looks at how it works and how you might use it in a real batch application.

To start at the beginning, follow the link to the first post.

The next post in the series is here.
------

First the answers to last week’s property mess.  Starting at the top, the value of property ABC resolves to the value of the passed in parameter XX which we said had a value of ZZ.  So ABC’s value is “ZZ”.  Next, the value of DEF is the string “ABC” concatenated with the value of the Job Property ABC.  Well, that was “ZZ” so the value of the DEF property is going to be ABCZZ.

Moving into the step, things got really messy.  The value of the GHI property is the string “XYZ” concatenated with the value of the ABC property (ZZ) concatenated with “XYZ” again and then the value of the DEF property (ABCZZ) concatenated with “XYZ” (again).  So the net for GHI is the string “XYZZZXYZABCZZXYZ”. 

But what would happen if the job was started without a value being supplied for the XX job parameter?  As coded, the value of ABC would be an empty string.  Then DEF would be shortened to just “ABC” and the GHI property would be set to “XYZXYZABCXYZ” (basically missing the ZZ value).  Could we set up a default value to be used instead of an empty string?  Sure!

The default is indicated by following the closing curly brace with a question mark and a colon, ‘?:’ and terminating the value with a semi-colon ‘;’.  Here’s a simple example that sets the value of property A to “Z” if the myParameter Job Parameter isn’t set:

        <property name=”A” value=”Value#{jobParameter[‘myParameter’]}?:Z;” />

So all that will resolve to “ValueZ” if the Job Parameter isn’t set. 

Alright, so in the puzzle from last week we’ll change the line that sets up the Job Property ABC to look like this:

        <property name=”ABC” value=”#{jobParameters[‘XX’]}?:MM;” />

What does that do to our results if the XX Job Parameter isn’t set?  Come back next week to check your answer…

 

0 comments
7 views

Permalink