我在清除自动完成文本字段的输入时遇到问题。出于某种原因,每当我调用 target.add(reference to AutoCompleteTextField);
我的输入值为空...
所以基本上,我可以清除存储输入的引用字符串,但每次我调用 ajaxupdate 时它都为空。
我尝试了 ajaxButton 和 AjaxSubmitLink。两者得到相同的反应。我有一个按钮来提交来自 textField 的输入。
代码:
<form wicket:id="autoCompleteForm">
<td><input wicket:id="autoCompleteTextField" size="20"/></td>
<td><button width:100px wicket:id="selectRoleBtn">Select</button></td>
</form>
private void autoCompleteForm()
{
findRoleForm = new Form<Void>("autoCompleteForm");
findRoleForm.setOutputMarkupId(true);
addOrReplace(findRoleForm);
field = new AutoCompleteTextField<String>("autoCompleteTextField",
new PropertyModel<String>(this,"autoString"))
{
@Override
protected Iterator<String> getChoices(String input)
{
if (Strings.isEmpty(input))
{
List<String> emptyList = Collections.emptyList();
return emptyList.iterator();
}
List<String> choices = new ArrayList<String>(10);
for (final Role role : rolesList)
{
final String roles = role.getRoleName();
if (roles.toUpperCase().startsWith(input.toUpperCase()))
{
choices.add(roles);
if (choices.size() == 10)
{
break;
}
}
}
return choices.iterator();
}
};
findRoleForm.addOrReplace(field);
findRoleForm.addOrReplace(new AjaxSubmitLink("selectRoleBtn", findRoleForm)
{
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
System.out.println("here1" + autoString);
if(rolesList != null && autoString!= null)
{
if(rolesList .size() != 0)
{
for(int i=0; i < rolesList .size(); i++)
{
System.out.println("here2" + autoString);
if(rolesList .get(i).getRoleName().equals(autoString))
{
role = rolesList.get(i);
roleInformation.addOrReplace(new Label("roleNameTxt", role.getRoleName()));
roleInformation.addOrReplace(new Label("roleAliasTxt", role.getRoleAlias()));
roleInformation.addOrReplace(new Label("roleOwnerTxt", role.getRoleOwnerId()));
roleInformation.addOrReplace(new Label("roleStatusTxt", role.getRoleAccessStatus()));
roleInformation.addOrReplace(new Label("roleCategoryTxt", role.getRoleCategoryName()));
roleInformation.addOrReplace(new Label("roleDescriptionTxt", role.getRoleDescription()));
roleInformation.addOrReplace(new Label("roleValidityTxt", role.getRoleValidityStatus()));
roleInformation.addOrReplace(new Label("roleNumUsers", ""));
//add adOrReplace(findRoleForm);
autoString = "";
target.add(field);
target.add(roleInformation);
currentRoleSelection = null;
target.add(rolesDropDownChoice);
break;
}
}
}
}
}
}).add(getIndicatorAppender());
}
编辑: autoCompleteTextField 输入字段第一次清除,但是当我再次尝试时。string: autoString 将为空。因此,如果您在第一次尝试时选择您的选择(从提供的搜索列表中),点击选择按钮,它会为您提供正确的字符串并清除。但是当您第二次选择提供的值时,“autoString”将为空......并且不会获得分配给它的输入值。