/**
   * Constructor
   *
   * @param id component id
   * @param date date for the field
   * @param rowModel date for the data row
   * @param column column to which this panel belongs
   * @param dc Converter for the data to display
   */
  public DateTextFieldPanel(
      String id,
      final IModel<Date> date,
      IModel<I> rowModel,
      AbstractColumn<M, I, S> column,
      DateConverter dc) {
    super(id, column, rowModel);

    DateTextField tf = newDateTextField(DateTextField_ID, date, dc);
    tf.setOutputMarkupId(true);
    tf.setLabel(column.getHeaderModel());
    add(tf);
  }
    /** {@inheritDoc} */
    @Override
    protected void onComponentTag(ComponentTag tag) {
      super.onComponentTag(tag);

      if (!isValid()) {
        tag.put("class", "imxt-invalid");
        FeedbackMessage message = getFeedbackMessages().first();
        if (message != null) {
          tag.put("title", message.getMessage().toString());
        }
      }
    }
Example #3
0
  /**
   * Construct a new YUIDateField.
   *
   * @param id the Wicket id for the editor.
   * @param model the model.
   * @param metaData the meta data for the property.
   * @param viewOnly true if the component should be view-only.
   */
  public YUIDateField(String id, IModel<Date> model, ElementMetaData metaData, boolean viewOnly) {
    super(id, model, metaData, viewOnly);

    type = metaData.getPropertyType();
    boolean displayTz = false;
    Component metaDataComponent = metaData.getBeanMetaData().getComponent();
    Localizer localizer = metaDataComponent.getLocalizer();
    if (Time.class.isAssignableFrom(type)
        || java.sql.Date.class.isAssignableFrom(type)
        || Date.class.isAssignableFrom(type)
        || Timestamp.class.isAssignableFrom(type)) {
      fmt =
          localizer.getString(
              DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR);
    } else if (Calendar.class.isAssignableFrom(type)) {
      fmt =
          viewOnly
              ? localizer.getString(
                  DATE_TIME_FIELD_PREFIX + "datetz" + FORMAT_SUFFIX,
                  metaDataComponent,
                  DATE_ZONE_FMT_STR)
              : localizer.getString(
                  DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR);
      displayTz = true;
    } else {
      throw new RuntimeException("YUIDateField does not handle " + type);
    }

    String customFmt = getFormat();
    if (customFmt != null) {
      fmt = customFmt;
    }

    Fragment fragment;
    if (viewOnly) {
      fragment = new Fragment("frag", "viewer");
      fragment.add(DateLabel.withConverter("date", model, new InternalDateConverter()));
    } else {
      fragment = new Fragment("frag", "editor");

      FormComponent dateField =
          DateTextField.withConverter("dateTextField", model, new InternalDateConverter());
      setFieldParameters(dateField);
      fragment.add(dateField);

      dateField.add(
          new DatePicker() {
            private static final long serialVersionUID = 1L;

            @Override
            protected boolean enableMonthYearSelection() {
              return false;
            }

            @Override
            protected CharSequence getIconUrl() {
              return RequestCycle.get()
                  .urlFor(new ResourceReference(YUIDateField.class, "calendar.gif"));
            }
          });

      if (displayTz) {
        DateLabel tzLabel = DateLabel.withConverter("timezone", model, new TimeZoneConverter());
        fragment.add(tzLabel);
      } else {
        fragment.add(new Label("timezone", "").setVisible(false));
      }
    }

    add(fragment);
  }
    public EditItemForm(final String id, final InventoryItem anItem) {
      super(id, new CompoundPropertyModel(anItem));

      /** edited values */
      IChoiceRenderer choiceRenderer =
          new IChoiceRenderer() {
            public String getIdValue(Object object, int index) {
              return object.toString();
            }

            public Object getDisplayValue(Object object) {
              HardwareDevice device = (HardwareDevice) object;
              return (device.getType().getNameType());
            }
          };
      DropDownChoice aDeviceList =
          new DropDownChoice("hardwareDevice", aDAO.getAllDevices(), choiceRenderer);
      add(aDeviceList);
      TextField aNameItem = new TextField("nameItem");
      add(aNameItem);
      IChoiceRenderer choiceRendererUser =
          new IChoiceRenderer() {
            public String getIdValue(Object object, int index) {
              return object.toString();
            }

            public Object getDisplayValue(Object object) {
              User aUser = (User) object;
              return aUser.getNameUser();
            }
          };
      DropDownChoice aUserList = new DropDownChoice("user", aDAO.getAllUsers(), choiceRendererUser);
      add(aUserList);
      IChoiceRenderer choiceRendererLocation =
          new IChoiceRenderer() {
            public String getIdValue(Object object, int index) {
              return object.toString();
            }

            public Object getDisplayValue(Object object) {
              LocationItemInventory aLocation = (LocationItemInventory) object;
              return aLocation.getNameLocation();
            }
          };
      DropDownChoice aLocationList =
          new DropDownChoice("location", aDAO.getAllLocations(), choiceRendererLocation);
      add(aLocationList);

      PropertyModel aInventoryDateModel = new PropertyModel(anItem, "inventoryDate");
      DateTextField aItemDate =
          new DateTextField(
              "inventoryDate", aInventoryDateModel, new PatternDateConverter("MM/dd/yyyy", true));
      DatePicker datePicker = new DatePicker();
      aItemDate.add(datePicker);
      add(aItemDate);

      TextField aPrice = new TextField("price");
      add(aPrice);
      TextField aBudget = new TextField("budget");
      add(aBudget);
      TextField aGuarantee = new TextField("guarantee");
      add(aGuarantee);

      PropertyModel aGuaranteeDateModel = new PropertyModel(anItem, "guaranteeDate");
      DateTextField aGuaranteeDate =
          new DateTextField(
              "guaranteeDate", aGuaranteeDateModel, new PatternDateConverter("MM/dd/yyyy", true));
      DatePicker GuaranteeDatePicker = new DatePicker();
      aGuaranteeDate.add(GuaranteeDatePicker);
      add(aGuaranteeDate);

      TextField aNote = new TextField("note");
      add(aNote);
    }
  private void init() {
    feedback.setOutputMarkupId(true);
    add(feedback);
    CompoundPropertyModel model = new CompoundPropertyModel(new Adherent());
    setModel(model);

    add(new RequiredTextField<String>("nom").add(new FocusOnLoadBehavior()));
    add(new RequiredTextField<String>("prenom"));
    add(
        new RequiredTextField<String>("numeroLicense", String.class)
            .add(new PatternValidator("\\d{6}")));

    // numéro de téléphone au bon format (10 caractères numériques)
    RequiredTextField<String> telephone = new RequiredTextField<String>("telephone", String.class);
    telephone.add(ExactLengthValidator.exactLength(10));
    telephone.add(new PatternValidator("\\d{10}"));
    add(telephone);

    add(new RequiredTextField<String>("mail").add(EmailAddressValidator.getInstance()));

    // Ajout de la liste des niveaux
    List<String> niveaux = new ArrayList<String>();
    for (NiveauAutonomie n : NiveauAutonomie.values()) {
      niveaux.add(n.toString());
    }
    add(new DropDownChoice("niveau", niveaux));

    // Ajout de la liste des aptitudes
    List<String> aptitudes = new ArrayList<String>();
    for (Aptitude apt : Aptitude.values()) {
      aptitudes.add(apt.name());
    }
    add(new DropDownChoice("aptitude", aptitudes));

    // Ajout de la liste des niveaux d'encadrement
    List<String> encadrement = new ArrayList<String>();
    for (Adherent.Encadrement e : Adherent.Encadrement.values()) {
      encadrement.add(e.toString());
    }
    add(new DropDownChoice("encadrement", encadrement));

    // Ajout de la checkbox pilote
    add(new CheckBox("pilote", model.bind("pilote")));

    // Ajout des roles
    List<String> roles =
        Arrays.asList(new String[] {"ADMIN", "USER", "SECRETARIAT", "DP", "ENCADRANT"});
    add(new ListMultipleChoice<String>("roles", roles));

    // Ajout du champs date du certificat medical
    DateTextField dateCMTextFiled =
        new DateTextField(
            "dateCM", new PropertyModel<Date>(model, "dateCM"), new StyleDateConverter("S-", true));
    dateCMTextFiled.setRequired(true);
    add(dateCMTextFiled);
    dateCMTextFiled.add(new DatePicker());

    Date dateDuJour = new Date();
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(dateDuJour);
    int anneeCourante = gc.get(Calendar.YEAR);
    int nextAnnee = anneeCourante + 1;

    List<Integer> annees = new ArrayList<Integer>();
    annees.add(new Integer(anneeCourante));
    annees.add(new Integer(nextAnnee));

    DropDownChoice<Integer> listAnnee = new DropDownChoice<Integer>("anneeCotisation", annees);
    listAnnee.setRequired(true);
    add(listAnnee);

    // Ajout de la checkbox TIV
    add(new CheckBox("tiv", model.bind("tiv")));
    // commentaire
    TextArea<String> textareaInput = new TextArea<String>("commentaire");
    textareaInput.add(ExactLengthValidator.maximumLength(45));
    add(textareaInput);

    ContactPanel cuPanel = new ContactPanel("cuPanel", model);
    add(cuPanel);

    add(
        new AjaxButton("validAdherent") {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Adherent adherent = (Adherent) form.getModelObject();
            try {

              ResaSession.get().getAdherentService().creerAdherent(adherent);

              setResponsePage(AccueilPage.class);
            } catch (TechnicalException e) {
              e.printStackTrace();
              error(e.getKey());
            }
          }
          // L'implémentation de cette méthode est nécessaire pour voir
          // les messages d'erreur dans le feedBackPanel

          @Override
          protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedback);
          }
        });

    add(
        new Link("cancel") {
          @Override
          public void onClick() {
            setResponsePage(AccueilPage.class);
          }
        });
  }