dimanche 31 janvier 2016

How to Dynamically change a field value in the jsp on click of checkbox?

This is my Jsp in which these are the elements. Now my question is, how can i change the offset date () which i set in my struts action class on click of the checkBox?

Offset date is nothing but disabling the dates till some decided date, suppose on checking the checkbox, the user can select dates after 2 days On deselcting, user can select after 1 day.

At present my logic works fine : on load of the screen, the proper offset date is selected, but i dint find the logic on how to dynamically call that method and change the offset date on click of the checkbox. Do I hv to submit the form each time on click of checkbox .. If yes how?

<script type="text/javascript">
function showRow() {

    var check = document.getElementById('check');
    var divObj = document.getElementById('hiddenrow');
    divObj.style.display = "none";
    check.onclick = function() {
        if (divObj.style.display == ''){
        divObj.style.display = 'none';
        }
        else
        {
        divObj.style.display = '';
        }
    }
}
window.onload = function() {
    showRow();
}

</script>
<s:actionerror cssClass="actionError" /> <s:form id="documentForm"
    namespace="/secure/ptu" action="updateTimingDetails"
    method="post">
    <table class="columns" style="margin-top: 1em;">

            <tr>
                <s:select label="Distribution Type"
                    list="#{'Mail By Date':'Mail By Date','Mail On Date':'Mail On Date'}"
                    name="mailOption" value="2" />
            </tr>
            <tr>
                <td>Distribution Date:</td>
                <td colspan="3"><input type="text" maxlength="10" id="mailDate"
                    name="mailDate" type="text" size="10" value="${mailDate}" /></td>
            </tr>
            <tr></tr>
            <tr align="left">
                <td><s:label for="check">
                    <input type="checkbox" name="check" id="check" size="20" value="true" />
                     Rush/Expedite</s:label></td>
            </tr>
        <tbody id="hiddenrow" style="display: none;">
            <tr>
                <td>Expedite Code:</td>
                <td><s:select
                    list="A list"
                    name="expediteCode" headerKey="-1" value="expediteCode"
                                    headerValue="--Select--" theme="simple"/></td>
                <td>Expedite Comment(optional):</td>
                <td><s:textarea theme="simple" name="expediteComment" cols="20"
                    rows="3"></s:textarea></td>
            </tr>
        </tbody>
    </table>
    <s:include value="/secure/ptu/ptuBottomNavigation.jsp" />
</s:form></div>

</body>
<script type="text/javascript">
            new Datepicker('mailDate', 
            {
                'dateFormat': 'm/d/Y',
                'notBefore': '<s:date name="startDateOffset" format="dd-MM-yyyy" />'
            }
            );

    </script>

Inside Action Class,

 public final Date getStartDateOffset()
    {
        return startDateOffset;
    }

    public final void setStartDateOffset(Date startDateOffset)
    {
        this.startDateOffset = startDateOffset;
    }

    /**
     * Sets the offset for the date as per Ptu business requirement
     */
    private void setDistributionDateOffset()
    {
        System.out.println("setDistributionDateOffset");
        Date currentSystemDate = new Date();
        Calendar c = GregorianCalendar.getInstance();
        //
        if(c.get(Calendar.HOUR_OF_DAY) > hour)
        {
            setStartDateOffset(DateUtils.addDays(currentSystemDate, 1));
            System.out.println("Calendar.HOUR_OF_DAY >10");

        }

        else
        {
            System.out.println("currentSystemDate is set----");
            setStartDateOffset(currentSystemDate);
        }

    }

This helps me get the offset date.




Aucun commentaire:

Enregistrer un commentaire