the date picker the date does not change in the date text field - wicket

I have an issue with the date Picker in wicket and need help please:
Here is the code when was everything okay :
private void addToDateFieldContainer() {
DateField field = new ReservationDateField("validToDate");
WebMarkupContainer container = new WebMarkupContainer("validToDateContainer");
container.add(field);
container.setVisible(configParams.isShowReservationToDate());
add(container);
}
but I had a problem that the datetext field had a different id from the parent component, so I added some code
private void addToDateFieldContainer() {
DateField field = new ReservationDateField("validToDate"){
#Override
protected DateTextField newDateTextField(String id, PropertyModel dateFieldModel) {
DateTextField dateTextField = DateTextField.forShortStyle(id, dateFieldModel);
dateTextField.setMarkupId(this.getMarkupId());
return dateTextField;
}
};
WebMarkupContainer container = new WebMarkupContainer("validToDateContainer");
container.add(field);
container.setVisible(configParams.isShowReservationToDate());
add(container);
}
now the date text id has the same id for the parent component, but it comes to a different problem :
when I press on the date picker the date does not change in the date text field
here is an image about for the date picker
Does anyone have a clue how I can overcome this issue?

Related

Javafx Datepicker validation

we tried to validate a javafx datepicker. So we use:
if (fromDatePicker.getValue() == null) {
sb.append("No valid from date!\n");
} else {
System.out.println(fromDatePicker.getValue().toString());
if (!DateUtil
.validEnglishDate(fromDatePicker.getValue().toString())) {
sb.append("No valid from date. Use the format yyyy-MM-dd.\n");
}
}
But at the moment it's impossible to get an invalid Date with the datepicker, because all invalid date's are changed to the start value.
So we asked us is it possible to get an invalid Date with the javafx datepicker?
***** EDIT *****
Example: we have the following datepicker:
DatePicker[2015-05-12]
now we entered "fjdfk" in the DatePicker so we have:
DatePicker[fjdfk]
on save the data's the datepicker changes automatical to DatePicker[2015-05-12]
You could use the DatePicker#setConverter(StringConverter<LocalDate>) to catch any parse exception and warn the user in consequence. Here is a sample :
public class SecureLocalDateStringConverter extends StringConverter<LocalDate> {
/**
* The date pattern that is used for conversion. Change as you wish.
*/
private static final String DATE_PATTERN = "dd/MM/yyyy";
/**
* The date formatter.
*/
public static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern(DATE_PATTERN);
private boolean hasParseError = false;
public boolean hasParseError(){
return hasParseError;
}
#Override
public String toString(LocalDate localDate) {
return DATE_FORMATTER.format(localDate);
}
#Override
public LocalDate fromString(String formattedString) {
try {
LocalDate date=LocalDate.from(DATE_FORMATTER.parse(formattedString));
hasParseError=false;
return date;
} catch (DateTimeParseException parseExc){
hasParseError=true;
return null;
}
}
}
From your control, you'll just have to call converter#hasParseError(), converter being the one you set with DatePicker#setConverter(StringConverter<LocalDate>)

In GXT 3 how to access another field in same row during handling of onCompleteEdit event

I have a GridInlineEditing object for GXT 3.0 grid. It all works as expected - I can capture user editing events and find out the row, column and model/change-record for this event.
What I have not figured out is how to best access another control in that row.
Specifically, I have this Column model:
private void initializeColumnModel() {
// Create the configurations for each column in the grid
List<ColumnConfig<Reminder, ?>> ccs = new LinkedList<ColumnConfig<Reminder, ?>>();
typeColumnConfig = new ColumnConfig<Reminder,String>( properties.name(), 120, "Type" );
completedColumnConfig = getDateCellColumn( properties.completed_(), 200, "Completed" );
dueColumnConfig = getDateCellColumn( properties.due_(), 200, "Due" );
applicableColumnConfig = new ColumnConfig<Reminder,Boolean>( properties.applicable(), 140, "Applicable");
// Add column configurations to ColumnModel.
ccs.add(typeColumnConfig);
ccs.add(completedColumnConfig);
ccs.add(dueColumnConfig);
ccs.add(applicableColumnConfig);
applicableColumnConfig.setAlignment(HasHorizontalAlignment.ALIGN_CENTER);
typeColumnConfig.setAlignment(HasHorizontalAlignment.ALIGN_CENTER);
reminderColumnModel = new ColumnModel<Reminder>(ccs);
}
and am attempting to intercept a change to the 'completed date' value and then programmatically operate the 'due date' control (adding a fixed number of years to that as if the user just did it).
Here's how I capture the event:
#Override
public Widget asWidget() {
if(!gridInitialized){
editing = new GridInlineEditing<Reminder>(grid);
DateField dueDateField = getDateField();
DateField completedDateField = getDateField();
editing.addEditor(dueColumnConfig, dueDateField);
editing.addEditor(completedColumnConfig, completedDateField);
editing.addEditor(applicableColumnConfig, new CheckBox());
editing.addCompleteEditHandler(new CompleteEditHandler<Reminder>(){
#Override
public void onCompleteEdit(CompleteEditEvent<Reminder> event) {
GridCell cell = event.getEditCell();
int row = cell.getRow();
int col = cell.getCol();
Reminder rem = reminderStore.get(row);
Store<Reminder>.Record rec = reminderStore.getRecord(rem);
//System.out.println("row:"+row+", col:"+col+", applic:"+rem.getApplicable());
//System.out.println("rec:"+rec.toString());
Change<Reminder, Boolean> applicChange = rec.getChange(properties.applicable());
Change<Reminder, Date> dueChange = rec.getChange(properties.due_());
Change<Reminder, Date> comChange = rec.getChange(properties.completed_());
System.err.print("Row "+(row+1)+" changed: ");
if(applicChange!=null){
boolean applicValue = applicChange.getValue();
System.out.println("applicable changed to "+applicValue);
}
if(dueChange!=null){
Date dueValue = dueChange.getValue();
System.out.println("due changed to: "+SimpleDate.convertFromDate(dueValue));
}
if(comChange!=null){
Date comValue = comChange.getValue();
System.out.println("com changed to: "+SimpleDate.convertFromDate(comValue));
try{
fixDueDate(row,comValue, rem);
}
catch(Exception e){
//boo.
System.err.println("Could not update the due date for this completion date change.");
}
}
}
});
gridInitialized=true;
}
// Initialize the Revert Changes button.
revert.addSelectHandler(new SelectHandler(){
#Override
public void onSelect(SelectEvent event) {
reminderStore.rejectChanges();
}
});
return widget;
}
The method 'fixDueDate' is where I hope to place my logic that adjusts the other column control (another DateField):
private void fixDueDate(int row, Date completedDate, Reminder rem) throws InvalidDateFormatException, InvalidDateException{
SimpleDate newCompDate = new SimpleDate(completedDate);
SimpleDate dueDate = newCompDate.addYears(rem.getRenewalYears());
//rem.setDue(dueDate.getFormattedDate());
//reminderStore.update(rem);
}
thanks.
This works:
private void fixDueDate(int row, Date completedDate, Reminder rem, Store<Reminder>.Record rec )
throws InvalidDateFormatException, InvalidDateException{
SimpleDate newCompDate = new SimpleDate(completedDate);
SimpleDate dueDate = newCompDate.addYears(rem.getRenewalYears());
rec.addChange(dueColumnConfig.getValueProvider(), dueDate.toDate());
}
and the modified field marks appear on both the user modified field and the field modified by this rec.addChange call above.

Show method for DialogFragment not working in Android Version 2.3

I am using DatePicker and Time Picker in my Application but I am getting an error while using it.
See the Code Below :
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day)
{
tv_date_value.setText(String.valueOf(day) + "/" + String.valueOf(month + 1) + "/" + String.valueOf(year));
}
}
This is the Package I have imported after googling :
import android.support.v4.app.DialogFragment;
The Problem occurs when I try to create an object of the DialogFragment and use the show() Method, it says:
The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)
Here is the Code for that:
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(myActivity.getFragmentManager(), "datePicker");
I am getting Error on show() method.
I am using this Date and Time Picker in a Class and not an Activity, So I am giving a reference of that Main Activity Class named : "myActivity".
Can anybody Please help me here???
Thanks,
David.
try using getActivity().getSupportFragmentManager()
use the code below:
android.app.FragmentManager fragmentManager=getActivity().getFragmentManager();
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(fragmentManager,"datepicker");

SmartGwt 2.5 DataSourceDateTimeField i18n validation error

I currently use smartGwt (version 2.5) inside an other framework (Broadleaf).
When i set the locale to french :
Date fields are well formated (DD/MM/YYYY) and the calendar is translated in french but when i change the date and save the form a popup appear with the error message :"Doit ĂȘtre une date" (Must be a date in english). The validator expect a date with MM/DD/YYYY format.
Link to the class used by the framework to create the date field : https://github.com/BroadleafCommerce/BroadleafCommerce/blob/BroadleafCommerce-2.2.x/admin/broadleaf-open-admin-platform/src/main/java/org/broadleafcommerce/openadmin/client/datasource/dynamic/module/BasicClientEntityModule.java
I found a post with same problem (forums.smartclient.com/showthread.php?t=19847) but there is no answer.
Please, let me know how to solve this problem
EDIT :
What i have tried :
#Override
public void onModuleLoad() {
DateUtil.setShortDateDisplayFormat(DateDisplayFormat.TOEUROPEANSHORTDATE);
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
#Override
public String format(Date date) {
if(date == null)
{
return null;
}
else{
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("DD/MM/YYYY");
return dateFormatter.format(date);
}
}
});
Because the code below is not allowed :
DateUtil.setShortDateDisplayFormatter(DateUtil.TOEUROPEANSHORTDATE);
I put my code during the application initialization but the problem still present :-(
Screenshot : http://www.hostingpics.net/viewer.php?id=989088date.png
Do you have an other idea?
Set date formatter of the field to DateDisplayFormat.TOEUROPEANSHORTDATE.
dateItem.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
Also check display seconds in DateTimeItem (SmartGWT) to find another way to set a custom formatted date string when dateItem.useTextField is true.
As the forum thread indicates, its also possible to set default date/datetime format for the application using methods of com.smartgwt.client.util.DateUtil, which should be used only once, during application initialization (e.g.- EntryPoint).
DateUtil.setShortDateDisplayFormatter(DateUtil.TOEUROPEANSHORTDATE);
Problem solved !
You have to use the code below during application initialization :
private static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";
public void onModuleLoad() {
DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
#Override
public String format(Date date) {
if(date != null)
{
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
return dateFormatter.format(date);
}
return null;
}
});
DateUtil.setDateParser(new DateParser()
{
public Date parse(String dateString)
{
try{
if(dateString != null){
final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
return format.parse(dateString);
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
});
}

GWT DatePicker to recognize Calendar Icon click

I'm using a DatePicker widget, and I put a little calendar image next to it. When you click on the actual DatePicker textbox, the calendar popup pops up (as it should). I'm looking to add this click handling to the little calendar image too, so that the user can click either the box or the image to see the calendar popup. Is there an easy way to do this?
I thought it might be something like this:
calendarImage.addClickHandler(datePick.getTextBox().getClickHandler())
But it doesn't seem that anything like this exists.
Thanks in advance!
Just add a clickhandler to the image that sets the datepicker visible.
It will become something like this:
private DatePicker datePicker = new DatePicker();
private TextBox textBox = new TextBox();
private Image icon = new Image("calendar.png");
public void onModuleLoad() {
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
#Override
public void onValueChange(ValueChangeEvent<Date> event) {
Date date = event.getValue();
String dateStr = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM).format(date);
textBox.setText(dateStr);
datePicker.setVisible(false);
}
});
datePicker.setVisible(false);
icon.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
datePicker.setVisible(true);
}
});
RootPanel.get().add(icon);
RootPanel.get().add(textBox);
RootPanel.get().add(datePicker);
}
Assuming you mean DateBox when you write DatePicker, simply call showDatePicker on click of the icon (and/or test isDatePickerShowing and call hideDatePicker)