Exemplo n.º 1
0
  private void init() {
    setDefaultModel(new PropertyModel(this, "product"));

    // Feedback
    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setFilter(new ContainerFeedbackMessageFilter(this));
    add(feedbackPanel);

    // Form
    this.form =
        new StatelessForm("form") {
          @Override
          protected void onSubmit() {
            product = productDao.update(product);
          }
        };
    this.form.setVersioned(false);
    add(this.form);

    // Boxes
    if (this.product != null) {
      add(new ReleasesBox("releasesBox", this.product, 100));
      this.form.add(new ReleaseTraitsPanel("templates", this.product));
    } else {
      add(new NoItemsFoundBox("releasesBox", "No product specified."));
      this.form.add(new WebMarkupContainer("templates"));
    }

    // Save as .properties - TODO
    this.form.add(
        new PropertiesDownloadLink(
            "downloadProps", product.getTraits(), product.getName() + "-traits.properties"));

    // Upload & apply .properties
    this.add(
        new PropertiesUploadForm("uploadForm") {
          FileUploadField upload;

          @Override
          protected void onSubmit() {
            Properties props;
            try {
              props = processPropertiesFromUploadedFile();
            } catch (IOException ex) {
              feedbackPanel.error("Could not process properties: " + ex.toString());
              return;
            }

            ReleaseTraits traits = ((Product) getPage().getDefaultModelObject()).getTraits();
            PropertiesUtils.applyToObjectFlat(traits, props);
            productDao.update(product);
          }
        });

    // Danger Zone
    WebMarkupContainer dangerZone = new WebMarkupContainer("dangerZone");
    this.add(dangerZone);

    // Danger Zone Form
    dangerZone.add(
        new StatelessForm("form") {
          {
            // Really button
            final AjaxButton really = new AjaxButton("deleteReally") {};
            really.setVisible(false).setRenderBodyOnly(false);
            really.setOutputMarkupPlaceholderTag(true);
            add(really);

            // Delete button
            add(
                new AjaxLink("delete") {
                  @Override
                  public void onClick(AjaxRequestTarget target) {
                    target.add(really);
                    really.setVisible(true);
                    // really.add(AttributeModifier.replace("style", "")); // Removes
                    // style="visibility: hidden".
                    // super.onSubmit( target, form );
                  }
                });
          }

          @Override
          protected void onSubmit() {
            productDao.deleteIncludingReleases((Product) product);
            setResponsePage(HomePage.class);
          }
        });
  } // init()
Exemplo n.º 2
0
 public static PageParameters createPageParameters(Product prod) {
   return new PageParameters().add("name", prod.getName());
 }