最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jsf - How to obtain the Date value from a p:calendar component in JavaScript? - Stack Overflow

programmeradmin0浏览0评论

I don't know how to obtain the Date value of a <p:calendar> in PrimeFaces ponent using JavaScript

This is my ponent

<p:calendar id="calendarInicio"
            widgetVar="horaInicioSpin"
            value="#{hbean.horaInicial}" timeOnly="true" 
            pattern="HH:mm" required="true"/>

I need to obtain the hour value of the ponent because I'm gonna send that value into other <p:calendar> ponent, using JavaScript. Can anyone give me an idea? Thanks in advance...

I don't know how to obtain the Date value of a <p:calendar> in PrimeFaces ponent using JavaScript

This is my ponent

<p:calendar id="calendarInicio"
            widgetVar="horaInicioSpin"
            value="#{hbean.horaInicial}" timeOnly="true" 
            pattern="HH:mm" required="true"/>

I need to obtain the hour value of the ponent because I'm gonna send that value into other <p:calendar> ponent, using JavaScript. Can anyone give me an idea? Thanks in advance...

Share Improve this question edited Apr 22, 2015 at 18:48 Tiny 28k112 gold badges351 silver badges608 bronze badges asked Apr 22, 2015 at 17:02 MarisolMarisol 551 gold badge2 silver badges8 bronze badges 1
  • Try using PrimeFaces.widgets['horaInicioSpin'] in JavaScript. – Luiggi Mendoza Commented Apr 22, 2015 at 17:48
Add a ment  | 

1 Answer 1

Reset to default 7

PrimeFaces provides a powerful client side API. Make use of it!

  1. Add a widgetName to your calendar. This way it is way easier to handle to ponent on the client side

    <p:calendar widgetVar="mycalendar" ... />
    
  2. write your custom JS, using the PrimeFaces client side API

    <h:form>
         <p:calendar widgetVar="mycal1" timeOnly="true" />
         <p:calendar widgetVar="mycal2" timeOnly="true" />
         <p:mandButton 
          onclick="var d = PF('mycal1').getDate(); d.setHours(d.getHours() + 1); PF('mycal2').setDate(d);" />
    </h:form>
    

Inside JS, you are able to modify the returned date according to your requirements and afterwards use the .setDate() function to set your date in the other calendar.

发布评论

评论列表(0)

  1. 暂无评论