voyent
ace:dateTimeEntry acessing month  XML
Forum Index -> Components
Author Message
juhaszg

Joined: 27/Apr/2017 06:13:52
Messages: 2
Offline


Hello!

I have a simple ace:dateTimeEntry, rendered as not a popup. When I change the month there is no change in the selected value, however on the server side I need to do some work which depends on the actual month (which is shown on the screen). Is there any way to get the actual month, without clicking on a day?

For example:
<div
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns="http://www.w3.org/1999/xhtml">

<ace:dateTimeEntry id="testCalendar"
value="#{calendarBean.selected}">
<ace:ajax event="dateSelect" execute="@this" render="@all"
listener="#{calendarBean.newDay}" />
</ace:dateTimeEntry>
</div>

in the bean I need something like this:
CalendarBean{
Date month;
...
public void setMonth(****){
month = *****;}
...
}

Thank you!

Gergely Juhasz
artzambrano

Joined: 21/Mar/2007 00:00:00
Messages: 177
Offline


There are no listeners or ajax events for the month change, since it only occurs in the client. However, there's a way to find out the month number by using some Javascript and the jQuery UI API. Here's some code to get you started:

Code:
 			<h:inputHidden id="monthValueHolder" value="#{bean.monthNumber}"/>
 			<h:outputText value="#{bean.monthNumber}"/>
 			<script type="text/javascript">
 				ice.ace.jq(function(){
 					var c = ice.ace.instance('form:cal'); // client id of the ace:dateTimeEntry component
 					if (c) {
 						c.jq.datepicker('option', 'onChangeMonthYear', function(year, month) {
 							var monthValueHolder = document.getElementById('form:monthValueHolder');
 							monthValueHolder.value = month;
 							ice.s({}, monthValueHolder);
 						});
 					}
 				});
 			</script>
 


The idea is to register the onChangeMonthYear event on the jQuery UI datepicker widget (http://api.jqueryui.com/datepicker/#option-onChangeMonthYear) and use it to update a hidden field. Then, we submit the whole form. In the code above, this hidden field will be updated with the month value (1-12) and the form will be submitted, updating its value in the server, and, then, because the value is bound to an h:outputText as well, the value will be displayed on the page. What you want to do is to add a valueChangeListener to the hidden input to do whatever operation you intend to do. You still need to polish and perfect this solution, since you'll have to make sure to re-apply this script if the ace:dateTimeEntry component is reloaded on the page, but this is some good code to get you started.

Art Zambrano
ICEsoft Technologies Inc.
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team