2

I have a problem related to Date type which I'm using in smartgwt.

I set up the date to have the possibility to change it manually:

setAttribute("useTextField", true); 

In Firefox and Chrome (and maybe other browsers , except Internet Explorer) if first I'm selecting a date with that pop-up calendar and than change it manually and then let the focus on the date field and going to save the document (actually is a form with multiple fields) the date changed manually it is lost, the date choosed from calendar it is saved. This is not happening in Internet Explorer.

In all browsers, if I select from Calendar a date and than change it manually and change the focus from it everythings goes fine - the manually changed date it is saved into db. Need some advices.

Thank you a lot.

Later edit:

I'm using com.smartgwt.client.widgets.form.fields.DateItem widget.

DateItem date = new DateItem("A date");
date.setWidth(320);
date.setWrapTitle(false);
date.setAttribute("useTextField", true); 
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");

I'm adding this date on a DynamicForm:

DynamicForm  form = new DynamicForm();
form.setFields(date);

and this form on a VLayout object:

VLayout editLayout = new VLayout(30);
editLayout.addMember(form);

The problem is reproducing in browsers like Firefox & Chrome when:

  1. I'm selecting first the date from calendar - say I'm selecting 2011/02/11
  2. I'm changing the day in 2011/02/12 manually - and I'm not changing the focus from this date field
  3. I'm pressing the 'Save' button.

After these steps the date is 2011/02/11 and not 2011/02/12 how it should be. In Internet Explorer browser did not happen - the date after the steps above is 2011/02/12!

Later edit:

I'm using a DataSource for updating the data.

I'm having a UserObject and in the userUpdate method I'm creating this user object first with values from fields (which are on the DynamicForm) - by calling the generateUserObjectFromForm() method

UserObject   user = generateUserObjectFromForm(); 

Here, in this method I'm doing something like: user.setAddedDate(date.getValueAsDate()), but here the date.getValueAsDate() value is the one selected from calendar, not the one modified manually.

I've tried also with:

date.getValue() //Fri Feb 11 00:00:00 GMT+200 2011  
date.getValueField() // null
date.getValueAsDate() //Fri Feb 11 00:00:00 GMT+200 2011
date.getDisplayField() //null
date.getDisplayValue()//l2011/02/11

but none worked properly.

I'm using an request object (UserUpdateRequest) for updating the user.

UserUpdateRequest looks like:


public class UserUpdateRequest implements IsSerializable
{
    UserObject user = null;

    public UserUpdateRequest ()
    {
    }

    public UserUpdateRequest (UserObject user)
    {
        this.user = user;
    }

    public UserObject getUser ()
    {
        return user;
    }
}

final UserUpdateRequest request = new UserUpdateRequest(user);

and on the RPC user update method I'm sending this UserUpdateRequest request.

Later edit (15 february):

I've discovered why is happening this issue related to focus, and this is because in the project I'm not using a Button object - and a com.google.gwt.event.dom.client.ClickEvent for it. I'm using a personalized widget:

package de.vogella.gwt.helloworld.client;
import com.smartgwt.client.widgets.Label;

public class buttonLabel extends Label
{
    public buttonLabel (String text, String elementID)
    {
        super();
        setContents(text);
        setAutoWidth();
        setBaseStyle("wwHoverLabel");
        setShowRollOver(true);          
    }

}

and this use com.smartgwt.client.widgets.events.ClickHandler().

Anyway I do not know how to resolve this ....

I've created a small project with this issue where I've put also a Button object (Save1) and also a personalized button buttonLabel (Save2) - both with clickhandlers.

Here is the link where you can download sources of this small project I've created: link

Case1: say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save1 - everything works fine - the date remains 2011/02/17

Case2-a - line Window.alert("2 " + date.getValue()); un-commented: say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2 - in the warning message date value is 2011/02/16 but in the field date remains 2011/02/17

Case2-b - line Window.alert("2 " + date.getValue()); uncommented: say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2 - the value from field date is automatically changed to 2011/02/16

Later later edit:

Since I can't figure out how to solve my problem I'm thinking for the moment at a temporary solution. So, I have:

DateItem date = new DateItem("Adate");
date.setWidth(120);
date.setWrapTitle(false);
date.setAttribute("useTextField", true); 
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");

Because the attribute useTextField is set to true we can see the text entry field. How can I make this text entry field to be un-editable. Actually I want to have only the possibility to choose the date from calendar and not to change it manually.

Paul
  • 3,812
  • 10
  • 50
  • 73
  • @Paul it would probably help if you showed us a little more code than you do at the moment, as it is now it is very difficult to tell what is happening purely from your explanation. – Mia Clarke Feb 10 '11 at 14:24
  • @Paul Thanks for the edit, now I understand what you mean. Are you using a DataSource to update your data, or are you doing this manually? What does the request look like when you get it to the server? – Mia Clarke Feb 11 '11 at 09:18
  • I've updated the question again. I'm not very sure I've response to your questions. I'm new in gwt ... and I'm facing with these kind of problems on a big project ... – Paul Feb 11 '11 at 10:49
  • 1
    @Paul, I am afraid I don't know what is causing this. I can see that you don't have enough reputation to offer a bounty on this question, so I'll do it for you. With some luck you'll get some answers then. – Mia Clarke Feb 11 '11 at 18:52
  • http://stackoverflow.com/questions/5009896/smartgwt-dateitem-usetextfield-true-how-to-make-text-entry-field-uneditable – Paul Feb 15 '11 at 21:45

1 Answers1

0

The following code should work.

DateItem date = new DateItem("Adate"); 
date.setAttribute("useTextField", true); 
date.setAttribute("inputFormat", "yyyy/MM/dd"); 
date.setAttribute("displayFormat", "toJapanShortDate"); 
TextItem textItem = new TextItem(); 
textItem.setAttribute("readOnly", "true"); 
date.setTextFieldProperties(textItem);
RAS
  • 8,100
  • 16
  • 64
  • 86
  • @Ras: thanks, I've updated the question: "Later edit (15 february)". – Paul Feb 14 '11 at 23:03
  • I've re-updated the question ...make somehow a temporary solution for this issue (http://stackoverflow.com/questions/5009896/smartgwt-dateitem-usetextfield-true-how-to-make-text-entry-field-uneditable) – Paul Feb 15 '11 at 21:44
  • @Ras: Thanks! It works ok with you code with small changes: `textItem.setAttribute("readOnly", true);` and I've used `date.setAttribute("textFieldProperties", textItem);` instead of `date.setTextFieldProperties(textItem);` – Paul Feb 16 '11 at 22:02
  • I observed that if for example I'm choosing from calendar date `2012/02/12` and I want to choose another date in calendar by default is selected today date - but what I want is to be selected the date I've choosed before (`2012/02/12`). How I can resolve this? – Paul Feb 16 '11 at 22:12
  • To be more clear with what I want to say above: The date chooser won't show the date on the text field but Today's date. For example, enter 30/05/2009 on the text field, go to another field, then come back on click on the date chooser and the selected day will be Today's date instead on June 30th, 2009. How can this be solved? – Paul Feb 17 '11 at 07:22
  • 1
    @Paul That's because of the inputFormat applied to dateItem. I don't know why, but it works perfectly if I don't apply inputFormat to dateItem. – RAS Feb 17 '11 at 13:16
  • @RAS: That's great! I've removed `date.setAttribute("inputFormat", "yyyy/MM/dd");` and works fine. Actually `date.setAttribute("displayFormat", "toJapanShortDate");` give the format of the date. "TOJAPANSHORTDATE Short date in format YYYY/MM/DD. Example: 2005/11/4" from [here](http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/types/DateDisplayFormat.html) Thanks. – Paul Feb 17 '11 at 15:48