How to use ISetValueAdaptor to populate the full name text field from first and last name text field

Hi all,

I am trying to build a form that allows users to input the first and last name text fields in Forms Builder 6.7 SP3 P15.

When either of the value changes in the above, use a custom adaptor to concatenate the values and populate to a third full name text field.

I am trying to implement the above functionality using custom ISetValueAdaptor, with a simple Java class and deploying to Webtop.

I have also included screenshots of my adaptor configuration, as well as the Special tab of the third full name text field (named as "staff_name").

The class seems to be called whenever values are changed in either the first or last name fields, but it looks like I am unable to get the parameters argument.

Kindly guide me on this implementation.


My code below:

public class FullNamePopulatorAdapter implements ISetValueAdaptor {

@Override

public Object execute(IAdaptorParameter[] parameters) throws AdaptorException {

String firstName = "";

String lastName = "";

String fullName = "";


if (parameters != null && parameters.length == 2) {

IAdaptorParameter parameter = parameters[0];

if (parameter.getObject() instanceof String) {

firstName = parameter.getObject() == null ? (String) parameter.getObject() : "";

firstName = firstName.trim();

}


parameter = parameters[1];

if (parameter.getObject() instanceof String) {

lastName = parameter.getObject() == null ? (String) parameter.getObject() : "";

lastName = lastName.trim();

}

}

if (!firstName.isEmpty() && !lastName.isEmpty()) {

fullName = lastName + " " + firstName;

} else if (!firstName.isEmpty()) {

fullName = firstName;

} else if (!lastName.isEmpty()) {

fullName = lastName;

}


DfLogger.info(CLASSNAME, "firstName = " + firstName + ", lastName = " + lastName + ", fullName = " + fullName, null, null);

return fullName;

}

}



Comments

  • Your custom class looks right. Are you sure that the binding mapping is correct and that values are stored in those fields in the xml?

  • Hi DCTM_Guru,

    Thanks for the quick response.

    After some tinkering I found the problem lies with the line parameter.getObject() and it is strangely not an instanceof String.

    Changed to use parameter.getValue() instead and now it works.

    Updated code below.

    However I now have a new problem. While the adaptor works for single valued attributes, it does not work with repeating values.

    I have another form for users to start workflows for a batch of users and get approval in one go.

    The sample screenshot is a part of the form in Forms Builder. Even when adding multiple rows, it looks like the adaptor only captures the first row.

    But even if it captures it does not populate the first row's Full Name.

    Wonder if there is a way to set the index of the row for the adaptor?


    public class FullNamePopulatorAdapter implements ISetValueAdaptor {

    private static final String CLASSNAME = FullNamePopulatorAdapter.class.getName();

    @Override

    public Object execute(IAdaptorParameter[] parameters) throws AdaptorException {

    String firstName = "";

    String lastName = "";

    String fullName = "";


    if (parameters != null && parameters.length == 2) {

    IAdaptorParameter parameter = parameters[0];

    firstName = parameter != null ? parameter.getValue() : "";

    firstName = firstName.trim();


    parameter = parameters[1];

    lastName = parameter != null ? parameter.getValue() : "";

    lastName = lastName.trim();

    }

    if (!firstName.isEmpty() && !lastName.isEmpty()) {

    fullName = lastName + " " + firstName;

    } else if (!firstName.isEmpty()) {

    fullName = firstName;

    } else if (!lastName.isEmpty()) {

    fullName = lastName;

    }


    DfLogger.info(CLASSNAME, "firstName = " + firstName + ", lastName = " + lastName + ", fullName = " + fullName, null, null);

    return fullName;

    }

    }

  • Ah - I vaguely remember this issue with repeating attributes. I think we had to create index col, since in the xml, there is not implied sequence.

  • Hi DCTM_Guru,

    Do you happen to remember the solution to make adaptors work with repeating attributes?

  • Its been a long time, but if I recall correctly, we didnt use repeating control. Instead we used a combination of both read-only table (to display any existing rows and cols) and editable row (like you shown above). There would "Insert" button visible and if there are existing repeating rows, then "Update" button will also be visible. Clicking row in read-only table would load values in the editable row.