i have used the Swt DateTime. But I get the problem that we cannot send null value through it. it is always declared. So i used the nebulla dateChooserCombo. it's a good one and i can send the null value too. But I faced the problem that unlike the Swt DateTime It is really difficult to switch form one year to another.we have to move everymonth in it. We can explicitly enter the date through the DateChoosercombo but user may not know the date Pattern so it may be difficult for them. Is there any solution for this Problem.Please Do suggest me? is There any way we can enter Null value through swt DateTime?
Then you can add checkbox which will enable or disable the DateTime widget, and let user to decide if he/she wants to define the date or not..
but user may not know the date Pattern so it may be difficult for them
So tell them the pattern (e.g. in a Label or in the tooltip for DateChooserCombo).
is There any way we can enter Null value through swt DateTime?
No.
Related
I'm trying to obtain a valid Date as input, with format dd/mm/yy and I do want the Formatted Field to automatically change the value when the input is something along the lines of 01/12/1992 or -4/12/-16. Until here it's all already done and ok.
But is there any way, in which I can trigger an event (e.g. a pop-up window) when the Formatted Field does this conversion?
Thanks.
edit: If someone sees this, I didn't find a solution and finally decided I don't care enough to solve it.
I have a java web app, where one of the functionalities I need, is to fetch an existing date, and have the option of editing the date, by selecting another. This works really good with a JQuery DatePicker that I found, in combination with a regular input field, type text, that triggers the datepicker.
My existing date (GregorianCalendar) objects are loaded from a database, and parsed into JavaBeans, and further loaded into the jsp page, and the specific input field.
However, Java's SimpleDateFormat, JSTL functions-tag library, and DatePicker's formatDate function! does not interpret formatting styles the same way. MM in java and JSTL gives "03", while in the DatePicker, it gives "March" as output. My desired "03" is achieved by the pattern mm in DatePicker, but then it shows the objects minutes, if any, in JSTL.
I figure there are two options. Either I create two patterns which can format the different outputs to the same desired String. Or I could use datePickers formatDate-function to format my java date object upon loading of the data.
I much desire to have only one global string pattern for my datepicker, because I want to be able to change the pattern without breaking the code, or having to many dependencies. Therefor solution number 2 is what I want.
Right now, this is my code for getting the formatted date String, using tag libraries:
<fmt:formatDate type="date"
pattern="${appdata.dateFormat}"
value="${myBeanObject.gregorianCalendarObject.time}">
</fmt:formatDate>
I want something like:
$.datepicker.formatDate( ${appdata.dateFormat},
${myBeanObject.gregorianCalendarObject.time});
However, with my limited JQuery/Javascript experience, I do not know how or where to put this code, and how to invoke the function correctly. Everything I seem to find about invoking scripts seem to involve an onclick, or "ready"-functions. I merely want to get the string, while building the page.
I realise that my problem is more basic than my title, but if anyone has another idea on how to get java's and the DatePicker's formatting patterns to play along, I would be happy to hear them. If not, how can I invoke the script, and get that String I want?
Thanks in advance.
EDIT
So far I have added a small parser in my singleton applicationwide data object. When setting the dateFormat-string, it automatically parses the String to one that is matching JQuery DatePicker's mismatching interpretation. But to make this really work, I would need to add a whole lot of possible translations, other than month and year-patterns.
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
datePickerFormat = dateFormat.replaceAll("yyyy", "yy");
datePickerFormat = datePickerFormat.replaceAll("M", "m");
}
I got one application that can switch language between English and Germany. When in Germany language i want the currency display will auto convert into German format. Therefore in my program i have to do checking for the locale then convert the currency based on the language selected. I choose to use locale.setDefault() but i not sure whether this will has any risk or not based on below statement which i found. Can somebody advise for this?
Statement:
"Since changing the default locale may affect many different areas of functionality, this method should only be used if the caller is prepared to reinitialize locale-sensitive code running within the same Java Virtual Machine."
Thanks.
That warning means that if you've already had code that initialized based on a different locale, then it won't magically hear about the locale change and update. For example, if you already set up your title bar and menus and button labels in English and then call setDefault(Locale.GERMANY), all of the text will still be in English. Your example sounds like you won't be changing the locale after startup, so just make sure that you call setDefault early, before you do anything that depends on the locale.
I want to know if there is a way to force the input format for a date in struts, something like dd/MM/yyyy .
The date is written in a text field. I read that this is a locale sensitive subject, but it seems a too much to switch locales for a simple changing of format.
I know I could call addFieldError(fieldName, errorMessage) inside the method of my Action class but to me it feels like a date format should have been thought of to be configured in an Action-validation.xml file. I searched to configure this with properties file but found no working example.
Is using a custom StrutsTypeConverter and addFieldError(fieldName, errorMessage) the only way to do it? Or is there another version of struts in which the date format inputed in a text field can be specified?
UPDATE:
I assumed I made myself clear enough but some answers demostrate otherwise.
The use case is: User enters manually a date in an arbitrary format in a textfield, afterwards struts2 validates the date format as corresponding to the format set by the programmer or not, displaying a message accordingly.
A jQuery date picker with a <s:date> tag can be an alternative to what I want to achieve, but it it NOT what I asked. Furthermore, Javascript can be disabled, rendering the date picker useless, jQuery being a Javascript library as far as I understand it.
My action implemented ModelDriven but the date format can't be supplied anywhere to be forced in the text field, I did use my own validator, but I changed the mapping of the form element to be a String named in the action class, then used a validator with a SimpleDateFormat with the format retrieved from a resource bundle to convert it to a date, then formated the date again, to see if the representation is the same as the one inputed in the text field. Hardly after all that the format is clear. If there are other suggestions I welcome them, this seems like the only choice.
I find this drawback at the very least annoying.
If you want to have a specific format of date on your page, i will advise you to use struts 2 jquery datepicker. You can find a demo of this following this url. Go to widgets tab, select datepicker.
I'm currently working on a Swing app and I've got a few JTextAreas that are going to be parsed, turned into dates and then added to a MySQL database. One is a Date field, the others are DateTime, what I'm trying to do is use InputVerifier to make sure they're entered correctly.
I've created an InputVerifier that tries to turn the text into a date useing DateFormat.parse() and that mostly works, however there are two flaws:
Firstly it can't check if I only have a Date, rather than a date and time
Secondly it can't check if I have both a date and time, rather than just one of them.
Is there any way around this? Or a better way to validate date fields in Swing I'm not aware off?
Swing has support for entering dates into text fields using a JFormattedTextField with a DateFormatter. With a DateFormatter you can specifiy a DateFormat object so can have either a date only field or a date and time field.
Have a look at How To Use Formatted Text Fields in the Swing tutorial as an introduction.
Just a thought: you could consider using a SpinnerDateModel with a JSpinner, instead of a text field. Maybe you could handle the date-only field by calling setCalendarField(Calendar.DAY) - never done it myself, though, so I'm not sure.