0

I create widgets for date for my project.

n using the same widget for setProperty and getProperty of a object.

public TextBox getTimeTxtbx() {
        // TODO Auto-generated method stub

        timebx =new TextBox();

        timebx.setReadOnly(true);
        final PopupPanel popupPanel=new PopupPanel(true);
        final DatePicker datePicker=new DatePicker();

        datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

            public void onValueChange(ValueChangeEvent<Date> event) {
                // TODO Auto-generated method stub

                Date date=event.getValue();
                timebx.setText(DateTimeFormat.getFormat("EEE MMM dd HH:mm:ss z yyyy").format(date));
                popupPanel.hide();
            }


        });
        popupPanel.setWidget(datePicker);
        timebx.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                // TODO Auto-generated method stub
                String strDate = timebx.getText();
                System.out.println(" strDate " +strDate);
                DateTimeFormat format = DateTimeFormat.getFormat("[EEE MMM dd HH:mm:ss z yyyy]");
                try {  
                      Date selDate = (Date)format.parse(strDate); 
                      datePicker.setValue(selDate, true);
                    } catch(Exception pe){
                     // setting current date
                        System.out.println("error" +pe);
                     datePicker.setValue(new Date(), true);
                    }
                int x=timebx.getAbsoluteLeft();
                int y=timebx.getAbsoluteTop();
                popupPanel.setPopupPosition(x, y+20);
                popupPanel.show();
            }
        });
        return timebx;
    }
    public void setTimebx(String string) {
        // TODO Auto-generated method stub
        timebx.setText(string);
    }

I am adding this widgets in flexTable in different gui class

flexTable.setWidget(i, j,textBoxDisplay.getTimeTxtbx());
textBoxDisplay.setTimebx(customProperty.getValues().toString());

In a flexTable , this above code is inside a iterator and called Twice. enter image description here

Like in Image : testDate an received on.

When i click on testDate the value of Received On is Changed


Edited

public ListBox getBooleanBox() {
        // TODO Auto-generated method stub
        selectBoolean = new ListBox(false);
        //selectBoolean.setName(title);
        selectBoolean.setStyleName("cmis-Customproperties-TextBox");
        selectBoolean.setSize("150px", "20px");
        selectBoolean.addItem("True","True");
        selectBoolean.addItem("False", "False");
        return selectBoolean;
    }
    public void setBooleanBox(String value){
         int itemCount = selectBoolean.getItemCount();
         for(int i = 0 ;i < itemCount;i++){
             if(selectBoolean.getItemText(i).equalsIgnoreCase(value)){
                 selectBoolean.setSelectedIndex(i);
             }
         }
    }

adding in flexTable

customPropertyTabel.setWidget(i, j,textBoxDisplay.getBooleanBox());
textBoxDisplay.setBooleanBox(removeSymbol(customProperty.getValues().toString()));

and this is working perfectly fine. I got the correct values.

NewCodeLearner
  • 738
  • 3
  • 14
  • 38
  • @Keppil when i click on the text box of testDate the popUp is on the textBox of ReceivedOn ant the value of receivedOn text box changes – NewCodeLearner Jul 24 '12 at 09:21

2 Answers2

1

It looks to me textBoxDisplay is the same widget instance for both testingDate and receivedOn. Meaning if the receivedOn is added it overrides the testingDate, hence you get the popup when you click on the icon of testingDate. So you need a textBoxDisplay for both testingDate and receivedOn, like: textBoxDisplayTestingDate and textBoxDisplayReceivedOn

Hilbrand Bouwkamp
  • 13,509
  • 1
  • 45
  • 52
  • I also had suspicion about instantiating the objects – Jama A. Jul 24 '12 at 10:21
  • i am doing the similar coding with boolean list .. AnimationEnabled and testingBoolean.. It is working fine.. Plz check the edited Area. – NewCodeLearner Jul 24 '12 at 10:23
  • With the boolean list you only initialize the listbox and don't add handlers. So the `selectBoolean` is not accessed outside the initialization phase. But `selectBoolean` will be the last initialized listbox. So if you add a change handler it will mean if any of you listbox changes value and you read the value of `selectBoolean` in your handler it will read the value of the last initialized listbox. – Hilbrand Bouwkamp Jul 24 '12 at 11:12
1

This is a referencing issue in the implementation.

On your second iteration of getTimeTxtbx (when you create Received On textbox) you have set the local variable timebx in textBoxDisplay instance to a new reference which is the Received On textbox. Your datePicker's onValueChange implementation set the text on timebx, hence the Received On textbox gets set instead of the testingDate textbox on your second iteration.

Try use a new instance of TextBoxDisplay instead during the iteration.

TextBoxDisplay textBoxDisplay = new TextBoxDisplay();
flexTable.setWidget(i, j,textBoxDisplay.getTimeTxtbx());
textBoxDisplay.setTimebx(customProperty.getValues().toString());
Hailei
  • 42,163
  • 6
  • 44
  • 69
fngaserin
  • 36
  • 5