简体   繁体   English

在JSF页面中调用Jquery datepicker

[英]Call Jquery datepicker in JSF page

I want to implement Jquery datepicker into JSF page like this example . 我想像这样的示例在JSF页面中实现Jquery datepicker。 So far I managed to call the calendar into JSF input field using this code: 到目前为止,我设法使用以下代码将日历调用到JSF输入字段中:

//For calendar
function calendar(){                                
    // Datepicker
    $('#datepicker').datepicker({
        inline: true,
        showWeek: true,
        firstDay: 1
    });
}

I use this input field to call the code: 我使用此输入字段来调用代码:

<h:panelGroup>
        <div id="datepicker"></div>
        <h:inputText  onfocus="calendar()" value="#{DatabaseController.formMap['userid']}" >                                       
    </h:inputText>
</h:panelGroup>

When I click on the input field the calendar is displayed. 当我单击输入字段时,将显示日历。

在此处输入图片说明

I want to implement the example into the JQuery web site but in my case when I click outside the input field the calendar does not hide as should be. 我想将示例实现到JQuery网站中,但是在我的情况下,当我在输入字段之外单击时,日历不会按原样隐藏。 How I can fix this? 我该如何解决?

Best Wishes Peter 最好的祝福彼得

You can use the classname instead of the id. 您可以使用类名而不是ID。 Put this JS and the end before the </h:body> 将此JS和结尾放在</h:body>

<script type="text/javascript">
    //For calendar
    $(".datepicker").datepicker({
        inline: true,
        showWeek: true,
        firstDay: 1
    });

</script>

And this is the input field with the calendar. 这是日历的输入字段。

<h:inputText styleClass="datepicker" value="#{DatabaseController.formMap['userid']}" >   </h:inputText>

you need to create a event function to run the $( "#datepicker" ).datepicker("hide"); 您需要创建一个事件函数来运行$( "#datepicker" ).datepicker("hide"); line when the element loses focus. 当元素失去焦点时排成一行。 You can do this with something like: 您可以使用以下方法执行此操作:

$("#dateInputElementIdGoesHere").blur(function() {
  $( "#datepicker" ).datepicker("hide");
});

first add this line in JSP page: 首先在JSP页面中添加以下行:

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />



    <script>
      $(function() {
        $( "#form1\\:enddate" ).datepicker();


      });

    </script>

<h:form id="form1">
<div>
     <h:outputLabel for="etmonth" value="End Month" style="font-size:20px"></h:outputLabel>

     <h:inputText id="enddate"  value="" style="width:208px;height:20px;margin-left:28px;"></h:inputText>
</div>  

</h:form>


And note this: 并注意:

description: form1=formid and enddate =inputtext_id

praveen sharma Praveen Sharma

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM