<commit_before>/* 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.syncope.console.wicket.markup.html.form;

import java.util.Date;
import java.util.StringTokenizer;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.extensions.yui.calendar.DateTimeField;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.model.Model;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.validation.IValidationError;
import org.apache.wicket.validation.ValidationError;

/**
 * DateFieldPanel
 */
public class DateFieldPanel extends Panel {
    /**
     *
     * @param id wicket id
     * @param name component name
     * @param model model object
     * @param datePattern schema attribute date pattern defined for it
     * @param required TRUE if it is required, FALSE otherwise
     * @param readonly TRUE if it can't be valued, FALSE otherwise
     * @param form form where it will be included
     */
    public DateFieldPanel(String id, String name ,final IModel<Date> model,
            final String datePattern, boolean required,boolean readonly,
            Form form) {
        super(id, model);

        if (required) {
            add(new Label("required", "*"));
        } else {
            add(new Label("required", ""));
        }

        Fragment datePanel = null;

        if(!datePattern.contains("H")) {
            datePanel = new Fragment("datePanel","dateField",this);

            DateTextField field = new DateTextField("field", model,datePattern);
            field.add(getDatePicker());

            field.setEnabled(!readonly);
            field.setLabel(new Model(name));

            datePanel.add(field);
        }

        else {
            datePanel = new Fragment("datePanel","dateTimeField",this);
<commit_msg>Fix on Date component for invalid values<commit_after>/* 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.syncope.console.wicket.markup.html.form;

import java.util.Date;
import java.util.StringTokenizer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.extensions.yui.calendar.DateTimeField;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.model.Model;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.validation.IValidationError;
import org.apache.wicket.validation.ValidationError;
import org.apache.wicket.datetime.markup.html.form.DateTextField;
//import org.apache.wicket.extensions.markup.html.form.DateTextField;
/**
 * DateFieldPanel
 */
public class DateFieldPanel extends Panel {
    /**
     *
     * @param id wicket id
     * @param name component name
     * @param model model object
     * @param datePattern schema attribute date pattern defined for it
     * @param required TRUE if it is required, FALSE otherwise
     * @param readonly TRUE if it can't be valued, FALSE otherwise
     * @param form form where it will be included
     */
    public DateFieldPanel(String id, String name ,final IModel<Date> model,
            final String datePattern, boolean required,boolean readonly,
            Form form) {
        super(id, model);

        if (required) {
            add(new Label("required", "*"));
        } else {
            add(new Label("required", ""));
        }

        Fragment datePanel = null;

        if(!datePattern.contains("H")) {
            datePanel = new Fragment("datePanel","dateField",this);

           DateTextField field = DateTextField.forDatePattern("field", model,
                   datePattern);

            field.add(getDatePicker());

            field.setEnabled(!readonly);
            field.setLabel(new Model(name));

            datePanel.add(field);
        }

        else {
            datePanel = new Fragment("datePanel","dateTimeField",this);

{'fraction_non_alphanumeric': 0.10135013501350135, 'fraction_numerical': 0.00144014401440144, 'mean_word_length': 3.1431767337807606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1569778', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1504, 'n_words': 436}