0

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..

kark
  • 4,763
  • 6
  • 30
  • 44
  • Check the browser-console. Do any javascript errors occur? Do you maybe have a breakpoint in some javascript function set and therefore the calendar does not pop up? Did you modify some CSS definitions from primefaces calendar? – Manuel Nov 21 '13 at 09:04
  • I dont see any error in console, and the thing is , i am using here for some other purpose, is any thing happen by that and, main problem is the javascript fn is not getting called – kark Nov 21 '13 at 09:10
  • Remove `ui:composition` and `ui:define`. Reduce your page to a minimum, step by step until you find the source of the problem. Remove the `p:ajax` as well for testing purposes. Check if the generated javascript code from Primefaces contains the string `preShowDay`. – Manuel Nov 21 '13 at 09:16

1 Answers1

1
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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Ya i got the error, but by mistake for this question i just copied it from notepad not from my `IDE` that's y n.Thank you very much,, it's blindly worked for me, but i don't get the reason what is use of `<![CDATA[ .. ]]>` block.whether it changes the `JS` format to normal code – kark Nov 22 '13 at 04:04
  • 1
    You're welcome. Click the link behind the error message in my answer for detail. – BalusC Nov 22 '13 at 09:32