How to Set Default Value of a Text Field in IBM Web Experience Factory

I recently wasted an embarrassing amount of time trying to figure out how to simply set a default value in a text field on a page created by a Data Services User Interface (DSUI) builder. So, after having finally found the solution, I thought I thought I better post it so it might be found more easily in the future. Here’s the skinny:

UPDATE: Please take care to note the first comment to this post; it adds important information.

Navigate to the Design tab of your consumer model, which contains the page and text field where you want to have a default value. Select the page in the application tree (under Pages). In the visual display of the page, you can right-click the field and select Formatting and Visibility > Attribute Setter, as shown below:

Creating a New Attribute Setter builder from the page UI.

This creates a new Attribute Setter builder in the model. Set the Page Locations to be single, select the appropriate page, and then add name as an attribute to set in the Attribute List table. Under the value column, type a string value to represent the default (this could also be a variable, the result from an Action, the result from an Action List, or the result of a Method).

Factory Attribute Setter builder

After you click Apply to apply the settings of the Attribute Setter builder, you will then see the default value in the UI of the page instead of the field’s logical name.

When you run the application the form field value will be pre-populated as per your settings.

This entry was posted in IBM WebSphere Portal and tagged . Bookmark the permalink.
  • SteveZag

    Well, that’ll work in the simple case, but it’s going to be a problem if your page has any validation errors (on other fields).  The value will constantly be set BACK to what you set it in the Attribute Setter. 

    In any PageAutomation-based page (that is, anything controlled by Data Page, which DSUI, View and Form, etc. all depend on), the initial value of the fields comes from the variable that the Data Page is based on.  You’ll see this in an update page, for instance:  all those fields are pre-populated from the Variable, the same one that the data will be written into when the form is submitted.  So, if you want to set up the initial value for a field, you do it by putting that value into the variable in the right place. 

    There are a couple of good ways to do this:  You can use an assignment in a method or action list.  (The Assignment operation of Action list will actually let you pick down into the guts of an XML variable.)  You can also use the (somewhat awkward) feature of Data Field Modifier, which has a field for that.  (I don’t really recommend this approach because it is confusing when the method that this creates gets called.  There is actually a setting in Data Page to control when it is called, but you can’t easily get at that setting via DSUI or V&F.) 

    Finally, what is probably the best way to control all the initial values at once:  Create another variable that uses the same schema, press “Sample Data” in the Variable builder, edit the data to be what you want the variable to show initially, and then IN A METHOD, assign the value from that variable to the Variable that the PageAutomation depends on USING .cloneElement( ).  (If you assign in an action list, it doesn’t clone the contents; it will just leave both Variables pointing at the same bunch of IXml.  The result is that when the form is submitted and the data copied into the Variable, you’ll also be polluting your starter variable.)  So the assignment should look something like:

    Variables v = webAppAccess.getVariables( );

    v.setXml( “TargetVariableName”, v.getXml( “SourceVariableName” ).cloneElement( ) ); 

    • Cody Burleson

      Thank you for your thoughtful comment; it’s really great when generous people like you take the time to help. Great advice! I hope you’ll keep an eye on the blog and perhaps teach us more!