You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by JohnSmith333 <da...@msa.hinet.net> on 2007/09/15 15:53:26 UTC
Question about use Palette with DropDownChoice
I have use a Palette with DropDownChoice. I want to change the
DropDownChoice's selected value and then update the Palette's lists. And
when I click the Palette's value ,I hope to save the change result.
But it's not work normally. Could anyone kind to help me? Thanks!
http://www.nabble.com/file/p12690471/PaletteChoice.java PaletteChoice.java
http://www.nabble.com/file/p12690471/PaletteChoice.html PaletteChoice.html
http://www.nabble.com/file/p12690471/1.jpg
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12690471
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by JohnSmith333 <da...@msa.hinet.net>.
I have changed the code to "ajax like'. But the problem also could not be
solved.
The code bellow do not change the palette's selected values and let it empy.
But I really have choice some value before. Why? Could anyone help me,
thanks!
if(selectedMap.containsKey(nowSelectedValue)){
setSelectedList((ArrayList)selectedMap.get(nowSelectedValue));
testResult("getSelectedList",getSelectedList());
}
-----------------------------
the code below:
package palette_choice;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import wicket.ajax.form.AjaxFormSubmitBehavior;
import wicket.extensions.markup.html.form.palette.Palette;
import wicket.markup.html.WebPage;
import wicket.markup.html.form.ChoiceRenderer;
import wicket.markup.html.form.DropDownChoice;
import wicket.markup.html.form.Form;
import wicket.model.CompoundPropertyModel;
import wicket.model.PropertyModel;
public class PaletteChoice extends WebPage implements Serializable
{
private static final long serialVersionUID = 1L;
private Form form;
private DropDownChoice choice;
private Palette palette ;
private Map mainMap=new HashMap();
private Map availibleMap=new HashMap();
private Map selectedMap=new HashMap();
private List availibleList=new ArrayList();
private List selectedList=new ArrayList();
private String mainChoice;
public PaletteChoice(){
final Map mainMap=new HashMap();
//List mainList=new ArrayList();
final Map availibleMap=new HashMap();
final Map selectedMap=new HashMap();
// data
mainMap.put("A","0");
mainMap.put("B","1");
Set mainKeySet=mainMap.keySet();
Iterator it=mainKeySet.iterator();
while(it.hasNext()){
Object ok=it.next();
ArrayList availibleList=new ArrayList();
for(int i=0;i<5;i++){
availibleList.add(String.valueOf(ok)+i);
}
availibleMap.put(ok, availibleList);
List selectedList=new ArrayList();
selectedMap.put(ok,selectedList);
}
List mainList=new ArrayList();
Set tmpSet=mainMap.keySet();
Iterator tmpIt=tmpSet.iterator();
while(tmpIt.hasNext()){
mainList.add((Serializable)tmpIt.next());
}
form = new Form("form",new CompoundPropertyModel(this));
form.setOutputMarkupId(true);
add(form);
choice = new DropDownChoice( "mainChoice",mainList);
choice.add(new AjaxFormComponentUpdatingBehavior("onChange")
{
protected void onUpdate(AjaxRequestTarget target)
{
String nowSelectedValue=getMainChoice();
setMainChoice(nowSelectedValue);
System.out.println("choice:"+nowSelectedValue);
if(mainMap.containsKey(nowSelectedValue)){
if(availibleMap.containsKey(nowSelectedValue)){
setAvailibleList((ArrayList)availibleMap.get(nowSelectedValue));
testResult("getAvailibleList",getAvailibleList());
}
if(selectedMap.containsKey(nowSelectedValue)){
setSelectedList((ArrayList)selectedMap.get(nowSelectedValue));
testResult("getSelectedList",getSelectedList());
}
}
target.addComponent(palette);
}
});
choice.setOutputMarkupId(true);
form.add(choice);
palette = new Palette("palette",new PropertyModel(
this,"selectedList"), new PropertyModel(this,"availibleList"),new
ChoiceRenderer("toString","toString"), 10, false);
palette.setOutputMarkupId(true);
palette.getRecorderComponent().add(new AjaxFormSubmitBehavior(form,
"onchange")
{
protected void onSubmit(AjaxRequestTarget target) {
String nowSelectedValue=getMainChoice();
if(mainMap.containsKey(nowSelectedValue)){
/*
if(availibleMap.containsKey(nowSelectedValue)){
availibleMap.put(nowSelectedValue,getAvailibleList());
System.out.println("size:"+((ArrayList)availibleMap.get(nowSelectedValue)).size());
}
*/
if(selectedMap.containsKey(nowSelectedValue)){
selectedMap.put(nowSelectedValue,getSelectedList());
}
System.out.println("******");
//target.addComponent(choice) ;
}
}
});
form.add(palette);
}
public List getAvailibleList() {
return availibleList;
}
public void setAvailibleList(List availibleList) {
this.availibleList = availibleList;
}
public List getSelectedList() {
return selectedList;
}
public void setSelectedList(List selectedList) {
this.selectedList = selectedList;
}
public String getMainChoice() {
return mainChoice;
}
public void setMainChoice(String mainChoice) {
this.mainChoice = mainChoice;
}
public void testResult(String info,List list)
{
System.out.println(info+" ***begin***");
Iterator it=list.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
System.out.println(info+" ***end***");
}
}
------------------------------------
The console show:
choice:A
getAvailibleList ***begin***
A0
A1
A2
A3
A4
getAvailibleList ***end***
getSelectedList ***begin***
getSelectedList ***end***
******
choice:B
getAvailibleList ***begin***
B0
B1
B2
B3
B4
getAvailibleList ***end***
getSelectedList ***begin***
getSelectedList ***end***
******
choice:A
getAvailibleList ***begin***
A0
A1
A2
A3
A4
getAvailibleList ***end***
getSelectedList ***begin***
A0
getSelectedList ***end***
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12691759
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by Kent Tong <ke...@cpttm.org.mo>.
Yes,sir. I have run the code more three times before.
Maybe it's because I run the code with wicket 1.2.6 and
wicket-extensions-1.2.6 and jdk 1.4.12.
Really I don't know what happen! Thank's your help again. Thanks!
Then try using 1.3 beta3.
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12748565
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by JohnSmith333 <da...@msa.hinet.net>.
Yes,sir. I have run the code more three times before.
Maybe it's because I run the code with wicket 1.2.6 and
wicket-extensions-1.2.6 and jdk 1.4.12.
Really I don't know what happen! Thank's your help again. Thanks!
Helo! Kent Thanks for your help.
But I still have the same question.
That's if I choice A with select A1 to selectedList and then choice B with
selected nothing to selectedList.
It's ok when I choice A again and see the A1 at selectedList.
But if I choice A with select A1 to selectedList and then choice B with
selected anything (ex:B1) to selectedList. Then when I choice A again ,there
will see that A1 not at selectedList.
So I choice before would be disappear! Why? I have any idea yet!
JohnSmith333 wrote:
>
>
> Have you actually tried my code? I did and it works as you described
> above.
>
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12748563
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by Kent Tong <ke...@cpttm.org.mo>.
Helo! Kent Thanks for your help.
But I still have the same question.
That's if I choice A with select A1 to selectedList and then choice B with
selected nothing to selectedList.
It's ok when I choice A again and see the A1 at selectedList.
But if I choice A with select A1 to selectedList and then choice B with
selected anything (ex:B1) to selectedList. Then when I choice A again ,there
will see that A1 not at selectedList.
So I choice before would be disappear! Why? I have any idea yet!
Have you actually tried my code? I did and it works as you described above.
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12748126
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by JohnSmith333 <da...@msa.hinet.net>.
Helo! Kent Thanks for your help.
But I still have the same question.
That's if I choice A with select A1 to selectedList and then choice B with
selected nothing to selectedList.
It's ok when I choice A again and see the A1 at selectedList.
But if I choice A with select A1 to selectedList and then choice B with
selected anything (ex:B1) to selectedList. Then when I choice A again ,there
will see that A1 not at selectedList.
So I choice before would be disappear! Why? I have any idea yet!
Kent Tong wrote:
>
>
> JohnSmith333 wrote:
>>
>> I have use a Palette with DropDownChoice. I want to change the
>> DropDownChoice's selected value and then update the Palette's lists. And
>> when I click the Palette's value ,I hope to save the change result.
>> But it's not work normally. Could anyone kind to help me? Thanks!
>>
>
> Your code contains quite a lot of bugs. Try this instead:
> <pre>
> public class PaletteChoice extends WebPage implements Serializable {
> private static final long serialVersionUID = 1L;
> private Form form;
> private DropDownChoice choice;
> private Palette palette;
> private Map mainMap = new HashMap();
> private String mainChoice;
> private Map availibleMap;
> private Map selectedMap;
>
> public PaletteChoice() {
> availibleMap = new HashMap();
> selectedMap = new HashMap();
> // data
> mainMap.put("A", "0");
> mainMap.put("B", "1");
> Set mainKeySet = mainMap.keySet();
> Iterator it = mainKeySet.iterator();
> while (it.hasNext()) {
> Object ok = it.next();
> ArrayList availibleList = new ArrayList();
> for (int i = 0; i < 5; i++) {
> availibleList.add(String.valueOf(ok) + i);
> }
> availibleMap.put(ok, availibleList);
> List selectedList = new ArrayList();
> selectedMap.put(ok, selectedList);
> }
> List mainList = new ArrayList();
> Set tmpSet = mainMap.keySet();
> Iterator tmpIt = tmpSet.iterator();
> while (tmpIt.hasNext()) {
> mainList.add((Serializable) tmpIt.next());
> }
> form = new Form("form", new CompoundPropertyModel(this));
> form.setOutputMarkupId(true);
> add(form);
> choice = new DropDownChoice("mainChoice", mainList) {
> protected void onSelectionChanged(java.lang.Object newSelection) {
> }
> protected boolean wantOnSelectionChangedNotifications() {
> return true;
> }
> };
> choice.setOutputMarkupId(true);
> form.add(choice);
> palette = new Palette("palette",
> new PropertyModel(this, "selectedList"), new PropertyModel(
> this, "availibleList"), new ChoiceRenderer("toString",
> "toString"), 10, false);
> palette.setOutputMarkupId(true);
> palette.getRecorderComponent().add(
> new AjaxFormSubmitBehavior(form, "onchange") {
> protected void onSubmit(AjaxRequestTarget target) {
> target.addComponent(form);
> }
> });
> form.add(palette);
> }
> public List getAvailibleList() {
> return mainMap.containsKey(mainChoice) ? (List) availibleMap
> .get(mainChoice) : Collections.EMPTY_LIST;
> }
> public void setAvailibleList(List availibleList) {
> if (mainMap.containsKey(mainChoice)) {
> availibleMap.put(mainChoice, availibleList);
> }
> }
> public List getSelectedList() {
> return mainMap.containsKey(mainChoice) ? (List) selectedMap
> .get(mainChoice) : Collections.EMPTY_LIST;
> }
> public void setSelectedList(List selectedList) {
> if (mainMap.containsKey(mainChoice)) {
> selectedMap.put(mainChoice, selectedList);
> }
> }
> public String getMainChoice() {
> return mainChoice;
> }
> public void setMainChoice(String mainChoice) {
> this.mainChoice = mainChoice;
> }
> }
> </pre>
>
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12747859
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Question about use Palette with DropDownChoice
Posted by Kent Tong <ke...@cpttm.org.mo>.
JohnSmith333 wrote:
>
> I have use a Palette with DropDownChoice. I want to change the
> DropDownChoice's selected value and then update the Palette's lists. And
> when I click the Palette's value ,I hope to save the change result.
> But it's not work normally. Could anyone kind to help me? Thanks!
>
Your code contains quite a lot of bugs. Try this instead:
public class PaletteChoice extends WebPage implements Serializable {
private static final long serialVersionUID = 1L;
private Form form;
private DropDownChoice choice;
private Palette palette;
private Map mainMap = new HashMap();
private String mainChoice;
private Map availibleMap;
private Map selectedMap;
public PaletteChoice() {
availibleMap = new HashMap();
selectedMap = new HashMap();
// data
mainMap.put("A", "0");
mainMap.put("B", "1");
Set mainKeySet = mainMap.keySet();
Iterator it = mainKeySet.iterator();
while (it.hasNext()) {
Object ok = it.next();
ArrayList availibleList = new ArrayList();
for (int i = 0; i < 5; i++) {
availibleList.add(String.valueOf(ok) + i);
}
availibleMap.put(ok, availibleList);
List selectedList = new ArrayList();
selectedMap.put(ok, selectedList);
}
List mainList = new ArrayList();
Set tmpSet = mainMap.keySet();
Iterator tmpIt = tmpSet.iterator();
while (tmpIt.hasNext()) {
mainList.add((Serializable) tmpIt.next());
}
form = new Form("form", new CompoundPropertyModel(this));
form.setOutputMarkupId(true);
add(form);
choice = new DropDownChoice("mainChoice", mainList) {
protected void onSelectionChanged(java.lang.Object newSelection) {
}
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
};
choice.setOutputMarkupId(true);
form.add(choice);
palette = new Palette("palette",
new PropertyModel(this, "selectedList"), new PropertyModel(
this, "availibleList"), new ChoiceRenderer("toString",
"toString"), 10, false);
palette.setOutputMarkupId(true);
palette.getRecorderComponent().add(
new AjaxFormSubmitBehavior(form, "onchange") {
protected void onSubmit(AjaxRequestTarget target) {
target.addComponent(form);
}
});
form.add(palette);
}
public List getAvailibleList() {
return mainMap.containsKey(mainChoice) ? (List) availibleMap
.get(mainChoice) : Collections.EMPTY_LIST;
}
public void setAvailibleList(List availibleList) {
if (mainMap.containsKey(mainChoice)) {
availibleMap.put(mainChoice, availibleList);
}
}
public List getSelectedList() {
return mainMap.containsKey(mainChoice) ? (List) selectedMap
.get(mainChoice) : Collections.EMPTY_LIST;
}
public void setSelectedList(List selectedList) {
if (mainMap.containsKey(mainChoice)) {
selectedMap.put(mainChoice, selectedList);
}
}
public String getMainChoice() {
return mainChoice;
}
public void setMainChoice(String mainChoice) {
this.mainChoice = mainChoice;
}
}
--
View this message in context: http://www.nabble.com/Question-about-use-Palette-with-DropDownChoice-tf4447817.html#a12738225
Sent from the Wicket - User mailing list archive at Nabble.com.