Пример #1
0
 @Override
 public MarkupContainer setDefaultModel(IModel model) {
   if (!(model instanceof CompoundPropertyModel)) {
     throw new WicketRuntimeException("model should be an instnceof CompoundPropertyModel");
   }
   super.setDefaultModel(new Model());
   form.setModel(model);
   return this;
 }
    @Override
    protected void onInitialize() {
      ContentViewOrEditPanel contentViewOrEditPanel =
          new ContentViewOrEditPanel("contentViewOrEditPanel", (IModel<Product>) getDefaultModel());
      SubCategoryViewOrEditPanel subCategoryViewOrEditPanel =
          new SubCategoryViewOrEditPanel(
              "subCategoryViewOrEditPanel", (IModel<Product>) getDefaultModel());
      Form<Product> productEditForm = new Form<Product>("productEditForm");
      productEditForm.setModel(
          new CompoundPropertyModel<Product>((IModel<Product>) getDefaultModel()));

      productEditForm.add(new TextField<String>("number"));
      productEditForm.add(new TextField<String>("name"));
      productEditForm.add(new TextArea<String>("description"));
      productEditForm.add(
          new UrlTextField(ITEM_URL, new PropertyModel<String>(getDefaultModelObject(), ITEM_URL)));
      productEditForm.add(new NumberTextField<Integer>("amount"));
      productEditForm.add(new NumberTextField<Integer>("discount"));
      productEditForm.add(new NumberTextField<Integer>("shippingCost"));
      productEditForm.add(new NumberTextField<Integer>("tax"));
      productEditForm.add(new NumberTextField<Integer>("itemHeight"));
      productEditForm.add(new TextField<String>("itemHeightUnit"));
      productEditForm.add(new NumberTextField<Integer>("itemLength"));
      productEditForm.add(new TextField<String>("itemLengthUnit"));
      productEditForm.add(new NumberTextField<Integer>("itemWeight"));
      productEditForm.add(new TextField<String>("itemWeightUnit"));
      productEditForm.add(new NumberTextField<Integer>("itemWidth"));
      productEditForm.add(new TextField<String>("itemWidthUnit"));
      productEditForm.add(new BootstrapCheckbox("bestsellers"));
      productEditForm.add(new BootstrapCheckbox("latestCollection"));
      productEditForm.add(new NumberTextField<Integer>("rating"));
      productEditForm.add(new BootstrapCheckbox("recommended"));
      productEditForm.add(new NumberTextField<Integer>("stock.maxQuantity"));
      productEditForm.add(new NumberTextField<Integer>("stock.minQuantity"));
      productEditForm.add(new NumberTextField<Integer>("stock.quantity"));

      add(productEditForm.setOutputMarkupId(true));
      add(
          contentViewOrEditPanel
              .add(contentViewOrEditPanel.new ContentEditFragement())
              .setOutputMarkupId(true));
      add(
          subCategoryViewOrEditPanel
              .add(subCategoryViewOrEditPanel.new SubCategoryEditFragement())
              .setOutputMarkupId(true));
      add(new NotificationPanel("feedback").hideAfter(Duration.seconds(5)).setOutputMarkupId(true));
      add(new CancelAjaxLink().setOutputMarkupId(true));
      add(new SaveAjaxButton(productEditForm).setOutputMarkupId(true));
      super.onInitialize();
    }
    @Override
    protected void onInitialize() {
      ContentViewOrEditPanel contentViewOrEditPanel =
          new ContentViewOrEditPanel("contentViewOrEditPanel", (IModel<Product>) getDefaultModel());
      SubCategoryViewOrEditPanel subCategoryViewOrEditPanel =
          new SubCategoryViewOrEditPanel(
              "subCategoryViewOrEditPanel", (IModel<Product>) getDefaultModel());
      Form<Product> productViewForm = new Form<Product>("productViewForm");
      productViewForm.setModel(
          new CompoundPropertyModel<Product>((IModel<Product>) getDefaultModel()));

      productViewForm.add(new Label("number"));
      productViewForm.add(new Label("name"));
      productViewForm.add(new Label("description"));
      productViewForm.add(new Label(ITEM_URL));
      productViewForm.add(new Label("amount"));
      productViewForm.add(new Label("discount"));
      productViewForm.add(new Label("shippingCost"));
      productViewForm.add(new Label("tax"));
      productViewForm.add(new Label("itemHeight"));
      productViewForm.add(new Label("itemHeightUnit"));
      productViewForm.add(new Label("itemLength"));
      productViewForm.add(new Label("itemLengthUnit"));
      productViewForm.add(new Label("itemWeight"));
      productViewForm.add(new Label("itemWeightUnit"));
      productViewForm.add(new Label("itemWidth"));
      productViewForm.add(new Label("itemWidthUnit"));
      productViewForm.add(new Label("bestsellers"));
      productViewForm.add(new Label("latestCollection"));
      productViewForm.add(new Label("rating"));
      productViewForm.add(new Label("recommended"));
      productViewForm.add(new Label("stock.maxQuantity"));
      productViewForm.add(new Label("stock.minQuantity"));
      productViewForm.add(new Label("stock.quantity"));

      add(new EditAjaxLink().setOutputMarkupId(true));
      add(productViewForm.setOutputMarkupId(true));
      add(
          contentViewOrEditPanel
              .add(contentViewOrEditPanel.new ContentViewFragement())
              .setOutputMarkupId(true));
      add(
          subCategoryViewOrEditPanel
              .add(subCategoryViewOrEditPanel.new SubCategoryViewFragement())
              .setOutputMarkupId(true));
      super.onInitialize();
    }
Пример #4
0
  public UserPanel(String id, CompoundPropertyModel userModel) {
    super(id, new Model());
    setOutputMarkupId(true);

    form = new Form("userForm", userModel);

    if (userModel == null) {
      User user = new User();
      user.setRoles(new ArrayList<Role>());
      form.setModel(new CompoundPropertyModel(user));
    }
    add(form);

    name = new TextField("name");
    password = new TextField("password");
    name.setOutputMarkupId(true);
    form.add(name);
    form.add(password);

    Roles roles = settings.getUserManagement().getAllRoles();
    Palette role =
        new Palette("roles", new Model(roles), new ChoiceRenderer("label", "label"), 6, false);
    form.add(role);

    CheckBox admin = new CheckBox("admin");
    form.add(admin);

    form.add(
        new AjaxButton("save", form) {

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form form) {
            User user = (User) form.getModelObject();
            settings.getUserManagement().addUser(user);
            onSave(target);
          }
        });
  }
  public VolunteerProfileView() {
    // hardcode current user, eventually will get user from session
    // currentuser = userDao.getUserByUsername("*****@*****.**");
    currentuser = CustomSession.get().getUser();
    /*Skill sk = new Skill("Animals");
    userDao.deleteAllUserSkills(currentuser);
    userDao.deleteUserHasSkill(currentuser, sk);*/

    // Profile Picture Management========================================================
    uploadProfilePicture = new Form<Void>("uploadProfilePicture");
    Button upload = new Button("upload_photo");
    uploadProfilePicture.add(upload);
    add(uploadProfilePicture);
    // create form for page
    form1 = new Form("form1");

    // set model of form
    form1.setModel(new Model(currentuser));

    // add text boxes to form
    form1.add(email = new TextField<String>("email", new PropertyModel(currentuser, "email")));
    form1.add(
        firstName =
            new TextField<String>("firstName", new PropertyModel(currentuser, "firstName")));
    form1.add(
        lastName = new TextField<String>("lastName", new PropertyModel(currentuser, "lastName")));
    form1.add(street = new TextField<String>("street", new PropertyModel(currentuser, "street")));
    form1.add(city = new TextField<String>("city", new PropertyModel(currentuser, "city")));
    form1.add(state = new TextField<String>("state", new PropertyModel(currentuser, "state")));
    form1.add(zip = new TextField<String>("zip", new PropertyModel(currentuser, "zip")));
    form1.add(
        phoneNumber =
            new TextField<String>("phoneNumber", new PropertyModel(currentuser, "phoneNumber")));
    form1.add(
        description =
            new TextArea<String>(
                "description", new PropertyModel(currentuser, "volunteerDescription")));

    email.setEnabled(false);

    // save button
    form1.add(
        new Button("save") {
          @Override
          public void onSubmit() {
            userDao = new UserDao();
            userDao.update(currentuser);
            this.setResponsePage(VolunteerProfileView.class);
          }
        });

    // cancel button
    form1.add(
        new Button("cancel") {
          @Override
          public void onSubmit() {
            this.setResponsePage(VolunteerProfileView.class);
          }
        });

    // add textfields and textfield buttons
    add(form1);

    // create form for checkboxes
    form2 = new Form("form2");

    // create dao for skills
    // get all skills
    // get user specific skills
    SkillDao skillsDao = new SkillDao();
    ArrayList<Object> skillslist = skillsDao.selectAll();
    ArrayList<Object> userskills = skillsDao.getAllSkillsByUser(currentuser);
    skillsSelect = new ArrayList<String>();

    String[] skillarray = new String[skillslist.size()];

    for (int i = 0; i < skillslist.size(); i++) {
      skillarray[i] = ((Skill) skillslist.get(i)).getName();
    }

    for (int i = 0; i < userskills.size(); i++) {
      skillsSelect.add(((Skill) userskills.get(i)).getName());
    }
    List<String> fixedskills = Arrays.asList(skillarray);

    // simulate user has animal skill while there is no way to add a skill to a user in db
    // skillsSelect.add("Animals");

    // create checkboxes for each skill, with users skills pre-checked
    final CheckBoxMultipleChoice<String> skillsBoxes =
        new CheckBoxMultipleChoice<String>("skills", new Model(skillsSelect), fixedskills);

    // add checkboxes to form2
    form2.add(skillsBoxes);

    // save skills button
    form2.add(
        new Button("saveskills") {
          @Override
          public void onSubmit() {
            // UserDao userDao = new UserDao();
            userDao.deleteAllUserSkills(currentuser);
            for (int i = 0; i < skillsSelect.size(); i++) {
              Skill temp = new Skill(skillsSelect.get(i));
              userDao.insertUserHasSkill(currentuser, temp);
            }
            this.setResponsePage(VolunteerProfileView.class);
          }
        });

    // cancel skills button
    form2.add(
        new Button("cancelskills") {
          @Override
          public void onSubmit() {
            this.setResponsePage(VolunteerProfileView.class);
          }
        });

    // add form2 to page
    add(form2);

    // create form for page
    form3 = new Form("form3");

    // Photo photo = new Photo("Steve pro pic", "", true, true, false,
    // false,"*****@*****.**");

    // set model of form
    // form3.setModel(new Model(photo));

    // form3.add(propic = new Image("propic", new ContextRelativeResource(photo.getLink())));

    // upload new picture button
    form3.add(
        new Button("upload") {
          @Override
          public void onSubmit() {
            // upload a new picture
          }
        });

    add(form3);
  }