sriram sudhakar
sriram sudhakar

Reputation: 67

Date Picker is not working on my jsf and xhtml file can anyone guide me please

this is my xhtml page where i am using JSF framework when i try this code outside my project it is working but when i try to integrate with my html view it is not working kidly help me to solve this issue

     <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core" 
             xmlns:p="http://primefaces.org/ui"
        xmlns:rich="http://richfaces.org/rich"
         xmlns:a4j="http://richfaces.org/a4j">

        <h:head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>EDPMS Process</title>
    <link rel="stylesheet" href="css/jquery-ui.css" />
     <link rel="stylesheet" href="css/style.css" />

      <link href="css/datepicker.css" rel="stylesheet" />
     <link type="text/css" rel="stylesheet" href="css/bootstrap.css" />
     <link type="text/css" rel="stylesheet" href="css/bootstrap-dropdown.css" />
    <link type="text/css" rel="stylesheet" href="css/headfoot.css" />
    <link href="css/font-awesome.css" rel="stylesheet" />

    <script src="js/jquery-1.9.1.js" type=""></script>
      <script src="js/jquery-ui.js" type=""></script>
     <script src="js/bootstrap.js" type="text/javascript"></script>
      <script src="src/main/webapp/js/bootstrap-datepicker.js" type="text/javascript"></script>
      <script src="js/bootstrap-datepicker.js" type="text/javascript">     </script>
      <script type="text/javascript" src="js/jquery.cookie.min.js"></script>
       <script type="text/javascript" src="js/jquery.collapsible.min.js"></script>
      <script type="text/javascript" src="js/highlight.pack.js"></script>
      <script type="text/javascript" src="js/jquery.cookie.min.js"></script>
      <script type="text/javascript" src="js/jquery.collapsible.min.js"></script>
     <script type="text/javascript" src="js/highlight.pack.js"></script>
     <script name="jquery/bootstrap-datepicker.js" library="primefaces"></script>
      <script src="js/warning.js" type=""></script>
    <link rel="stylesheet" href="css/mytablestyle.css" />*/
    <!-- <link rel="stylesheet" href="css/styles_ti_plus_2.css" /> -->

    <h:outputStylesheet value="css/jquery-ui-1.10.2.custom.min.css" />
    <!-- <link rel="stylesheet" href="css/jquery-ui-1.10.2.custom.min.css" /> -->
    <!-- <h:outputScript name="css/jquery-ui-1.10.2.custom.min.css" /> -->
    <!-- <script type="text/javascript" src="js/jquery-ui.js"></script> -->
    <!-- <script type="text/javascript" src="js/jquery-1.10.2.js"></script> -->

    <!-- <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" /> -->
    <!-- <script src="//code.jquery.com/jquery-1.10.2.js"></script> -->
    <!-- <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> -->
    <!-- <h:outputScript name="js/jquery-ui-1.10.4.custom.min.js"/> -->
                        <div class="form-group">
                            <div style="height:500px">
                                  <div>        
    <h3>Inline</h3>  
   <p:calendar value="#{calendarView.date1}" mode="inline"/>   

    <h3>Popup</h3>  
    <p:calendar value="#{calendarView.date2}" />  

    <h3>Popup Button</h3>  
    <p:calendar value="#{calendarView.date3}" showOn="button" />  

    <p:commandButton value="Submit" update="display" oncomplete="dialog.show()" />  

    <p:dialog header="Selected Dates" widgetVar="dialog"   
        showEffect="fold" hideEffect="fold"  
        height="150">  

    <h:panelGrid id="display" columns="2" cellpadding="5">  

        <h:outputText value="Inline Date:" />  
        <h:outputText value="#{calendarView.date1}">  
            <f:convertDateTime pattern="MM/dd/yyyy"/>  
        </h:outputText>  

        <h:outputText value="Popup Date:" />  
        <h:outputText value="#{calendarView.date2}">  
            <f:convertDateTime pattern="MM/dd/yyyy"/>  
        </h:outputText>  

        <h:outputText value="Popup Button Date: " />  
        <h:outputText value="#{calendarView.date3}">  
            <f:convertDateTime pattern="MM/dd/yyyy"/>  
        </h:outputText>  

       </h:panelGrid>  

       </p:dialog>  
        </div>
                            <h:form> 
                    <h3>LEO DATE</h3>  
          <p:calendar value="#{calendarView.date3}" showOn="button" />  
              <p:dialog header="Selected Dates" widgetVar="dialog"   
                                      showEffect="fold" hideEffect="fold"  
                                        height="150">  

                <h:panelGrid id="display" columns="2" cellpadding="5"> 

                         <h:outputText value="Popup Button Date: " />  
                          <h:outputText value="#{calendarView.date3}">  
                                 <f:convertDateTime pattern="MM/dd/yyyy"/>  
                                 </h:outputText>  

                                </h:panelGrid>  

                                </p:dialog>  
                                </h:form>
                                </div>
                            </div>

Java Code

    package com.misys.tiplus2.controller;

     import java.text.SimpleDateFormat;
     import java.util.Date;
     import javax.faces.application.FacesMessage;
     import javax.faces.bean.ManagedBean;
      import javax.faces.context.FacesContext;

    import org.primefaces.context.RequestContext;
   import org.primefaces.event.SelectEvent;

    @ManagedBean(name = "calendarView", eager = true)
    public class CalendarView {

    private Date date1;
     private Date date2;
     private Date date3;
     public Date getDate1() {
     return date1;
     }
    public void setDate1(Date date1) {
    this.date1 = date1;
    }
    public Date getDate2() {
    return date2;
    }
     public void setDate2(Date date2) {
      this.date2 = date2;
    }
     public Date getDate3() {
      return date3;
    }
     public void setDate3(Date date3) {
       this.date3 = date3;
    }

    public void onDateSelect(SelectEvent event) {
     FacesContext facesContext = FacesContext.getCurrentInstance();
     SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
     facesContext.addMessage(null, new  FacesMessage(FacesMessage.SEVERITY_INFO, "Date Selected",     format.format(event.getObject())));
         }

     public void click() {
    RequestContext requestContext = RequestContext.getCurrentInstance();

    requestContext.update("form:display");
    requestContext.execute("PF('dlg').show()");
}
}

Upvotes: 0

Views: 3595

Answers (1)

stg
stg

Reputation: 2797

PrimeFaces is build on top of jQuery, i.a.

Thus, if you really have to include the jQuery API, then make use of the one, that comes along with PrimeFaces to avoid compatibility issues. This means you should use

<h:outputScript library="primefaces" name="jquery/jquery.js" /> 

instead of <script src="js/jquery-1.9.1.js" type=""></script>

As Kukeltje already mentioned in the comment, you really have to clean up your css and js imports. Antoher example for this is your usage of the date-picker API. You are including it three times or even more:

<script src="src/main/webapp/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="js/bootstrap-datepicker.js" type="text/javascript">     </script>
<script name="jquery/bootstrap-datepicker.js" library="primefaces"></script>

However, within the posted JSF view, there is not even the need to include any of these JS-files, as PrimeFaces does the jobs for you and generates the HTML -including the neccessary JS- automatically.

Furthermore you have to check your xhtml. You are not closing the h:head-tag at all, so this should not even render a valid HTML output.

Last but not least: Please describe your problem, if still present after those changes, from a developers point of view. Statements like is not working kidly do not describe the problem in a proper way.

Upvotes: 2

Related Questions