on 07-13-2006 1:02 PM
Hi all,
I have a requirement like in my view there will be two popup buttons from where i can select Dates and the there will be one more button, when i click on this, it should display the difference between the 2 selected dates. How this could be done in WD.
Any ideas.....help me
Thanks in advance
regards,
Ganesh
Hi,
Try this:
1. In your view, have two input fields for the two date objects. Bind them to two different context attributes of type date.
2. This will give you two buttons next to the two input fields. On click of these buttons, you will get the calendar pop up from where you can select the dates.
3. Now in your view have one more button and attach a event say "calculateDateDiff" to the onAction event of this button.
4. In the eventhandler for this event, use the following code:
java.util.Date date1 = wdContext.currentContextElement.getDateOne();
java.util.Date date2 = wdContext.currentContextElement.getDateTwo();
Calendar cal1 = null;
Calendar cal2 = null;
cal1=Calendar.getInstance();
cal2=Calendar.getInstance();
// different date might have different offset
cal1.setTime(date1);
long ldate1 = date1.getTime() + cal1.get(Calendar.ZONE_OFFSET) + cal1.get(Calendar.DST_OFFSET);
cal2.setTime(date2);
long ldate2 = date2.getTime() + cal2.get(Calendar.ZONE_OFFSET) + cal2.get(Calendar.DST_OFFSET);
// Use integer calculation, truncate the decimals
int hr1 = (int)(ldate1/3600000); //60*60*1000
int hr2 = (int)(ldate2/3600000);
int days1 = (int)hr1/24;
int days2 = (int)hr2/24;
int dateDiff = days2 - days1;
Bind this dateDiff to some context attribute of type int and then push it to your view.
Regards,
Satyajit.
P.S. You need to close your previous threads.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have created 2 input fields and bound the two to two context attributes of type Date. But i could not get the buttons next to them. Can you be more clear how to bind? May be i went wrong some where.!
<b>>>2.This will give you two buttons next to the two input fields. On click of these buttons, you will get the calendar pop up from where you can select the dates.</b>
Please suggest me
Thanks a lot
Hi,
I created two variables in Context by selecting value attributes of type date.
<b>Then for inputfield1 value i selected date1 which is my context attribute (of type date), i have done same for inputfield2.</b>Still i could not get the small buttons as you said.
Plesae suggest me
Thanks a lot
Hi
I have created a View and created 2 input fields and on the <b>value</b> i selected date1 which is my context attribute (of type date). I created exactly like what you said:
>>Create two context attributes of type date. Select this "date" from the dropdown that you get when you go to the "type" property of the context attribute.
Even i have given value as 3 for Colcount of RootUIElementContainer. What else to do and where I went wrong?
Help me
Thanks
Hi,
I have not written a single line of code, and deployed and the result is nothing... not even my input fields are not displayed. <b>Any code is to be implemented? if so where do i implement the code in which methodds? what exactly is the code that i should write?</b>. Please help me.
Thanks a lot
Hi,
1.First create two context attributes and set the type "DATE" using the dropdown in the properties of context attribute.
2.Create two inputfields in the view and bind those attributes to the inputfields. Ensure these inputfields are visible.
3.No coding is necessary.Deploy the application and give some string in the date inputfields to ensure it is date type.
Hope this will help you.
Regards,
Saravanan K
Hi,
I have changed some part of design and added date diff to <b>calculate difference between the 2 dates and deployed, but
am not getting the effect a button is added and one input is also added these 2 are not coming when i deploy and ran the same application</b>. How to rectify this? and also let me know how to close the thread
regards,
Ganesh
Hi,
1. Apart from the two inputfields that you have defined for the two dates, you must have created one more inputfield to display the date difference. Bind the "value" property of this inputfield to some context attribute, say DateDifference, of type String.
2. You must have created a button on click of which you need to calculate the date difference. For the OnAction event of this button, write the code to calculate the difference of dates.
3. Now after you have calculated the date difference and stored in some local variable say dateDiff, write this code:
wdContext.currentContextElement.setDateDifference(dateDiff);
4. Build and deploy and run your application. Tell us what you get.
Btw you can close a thread by marking one of the answers as "Solved Problem" or your own post as "Solved on my own".
Regards,
Satyajit.
Dear jonna,
You can parse the month, day, year, hour second from the dates and calculate the difference.
Kind regards,
Saravanan K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Assuming that u have bound the UI elements to context attribtutes date1 and date2 . You can do this
Date date1 = wdcontext.nodeXX().currentElement().getAttributeValue("Date1");
Date date2 = wdcontext.nodeXX().currentElement().getAttributeValue("Date2");
diff = date1- date2;
wdcontext.nodeXX().currentElement().setAttributeValue("Diff",diff);
Regards,
Arun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.