コード例 #1
0
 private String getCost(List<OrderObject> orderObjects, String name) {
   Double cost = 0.0;
   for (OrderObject object : orderObjects) {
     if (object.getName().equals(name)) {
       cost = object.getCost();
     }
   }
   return cost.toString();
 }
コード例 #2
0
 private List<String> getNames(List<OrderObject> orderObjects, String criteria) {
   List<String> pickedList = new ArrayList<String>();
   for (OrderObject orderObject : orderObjects) {
     if (orderObject.getCountry().equals(criteria)) {
       pickedList.add(orderObject.getName());
     }
   }
   return pickedList;
 }
コード例 #3
0
    public AdminOrderPageForm(String id) {
      super(id);

      errorPanel = new FeedbackPanel("feedback");
      username = new TextField<String>("username", Model.of(""));
      email = new TextField<String>("email", Model.of(""));
      countryCostModel = Model.of("");
      hotelCostModel = Model.of("");
      tourCostModel = Model.of("");

      countryCost = new Label("countryCostLabel", countryCostModel);
      hotelCost = new Label("hotelCostLabel", hotelCostModel);
      tourCost = new Label("tourCostLabel", tourCostModel);

      order = new Order();
      orderDao = new OrderDao();
      hotelOptions = new HashMap<String, List<String>>();
      tourOptions = new HashMap<String, List<String>>();

      countries = orderDao.getCountries();
      hotels = orderDao.getHotels();
      tours = orderDao.getTours();

      for (OrderObject country : countries) {
        hotelOptions.put(country.getName(), getNames(hotels, country.getName()));
        tourOptions.put(country.getName(), getNames(tours, country.getName()));
      }

      IModel<List<? extends String>> makeCountryChoises =
          new AbstractReadOnlyModel<List<? extends String>>() {
            @Override
            public List<String> getObject() {
              return new ArrayList<String>(hotelOptions.keySet());
            }
          };

      IModel<List<? extends String>> modelTownChoices =
          new AbstractReadOnlyModel<List<? extends String>>() {
            @Override
            public List<String> getObject() {
              List<String> models = hotelOptions.get(selectedOption);
              if (models == null) {
                models = Collections.emptyList();
              }
              return models;
            }
          };

      IModel<List<? extends String>> modelTourChoices =
          new AbstractReadOnlyModel<List<? extends String>>() {
            @Override
            public List<String> getObject() {
              List<String> models = tourOptions.get(selectedOption);
              if (models == null) {
                models = Collections.emptyList();
              }
              return models;
            }
          };

      countryDropDown =
          new DropDownChoice<String>(
              "countryDropDown",
              new PropertyModel<String>(this, "selectedOption"),
              makeCountryChoises);

      hotelDropDown =
          new DropDownChoice<String>(
              "hotelDropDown", new PropertyModel<String>(this, "selectedHotel"), modelTownChoices);

      tourDropDown =
          new DropDownChoice<String>(
              "tourDropDown", new PropertyModel<String>(this, "selectedTour"), modelTourChoices);
      totalCostSumModel = new PropertyModel<String>(this, "calculatedTotalCostSum");
      totalCostSum = new TextField("totalCostSumLabel", totalCostSumModel);

      hotelDropDown.setOutputMarkupId(true);
      tourDropDown.setOutputMarkupId(true);
      countryCost.setOutputMarkupId(true);
      hotelCost.setOutputMarkupId(true);
      tourCost.setOutputMarkupId(true);
      totalCostSum.setOutputMarkupId(true);

      countryDropDown.add(
          new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
              target.add(hotelDropDown);
              target.add(tourDropDown);

              String cost = getCost(countries, selectedOption);
              countryCostModel.setObject(cost);
              hotelCostModel.setObject(getCost(hotels, selectedHotel));
              tourCostModel.setObject(getCost(tours, selectedTour));
              totalCostSumModel.setObject(getTotalCostSum());

              target.add(countryCost);
              target.add(hotelCost);
              target.add(tourCost);
              target.add(totalCostSum);
            }
          });
      hotelDropDown.add(
          new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
              hotelCostModel.setObject(getCost(hotels, selectedHotel));
              totalCostSumModel.setObject(getTotalCostSum());
              target.add(hotelCost);
              target.add(totalCostSum);
            }
          });
      tourDropDown.add(
          new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
              tourCostModel.setObject(getCost(tours, selectedTour));
              totalCostSumModel.setObject(getTotalCostSum());
              target.add(tourCost);
              target.add(totalCostSum);
            }
          });
      add(new Label("feedBack", feedBack));
      add(errorPanel);
      add(username);
      add(email);
      add(countryDropDown);
      add(hotelDropDown);
      add(tourDropDown);
      add(countryCost);
      add(hotelCost);
      add(tourCost);
      add(totalCostSum);
    }