1

Some context first, I need to select a month using a datepicker and a meter (by his serial), the send a query to a MySql database and get some data to "plot in a flot" graph. I already have working the month, the meter selecter and the query.

What I need now is to have the Flot graph and the datepicker in the same page.

What I have tried:

  • Apparently there is a conflict with the jQuery/javascript libraries, so I already change the datepicker to the same jQuery version of the flot (jquery-1.11.3).
  • Also tried to separate the datepicker of the flot, using another jsp page only for the flot graph.

But still can't manage to get both of the items working well, because the display of the datepicker don't work or the Flot graph doesn't show.

I'm stuck and really need this working.

perfilCarga.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html>

<html>
    <head>               
        <link rel="stylesheet" href="resources/css/jquery-ui-1.10.3.custom.css" type="text/css" />         
        <script type="text/javascript" src="resources/js/jquery-1.11.3.js"></script>
        <script type="text/javascript" src="resources/js/jquery.flot.min.js"></script>          
        <script type="text/javascript" src="resources/js/jquery-ui-1.10.3.custom.js"></script>
        <script type="text/javascript" src="resources/js/datepicker_reg.js"></script> <!-- changes the datepicker lenguage to espanish-->
        <script type="text/javascript" src="resources/js/datepicker_mes.js"></script><!-- fix the datepicker to ommit the day-->
        <script type="text/javascript" src="resources/js/perfil_carga.js"></script><!-- send the meter serial and date to the servlet using ajax-->

        <script type="text/javascript">
            $.datepicker.setDefaults($.datepicker.regional['es']);
        </script>    

        <style>
            .ui-datepicker-calendar {
            display: none;
            }
        </style>       

    <title></title>
    </head>
    <body>
            <table><tr>
                    <td>
            <s:form theme="simple" action="GetProfile" method="POST">

                    Seleccione un medidor:<br>
                    <s:select id="meterList" name="meter" list="meters" />
                    <br>
                    Seleccione una Fecha:<br>
                    <input name="startDate" id="startDate" class="date-picker" />
                    <br><br>
                    <button type="button" id="LoadRecordsButton" onclick="changeContent()">Generar Perfil</button>          
            </s:form>
                    </td>
                    <td>
                        <jsp:include page="flot_graph.jsp" /> 
                    </td>
            </tr></table>
    </body>
</html>

flot_graph.jsp

<html>
    <head>
        <link href="resources/css/flot_plot.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="resources/js/jquery-1.11.3.js"></script>
        <script type="text/javascript" src="resources/js/jquery.flot.min.js"></script>  
        <title></title>
<script type="text/javascript">
var d1 = [[1, 500], [2, 300], [3, 500], [4, 300], [5, 500], [6, 300]];

$(document).ready(function () {
    $.plot($("#placeholder"), [d1]);
});
</script>
    </head>
    <body>
        <center>  
            <div id="placeholder"></div>
        </center>
    </body>
</html>

Update

From the comment of @user3509208 got the following error in the chrome console.

Uncaught TypeError: $(...).datepicker is not a function

In the file datepicker_mes.j (line 2).

$(function() {
    $('.date-picker').datepicker(
        {
            dateFormat: "mm/yy",
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            onClose: function(dateText, inst) {

                function isDonePressed(){
                    return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
                }

                if (isDonePressed()){
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1)).trigger('change');

                    $('.date-picker').focusout();//Added to remove focus from datepicker input box on selecting date
                }
            },
            beforeShow : function(input, inst) {

                inst.dpDiv.addClass('month_year_datepicker');

                if ((datestr = $(this).val()).length > 0) {
                    year = datestr.substring(datestr.length-4, datestr.length);
                    month = datestr.substring(0, 2);
                    $(this).datepicker('option', 'defaultDate', new Date(year, month-1, 1));
                    $(this).datepicker('setDate', new Date(year, month-1, 1));
                    $(".ui-datepicker-calendar").hide();
                }
            }
        });
});
3
  • 1
    Did you Developer Tools in Google Chrome and see what errors are being written to the console. Commented Feb 11, 2016 at 18:43
  • Thanks for your comment @user3509208 question have been updated. Commented Feb 11, 2016 at 20:08
  • Might be a conflict issue with the jquery. Try keeping all the reference of jquery in one page. Remove jquery reference from flot_graph jsp as you are including it in your first jps which already has the reference to jquery. Commented Feb 11, 2016 at 20:19

1 Answer 1

0

So aparently is an "order format" (I really don't know how else call it) problem. After checking the error in console, start googling and find this Answer by @Oladipo Olasemo. So after organize the code as suggested, the problem dissapear.

<html>
    <head>
        <!--  Style sheet references and CSS definitions -->
    </head>
    <body>
        <!-- HTML markup and other page content -->

        <!-- JavaScript references. You could include jQuery here as well and do all your scripting here. -->
    </body>
</html>

Thanks again to @user3509208, his comment lead me to the answer.

Now to plot those graphs!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.