开发者

wicket issue unable to move items from one listmultiplechoice another

I have a Wicket Panel. It has two text fields adjacent to each other and two ListMultipleChoice controls adjacent to each other and two buttons "add and remove" in between two these ListMultipleChoice's.

I was unable to move the items from one list box to another unless I entered some values in text fields, which were prior to the list boxes.

If values were entered in text fields, I was able to move the items.

Please find the code below.

TextField<BigDecimal> textfield1 = new TextField<BigDecimal>("value1")
{
    private static final long serialVersionUID = 8199976201679629866L;

    @Override
    public IConverter getConverter(Class<?> type) {
        return new FixedDecimalPlacesConverter();
    }

};
textfield1.setType(BigDecimal.class);
textfield1.setLabel(new Model<String>("Value1"));
textfield1.setRequired(true)
.add(PositiveNumberValidator.getInstance())
.add(new FixedDecimalPlacesValidator(2));
add(new FeedBackBorder("Border1").add(textfield1));

TextField <BigDecimal> textfield2 = new TextField<BigDecimal>("value2")
{
    private static final long serialVersionUID = 8199976201679629866L;

    @Override
    public IConverter getConverter(Class<?> type) {
        return new FixedDecimalPlacesConverter();
    }

};
textfield2.setType(BigDecimal.class);
textfield2.setOutputMarkupId(true);
textfield2.setLabel(new Model<String>("Value2"));
textfield2.setRequired(true)
.add(PositiveNumberValidator.getInstance())
.add(new FixedDecimalPlacesValidator(2));
add (new FeedBackBorder("Border2").add(textfield2));

ChoiceRenderer<UserBean> choiceRenderer = new ChoiceRenderer<UserBean>("userName", "userID.ID");

availableUsers= new ListMultipleChoice<UserBean>( "availableUsersBean", availableUsersList, choiceRenderer );
availableUsers.setOutputMarkupId(true);
availableUsers.setLabel(new Model<String>("Available Users"));
add(new FeedBackBorder("availableUsersBorder").add(availableUsers));

selectedUsers = new ListMultipleChoice<UserBean>( "selectedUsersBean", selectedUsersList, choiceRenderer );
selectedUsers.setOutputMarkupId(true);
selectedUsers.setLabel(new Model<String>("Selected Users"));
add(new FeedBackBorder("selectedUsers Border").add(selectedUsers ));

add = new AjaxButton("add") {
    @Override
    protected void onSubmit(AjaxRequestTarget target, Form form) {
        update(target, availableUsers.getModelValue(开发者_JS百科),availableUsers, selectedUsers);
    }
};
add(new FeedBackBorder("addBorder").add(add));

remove = new AjaxButton("remove") {
    @Override
    protected void onSubmit(AjaxRequestTarget target, Form form) {
        update(target, selectedUsers.getModelValue(), selectedUsers , availableUsers);
    }
};
add(new FeedBackBorder("removeBorder").add(remove));

What could be the issue?


add.setDefaultFormProcessing(false); remove.setDefaultFormProcessing(false);

I am using org.apache.wicket.markup.html.form.Button which allows you to turn off full form submit with button click with the setDefaultFormProcessing(boolean). This should allow you to process actions without submitting your complete form, therefore not validating required textfields.


At a first glance: Your TextFields are required. Submitting the Form via AjaxButtons wouldn't trigger the onSubmit method for an invalid form but the onError method.

Possible Solutions (in no particular order):

  • Moving the Lists to a nested form
  • Moving the contents of the onSubmit to a separate method and call it from onError too
  • Move the item moving logic to a pure JavaScript based Behaviour or Decorator that doesn't trigger a form submit.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜