问题描述:

I am working on JSF with primefaces, i have a calendar field in those when i need to disable some dates , so i have used the attribute named beforeShowDay, but the thing is that when i use this attribute the calendar is not opening(not pop-up) , but when i dont use beforeShowDayattribute it is working ,

My code is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html <!--namespaces-->>

<h:body>

<ui:composition>

<ui:define name="content">

<script type="text/javascript">

function tuesdaysAndFridaysDisabled(date)

{

var day = date.getDay();

return [(day != 2 && day != 5), '']

}

</script>

<h:form>

<p:calendar id="leavefrom" value="#{requestbean.leavefrom}" beforeShowDay="tuesdaysAndFridaysDisabled" effect="drop" pattern="yyyy/dd/MM" required="true" >

<p:ajax update="leaveto" event="dateSelect" />

</p:calendar>

</h:form>

</ui:define>

</ui:composition>

</h:body>

</html>

Any suggestion for this..

网友答案:
return [(day != 2 && day != 5), '']

The & is a special character in Facelets and should have caused the error "The entity name must immediately follow the '&' in the entity reference" from the Facelets compiler. I'm actually surprised that you didn't got it. Perhaps your editor is doing something special with it, or you're actually not running the code as shown in the question. Checking the JSF-generated HTML output in browser should give clues.

In any case, you should be placing the entire script in a <![CDATA[ .. ]]> block:

<h:outputScript>
 <![CDATA[
  function tuesdaysAndFridaysDisabled(date)
  {
    var day = date.getDay();
    return [(day != 2 && day != 5), '']
  }
 ]]>
</h:outputScript>

or, better, be putting it in a standalone JS file /resources/functions.js:

<h:outputScript name="functions.js" />    

Then your code snippet starts to work for me.

相关阅读:
Top