I have jQuery modal div which displays on an on-click event....
<div id="time_scheduler" style="display: none;" title="Change Event Time" class="dialog">
<div class="block">
<h:form>
<span>Select Shift</span>
<p></p>
<h:selectOneMenu value="#{fieldController.shift}">
<f:selectItems itemLabel=" #{s.shiftName} #{s.startTime} to #{s.endTime}" var="s" value="#{fieldController.allShiftUnfiltered}" />
<f:converter converterId="shconvert" />
</h:selectOneMenu>
<p></p>
<h:commandButton onclick="getShift('#{request.contextPath}/changeEvent?','#{fieldController.shift.startTime}','#{fieldController.shift.endTime}');" styleClass="btn btn-small" value="change" />
</h:form>
</div>
</div>
and also a javascript function in a js file which gets called in a commandButton , the problem is each time the page displays , i get a null on the selectOneMenu after i click, then later i get the value, although its inconsistent,
function getShift(url,start_time,end_time){
console.log('starttime is '+start_time); //start time is null on page first load
console.log('endtime is '+end_time); //end time is null on first page load
$.ajax({
url: url + 'event_id=' + event_id + '&start_time=' + start_time + '&end_time=' + end_time,
cache: false,
success: function(value) {
console.log(value);
}
});
}
I have a converter class
@FacesConverter(value = "shconvert")
public class ShiftConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
AdminEJB adm;
try {
adm = (AdminEJB) new InitialContext().lookup("java:global/ffm/AdminEJB");
return adm.findShift(value);
} catch (NamingException ex) {
return null;
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value.toString();
}
}
which pretty much does the conversion at a postconstruct level, what could really be the best way to pass this values to the javascript function each time the is changed ?