For completeness here is how I implemented the advice from Andrea and Roman.
When the user enters data in both the firstName
and lastName
fields we show them a list of names to choose from to fill in the rest of the form. The jsp is
<div class="row">
<div class=" col-sm-2 col-xs-12 no-padding-right text-right"><span class="required">*</span><label class="pull-right" for="lastNameId"><s:text name="lastName"></s:text>:</label></div>
<div class=" col-sm-2 col-xs-12 no-padding-right ">
<s:textfield name="lastName" id="lastNameId" maxlength="50" onchange ="dirtyFlag();" onblur="selectNameInfo(\'newRequest\');" class="form-control"/>
</div>
<div class=" col-sm-2 col-xs-12 no-padding-right text-right " ><span class="required">*</span><label class="pull-right" for="firstNameId"><s:text name="firstName"></s:text>:</label></div>
<div class=" col-sm-2 col-xs-12 no-padding-right ">
<s:textfield name="firstName" id="firstNameId" maxlength="50" onchange ="dirtyFlag();" onblur="selectNameInfo(\'newRequest\');" class="form-control"/>
</div>
</div>
The javascript is
function selectNameInfo(formId) {
var lastName = document.forms[0].elements["lastNameId"].value;
var firstName = document.forms[0].elements["firstNameId"].value;
if(lastName != "" && firstName != ""){
clearDirtyFlag();
var oldAction = document.getElementById(formId).action;
var actionName = document.getElementById(formId).name;
var url = oldAction.replace(actionName,actionName+"_NameSearch");
document.forms[0].action = url;
document.forms[0].submit();
};
}
The javascript forms a url by adding "_NameSearch" to the action
of the form calling the selectNameInfo()
function. In this case the new action is newRequest_NameSearch
which goes to the following xml which calls the generateNameList()
method of the action class without using DMI which was my original question.
<action name="newRequest_NameSearch" class="gov.mo.dnr.egims.controller.evaluation.NewRequestAction" method = "generateNameList">
<result name="success" type="tiles">newRequest</result>
<result name="nameSearch" type="tiles">selectNameInfo</result>
<result name="error" type="tiles">error</result>
</action>