2011-06-17 11 views
0

私のボタンのonSubmitメソッドを使用してCheckBoxMulitpleChoiceコンポーネントのいずれかを更新するには、ウィジェットパネルで少なくとも2回のクリックが必要です。これらのコンポーネントを最初のクリックで更新するにはどうすればよいですか?Wicket CheckBoxMultipleChoiceが更新されない

2つのCheckBoxMultipleChoiceコンポーネントを使用して、通知するユーザーのリストをコンパイルしています。最初のものは、DropDownChoiceチーム選択で利用可能なユーザーに基づいて作成されます。ユーザーはそのチームのユーザーを選択して、2番目のCheckBoxMultipleChoiceに追加することができます。これは、通知するすべてのユーザーを表示し、ユーザーがユーザーを削除できるようにします。

私はパレットコンポーネントを使用しようとしましたが、Wicket 1.3.1(これは1.4への移行に問題がありますが、これは別の投稿用です)を使用していて、UIを制御できませんでした。私もフォームにコンポーネントを配置しようとしましたが、これは機能を変更していません。チェックボックスからエントリを追加または削除するには、少なくとも2回のクリックが必要です。 getValue()は、ボタンの動作が実行されるまで更新されないようです。

 // Team selection for notification ================================= 
     final DropDownChoice teamNotificationChoice = new DropDownChoice("teamNotification", teamList, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((Team) o).getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return Long.toString(((Team) o).getId()); 
      } 
     }); 
     notifySelectionList.add(teamNotificationChoice); 

     // teamUser selection list for notification ======================== 
     List<ItemUser> choices = UserUtils.convertToItemUserListFromUsers(getJtrac().findUsersForSpace(space.getId())); 
     teamUsers = new CheckBoxMultipleChoice("teamUsers", choices, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((ItemUser) o).getUser().getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return ((ItemUser) o).getUser().getLoginName(); 
      } 
     }); 
     notifySelectionList.add(teamUsers); 

     // Add selected teamUsers button =================================== 
     Button button = new Button("addUsersToList") { 
      @Override 
      public void onSubmit(){ 
      } 
     }; 
     button.add(new AjaxFormComponentUpdatingBehavior("onClick") { 
      protected void onUpdate(AjaxRequestTarget target) { 
       List choices = teamUsers.getChoices(); 
       String value = teamUsers.getValue(); 
       for (int index = 0; index < choices.size(); index++) { 
        final ItemUser choice = (ItemUser) choices.get(index); 
        if(isSelected(choice, index, value)&!userSelection.contains(choice)) { 
         userSelection.add(choice); 
        } 
       } 
       SortUtils.sortItemUsers(userSelection); 
       itemUsers.setChoices(userSelection); 
       target.addComponent(itemUsers); 
      } 
     }); 
     notifySelectionList.add(button); 
     notifySelectionList.setOutputMarkupId(true); 

     // notify list =================================================== 
     itemUsers = new CheckBoxMultipleChoice("itemUsers", userSelection, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((ItemUser) o).getUser().getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return ((ItemUser) o).getUser().getLoginName(); 
      } 
     }); 
     itemUsers.setMaxRows(10); 
     itemUsers.setOutputMarkupId(true); 
     notifyList.setOutputMarkupId(true); 
     notifyList.add(itemUsers); 

     // Remove selected teamUsers button =================================== 
     Button removeButton = new Button("removeUsersFromList") { 
      @Override 
      public void onSubmit(){ 
      } 
     }; 
     removeButton.add(new AjaxFormComponentUpdatingBehavior("onClick") { 
      protected void onUpdate(AjaxRequestTarget target) { 
       List choices = itemUsers.getChoices(); 
       String value = itemUsers.getValue(); 
       for (int index = 0; index < choices.size(); index++) { 
        final ItemUser choice = (ItemUser) choices.get(index); 
        if(isSelected(choice, index, value)) { 
         userSelection.remove(choice); 
        } 
       } 
       itemUsers.setChoices(userSelection); 
       target.addComponent(itemUsers); 
      } 
     }); 
     notifyList.add(removeButton); 

誰もが気にならば、私は、私はこれがないと仮定任意のフィードバックを取得していないので、[OK]を、私は、知らない...あなたが提供することができるかもしれどんなアドバイスを事前に

+0

新しいものにアップグレードしてください。 1.3.1は非常に古いバージョンです。 –

+0

@ martin-gあなたは私の投稿を読んだことがありますか?問題はバージョンに関連していません。それはAjaxFormComponentUpdatingBehavior()の過度の使用で終わった。 – OnesAndZeros

答えて

1

をありがとう共通の問題ですが、私の解決策は誰かを助けることができる場合に備えてここに置きます。

AjaxFormComponentUpdatingBehavior()を削除し、ボタンのonSubmit()メソッドを使用するだけで問題なく動くようになりました。私もsetDefaultFormProcessing(false)ボタン上にあるので、CheckboxMultipleChoiceパネルだけが更新されます。これは次のようになります。

 // Team selection for notification ================================= 
     final DropDownChoice teamNotificationChoice = new DropDownChoice("teamNotification", teamList, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((Team) o).getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return Long.toString(((Team) o).getId()); 
      } 
     }); 
     notifySelectionList.add(teamNotificationChoice); 

     // teamUser selection list for notification ======================== 
     List<ItemUser> choices = UserUtils.convertToItemUserListFromUsers(getJtrac().findUsersForSpace(space.getId())); 
     teamUsers = new JtracCheckBoxMultipleChoice("teamUsers", choices, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((ItemUser) o).getUser().getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return ((ItemUser) o).getUser().getLoginName(); 
      } 
     }); 
     notifySelectionList.add(teamUsers); 

     // Add selected teamUsers button =================================== 
     Button button = new Button("addUsersToList") { 
      @Override 
      public void onSubmit(){ 
       List choices = teamUsers.getChoices(); 
       String value = teamUsers.getValue(); 
       for (int index = 0; index < choices.size(); index++) { 
        final ItemUser choice = (ItemUser) choices.get(index); 
        if(isSelected(choice, index, value)&!userSelection.contains(choice)) { 
         userSelection.add(choice); 
        } 
       } 
       SortUtils.sortItemUsers(userSelection); 
       itemUsers.setChoices(userSelection); 
       notifyList.add(itemUsers); 
       teamUsers.updateModel(); 
      } 
     }; 
     button.setDefaultFormProcessing(false); 
     notifySelectionList.add(button); 
     notifySelectionList.setOutputMarkupId(true); 

     // notify list =================================================== 
     itemUsers = new JtracCheckBoxMultipleChoice("itemUsers", userSelection, new IChoiceRenderer() { 
      public Object getDisplayValue(Object o) { 
       return ((ItemUser) o).getUser().getName(); 
      } 
      public String getIdValue(Object o, int i) { 
       return ((ItemUser) o).getUser().getLoginName(); 
      } 
     }); 
     itemUsers.setMaxRows(10); 
     itemUsers.setOutputMarkupId(true); 
     notifyList.setOutputMarkupId(true); 
     notifyList.add(itemUsers); 

     // Remove selected teamUsers button =================================== 
     Button removeButton = new Button("removeUsersFromList") { 
      @Override 
      public void onSubmit(){ 
       List choices = itemUsers.getChoices(); 
       String value = itemUsers.getValue(); 
       if(value!=""){ 
        String[] valueList = itemUsers.getValue().split(";"); 
        List<User> userList = new ArrayList<User>(); 
        for (String s:valueList){ 
         userList.add(getJtrac().loadUser(s)); 
        } 
        List<ItemUser> itemUserList = UserUtils.convertToItemUserListFromUsers(userList); 
        for (ItemUser iu:itemUserList) { 
         userSelection.remove(iu); 
        } 
        itemUsers.setChoices(userSelection); 
        notifyList.add(itemUsers); 
       } 
      } 
     }; 
     removeButton.setDefaultFormProcessing(false); 
     notifyList.add(removeButton); 
+0

あなたの答えを共有してくれてありがとう。私も同様の問題がありますが、基本的にはCheckboxMultipleChoiceは初めてボタンをクリックしたときに値を取得し、選択した値に応じてエラーを表示します。エラーを修正した後、CheckboxMultipleChoice要素に関連するモデルは再び更新されません: – will824

+0

@ will824 - 私はあなたの特定の設定についてはわかりませんが、エラーを表示しているときにチェックボックスのAjaxをリフレッシュすることを試みる可能性がありますか?あるコードで独自の質問を投稿すると、助けることができる任意のアイデア。ありがとう。 – OnesAndZeros

関連する問題