javagwtgwt2gwt-widgets

SetDate in textBox?


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.


Solution

  • 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());