Пример #1
0
  public RadioListPage() {

    Form<RadioListPage> form =
        new Form<RadioListPage>("form", new CompoundPropertyModel<RadioListPage>(this)) {
          @Override
          protected void onSubmit() {
            super.onSubmit();
            System.out.println("selected:" + selected);
          }
        };
    add(form);

    final RadioGroup<Person> personRadioGroup = new RadioGroup<Person>("selected");

    ListView<Person> personListView =
        new ListView<Person>(
            "persons",
            new ArrayList<Person>(
                Arrays.asList(
                    new Person("name 1", "vorname 1"),
                    new Person("name 2", "vorname 2"),
                    new Person("name 3", "vorname 3"),
                    new Person("name 4", "vorname 4")))) {
          @Override
          protected void populateItem(ListItem<Person> item) {

            item.add(new Label("name", Model.of(item.getModelObject().name)));
            item.add(new Label("vorname", Model.of(item.getModelObject().vorname)));
            item.add(new Radio<Person>("radio", new Model<Person>(item.getModelObject())));
          }
        };
    form.add(personRadioGroup);
    personRadioGroup.add(personListView);
  }
Пример #2
0
  /** Constructor */
  public RadioGroupPage2() {

    final RadioGroup<Person> group = new RadioGroup<>("group", new Model<Person>());
    final RadioGroup<Person> group2 = new RadioGroup<>("group2", new Model<Person>());
    Form<?> form =
        new Form<Void>("form") {
          @Override
          protected void onSubmit() {
            info("selection group1: " + group.getDefaultModelObjectAsString());
            info("selection group2: " + group2.getDefaultModelObjectAsString());
          }
        };

    add(form);
    form.add(group);
    group.add(group2);

    ListView<Person> persons =
        new ListView<Person>("persons", ComponentReferenceApplication.getPersons()) {

          @Override
          protected void populateItem(ListItem<Person> item) {
            item.add(new Radio<>("radio", item.getModel(), group));
            item.add(new Radio<>("radio2", item.getModel(), group2));
            item.add(new Label("name", new PropertyModel<>(item.getDefaultModel(), "name")));
            item.add(
                new Label(
                    "lastName", new PropertyModel<String>(item.getDefaultModel(), "lastName")));
          }
        };

    group2.add(persons);

    add(new FeedbackPanel("feedback"));
  }
Пример #3
0
  private void initLayout() {
    Form mainForm = new Form(ID_MAIN_FORM);
    add(mainForm);

    ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, model);
    mainForm.add(importOptions);

    final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
    input.setOutputMarkupId(true);
    mainForm.add(input);

    final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
    buttonBar.setOutputMarkupId(true);
    mainForm.add(buttonBar);

    final IModel<Integer> groupModel = new Model<Integer>(INPUT_FILE);
    RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel);
    importRadioGroup.add(
        new AjaxFormChoiceComponentUpdatingBehavior() {

          @Override
          protected void onUpdate(AjaxRequestTarget target) {
            target.add(input);
            target.add(buttonBar);
          }
        });
    mainForm.add(importRadioGroup);

    Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup);
    importRadioGroup.add(fileRadio);

    Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup);
    importRadioGroup.add(xmlRadio);

    WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE);
    addVisibileForInputType(inputAce, INPUT_XML, groupModel);
    input.add(inputAce);

    AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel);
    aceEditor.setOutputMarkupId(true);
    inputAce.add(aceEditor);

    WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL);
    addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel);
    input.add(inputFileLabel);

    WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE);
    addVisibileForInputType(inputFile, INPUT_FILE, groupModel);
    input.add(inputFile);

    FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT);
    inputFile.add(fileInput);

    initButtons(buttonBar, groupModel);
  }
Пример #4
0
  private RadioGroup<Book> newRadioGroup(List<Book> candidateChoices) {
    RadioGroup<Book> radioGroupComponent = new RadioGroup<Book>("radioGroup");
    ListView<Book> listView =
        new ListView<Book>("loop", candidateChoices) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<Book> item) {
            item.add(new Radio<Book>("radio", new Model<Book>(item.getModelObject())));
          }
        };
    radioGroupComponent.add(listView);
    return radioGroupComponent;
  }
Пример #5
0
  public VistaHorasPage() {

    final Subject subject = SecurityUtils.getSubject();
    this.usuario = this.daoService.getUsuario(subject.getPrincipal().toString());

    this.labelDesdeModel =
        new LoadableDetachableModel<String>() {

          @Override
          protected String load() {
            return desde.toString();
          }
        };

    this.fechasModel =
        new LoadableDetachableModel<List<String>>() {

          @Override
          protected List<String> load() {

            List<String> fechas = new ArrayList<String>();

            for (int j = 2005; j < 2014; j++) {
              for (int i = 1; i < 13; i++) {
                fechas.add(i + "/" + j);
              }
            }

            return fechas;
          }
        };

    this.lstUsuariosModel =
        new LoadableDetachableModel<List<UsuarioListaHoras>>() {
          @Override
          protected List<UsuarioListaHoras> load() {
            return daoService.obtenerHorasUsuarios(desde, hasta, VistaHorasPage.this.sectorGlobal);
          }
        };

    this.lstUsuariosEnRojoModel =
        new LoadableDetachableModel<List<UsuarioListaHoras>>() {

          @Override
          protected List<UsuarioListaHoras> load() {
            //				List<UsuarioListaHoras> devolver = daoService.obtenerHorasUsuarios(desde,
            // hasta,VistaHorasPage.this.sectorGlobal);
            List<UsuarioListaHoras> devolver = VistaHorasPage.this.lstUsuariosModel.getObject();
            List<UsuarioListaHoras> itemsToRemove = new ArrayList<UsuarioListaHoras>();
            for (UsuarioListaHoras usuarioHoras : devolver) {
              if (!usuarioHoras.tieneDiaMenorDedicacion(VistaHorasPage.this.desde)) {
                itemsToRemove.add(usuarioHoras);
              }
            }
            devolver.removeAll(itemsToRemove);
            return devolver;
          }
        };

    VistaHorasForm form = new VistaHorasForm("form");
    form.setOutputMarkupId(true);
    add(form);

    List<Feriado> feriados = daoService.getFeriados();
    final List<Date> fechaFeriados = new ArrayList<Date>();
    for (Feriado feriado : feriados) {
      fechaFeriados.add(feriado.getFecha());
    }
    this.listViewContainer = new WebMarkupContainer("listViewContainer");
    this.listViewContainer.setOutputMarkupId(true);
    totales = new double[31];
    //		for (int i = 0; i < 32; i++) {
    //			totales[i]= new Double(0);
    //		}
    final PageableListView<UsuarioListaHoras> usuariosHorasListView =
        new PageableListView<UsuarioListaHoras>("tabla", this.lstUsuariosModel, 1000) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<UsuarioListaHoras> item) {
            final UsuarioListaHoras usuarioHoras = item.getModel().getObject();
            //
            //	           	if((item.getIndex() % 2) == 0){
            //	           		item.add(new AttributeModifier("class","odd"));
            //	           	}
            String nombreCorregido =
                daoService
                    .getNombreApellido(usuarioHoras.getUsuario())
                    .replaceAll("ó", "ó")
                    .replaceAll("é", "é")
                    .replaceAll("ñ", "ñ")
                    .replaceAll("á", "á")
                    .replaceAll("í", "í");

            Label nombre = new Label("apellidoNombre", nombreCorregido);
            item.add(nombre);
            Map<Date, Double> colHoras = new HashMap<Date, Double>();
            colHoras.putAll(usuarioHoras.getDiaHoras());

            LocalDate diaActual = new LocalDate(VistaHorasPage.this.desde);
            Double totalHoras = new Double(0);
            for (int j = 1; j <= 31; j++) {
              Label lbHoras;
              Double horasDia = new Double(0);

              horasDia = colHoras.get(diaActual.toDate());
              if (horasDia != null) {
                totales[j - 1] = totales[j - 1] + horasDia;
                String mensaje = decimal.format(horasDia);
                totalHoras = totalHoras + horasDia;
                lbHoras = new Label("contenidoDia" + j, Model.of(mensaje));
                lbHoras.add(new AttributeModifier("style", Model.of("display: block; ")));
                if (fechaFeriados.contains(diaActual.toDate())
                    || diaActual.getDayOfWeek() == DateTimeConstants.SATURDAY
                    || diaActual.getDayOfWeek() == DateTimeConstants.SUNDAY) {
                  lbHoras.add(
                      new AttributeAppender(
                          "style", Model.of("background-color: rgb(223, 223, 223); height:100%;")));
                  // background-clip: border-box; background-color: blue; color: white; border: 5px
                  // solid blue; border-radius: 5px;
                }
                if (horasDia < usuarioHoras.getDedicacion()) {
                  lbHoras.add(new AttributeAppender("style", Model.of("color:red;")));
                }
              } else if (fechaFeriados.contains(diaActual.toDate())
                  || diaActual.getDayOfWeek() == DateTimeConstants.SATURDAY
                  || diaActual.getDayOfWeek() == DateTimeConstants.SUNDAY) {
                lbHoras = new Label("contenidoDia" + j, "0");
                lbHoras.add(
                    new AttributeModifier(
                        "style", Model.of("background-color:rgb(223, 223, 223); height:100%;")));
              } else {
                lbHoras = new Label("contenidoDia" + j, "0");
              }

              item.add(lbHoras);
              diaActual = diaActual.plusDays(1);
            }
            //            	System.out.println(totalHoras);
            // Model.of(totalHoras)
            item.add(new Label("totalPersona", Model.of(totalHoras)));
          };
        };
    // html dinamico
    this.titulos =
        new WebComponent("tituloHtml") {
          @Override
          public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
            Response response = getRequestCycle().getResponse();
            String respuesta = "";
            respuesta += "<th class='tablaTitulo' scope='col'>Usuarios</th>";
            LocalDate diaActual = new LocalDate(VistaHorasPage.this.desde);
            for (int i = 1; i < 32; i++) {

              respuesta +=
                  "<th class='tablaTitulo' scope='col' >" + diaActual.getDayOfMonth() + "</th>";
              diaActual = diaActual.plusDays(1);
            }
            respuesta += "<th class='tablaTitulo' scope='col' > Total </th>";
            response.write(respuesta);
          }
        };

    this.totalesHtml =
        new WebComponent("totalesHtml") {
          public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
            Response response = getRequestCycle().getResponse();
            String respuesta = "";
            respuesta += "<td class='tablaTitulo' scope='col'>Totales:</td>";
            LocalDate diaActual = new LocalDate(VistaHorasPage.this.desde);
            for (int i = 1; i < 32; i++) {

              respuesta +=
                  "<td class='tablaTitulo' scope='col' >"
                      + decimal.format(VistaHorasPage.this.totales[i - 1])
                      + "</td>";
              diaActual = diaActual.plusDays(1);
            }
            respuesta += "<td class='tablaTitulo' scope='col' >  </td>";
            response.write(respuesta);
            for (int i = 0; i < 31; i++) {
              totales[i] = new Double(0);
            }
          };
        };

    this.listViewContainer.add(titulos);
    this.listViewContainer.add(totalesHtml);
    this.listViewContainer.add(usuariosHorasListView);
    //		this.listViewContainer.add(new AjaxPagingNavigator("navigator", usuariosHorasListView));
    add(listViewContainer);

    radioContainer = new WebMarkupContainer("radioContainerUsuarios");
    radioContainer.setOutputMarkupId(true);

    RadioGroup<String> radiog = new RadioGroup<String>("radioGroup", new Model<String>());

    Radio<String> mostrarTodas = new Radio<String>("mostrarTodas", Model.of("Todos"));
    Radio<String> mostrarEnRojo =
        new Radio<String>("mostrarEnRojo", Model.of("Menor que dedicación"));

    mostrarTodas.add(
        new AjaxEventBehavior("onchange") {

          protected void onEvent(AjaxRequestTarget target) {
            VistaHorasPage.this.lstUsuariosModel.detach();
            VistaHorasPage.this.lstUsuariosEnRojoModel.detach();
            usuariosHorasListView.setModel(VistaHorasPage.this.lstUsuariosModel);
            target.add(VistaHorasPage.this.listViewContainer);
          }
        });

    mostrarEnRojo.add(
        new AjaxEventBehavior("onchange") {

          protected void onEvent(AjaxRequestTarget target) {
            VistaHorasPage.this.lstUsuariosModel.detach();
            VistaHorasPage.this.lstUsuariosEnRojoModel.detach();
            usuariosHorasListView.setModel(VistaHorasPage.this.lstUsuariosEnRojoModel);
            target.add(VistaHorasPage.this.listViewContainer);
          }
        });

    radiog.add(mostrarTodas);
    radiog.add(mostrarEnRojo);
    radioContainer.add(radiog);

    add(radioContainer);
  }
  public ProductUpdatePage(PageParameters params) {
    final Long productId = params.get(PARAM_PRODUCT_ID).toLongObject();

    ProductDto product = null;
    try {
      product = PriceComparatorApplication.getApi().getProduct(productId);
    } catch (PriceComparatorBusinesException e) {
      // TODO
      e.printStackTrace();
    }

    updateDto = new ProductUpdateDto();
    updateDto.setId(productId);
    updateDto.setName(product.getName());
    updateDto.setUnit(product.getUnit());
    updateDto.setCountOfUnit(product.getCountOfUnit());
    updateDto.setCountOfItemInOnePackage(product.getCountOfItemInOnePackage());

    add(new FeedbackPanel("feedback"));

    Form<Void> form =
        new Form<Void>("form") {
          @Override
          protected void onSubmit() {
            try {
              PriceComparatorApplication.getApi().updateProduct(updateDto);
              setResponsePage(ProductListPage.class);

            } catch (Exception e) {
              // TODO
              e.printStackTrace();
            }
          }
        };
    add(form);

    TextField<String> productName =
        new TextField<>(
            "productName", new PropertyModel<String>(updateDto, ProductUpdateDto.AT_NAME));
    productName.setRequired(true);
    form.add(productName);

    RadioGroup<Unit> group =
        new RadioGroup<>("group", new PropertyModel<Unit>(updateDto, ProductUpdateDto.AT_UNIT));
    form.add(group);

    Radio<Unit> kus = new Radio<>("kus", Model.of(Unit.KUS));
    Radio<Unit> vaha = new Radio<>("vaha", Model.of(Unit.KILOGRAM));
    Radio<Unit> objem = new Radio<>("objem", Model.of(Unit.LITER));
    Radio<Unit> dlzka = new Radio<>("dlzka", Model.of(Unit.METER));
    Radio<Unit> davka = new Radio<>("davka", Model.of(Unit.DAVKA));
    group.add(kus, vaha, objem, dlzka, davka);

    TextField<BigDecimal> countOfUnit =
        new TextField<>(
            "countOfUnit",
            new PropertyModel<BigDecimal>(updateDto, ProductUpdateDto.AT_COUNT_OF_UNIT));
    countOfUnit.setRequired(true);
    form.add(countOfUnit);

    TextField<Integer> countOfItemInOnePackage =
        new TextField<>(
            "countOfItemInOnePackage",
            new PropertyModel<Integer>(
                updateDto, ProductUpdateDto.AT_COUNT_OF_ITEM_IN_ONE_PACKAGE));
    countOfItemInOnePackage.setRequired(true);
    form.add(countOfItemInOnePackage);
  }
Пример #7
0
  /**
   * @param id
   * @param model the model over the appropriate list of {@link Grid}
   * @see WMSInfo#getAuthorityURLs()
   * @see LayerInfo#getAuthorityURLs()
   * @see LayerGroupInfo#getAuthorityURLs()
   */
  public TileMatrixSetEditor(final String id, final IModel<GridSetInfo> info) {
    super(id, new PropertyModel<List<Grid>>(info, "levels"));
    add(new TileMatrixSetValidator());

    final IModel<List<Grid>> list = getModel();
    checkNotNull(list.getObject());

    this.info = info;
    this.readOnly = info.getObject().isInternal();

    // container for ajax updates
    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);

    final IModel<Boolean> preserveesolutionsModel =
        new PropertyModel<Boolean>(info, "resolutionsPreserved");

    final RadioGroup<Boolean> resolutionsOrScales =
        new RadioGroup<Boolean>("useResolutionsOrScalesGroup", preserveesolutionsModel);
    container.add(resolutionsOrScales);

    Radio<Boolean> preserveResolutions =
        new Radio<Boolean>("preserveResolutions", new Model<Boolean>(Boolean.TRUE));
    Radio<Boolean> preserveScales =
        new Radio<Boolean>("preserveScales", new Model<Boolean>(Boolean.FALSE));

    resolutionsOrScales.add(preserveResolutions);
    resolutionsOrScales.add(preserveScales);

    // update the table when this option changes so either the resolutions or scales column is
    // enabled
    resolutionsOrScales.add(
        new AjaxFormChoiceComponentUpdatingBehavior() {
          private static final long serialVersionUID = 1L;

          @Override
          protected void onUpdate(AjaxRequestTarget target) {
            resolutionsOrScales.processInput();
            final boolean useResolutions = resolutionsOrScales.getModelObject().booleanValue();

            Iterator<Component> iterator = grids.iterator();
            while (iterator.hasNext()) {
              @SuppressWarnings("unchecked")
              ListItem<Grid> next = (ListItem<Grid>) iterator.next();
              next.get("resolution").setEnabled(useResolutions);
              next.get("scale").setEnabled(!useResolutions);
            }
            target.add(table);
          }
        });

    // the link list
    table = new WebMarkupContainer("table");
    table.setOutputMarkupId(true);

    table.add(thLabel("level"));
    table.add(thLabel("resolution"));
    table.add(thLabel("scale"));
    table.add(thLabel("name"));
    table.add(thLabel("tiles"));

    container.add(table);

    grids =
        new ListView<Grid>("gridLevels", new ArrayList<Grid>(list.getObject())) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void onBeforeRender() {
            super.onBeforeRender();
          }

          @Override
          protected void populateItem(final ListItem<Grid> item) {
            // odd/even style
            final int index = item.getIndex();
            item.add(AttributeModifier.replace("class", index % 2 == 0 ? "even" : "odd"));

            item.add(new Label("zoomLevel", String.valueOf(index)));

            final TextField<Double> resolution;
            final TextField<Double> scale;
            final TextField<String> name;
            final Label tiles;
            final Component removeLink;

            resolution =
                new DecimalTextField(
                    "resolution", new PropertyModel<Double>(item.getModel(), "resolution"));
            resolution.setOutputMarkupId(true);
            item.add(resolution);

            scale =
                new DecimalTextField(
                    "scale", new PropertyModel<Double>(item.getModel(), "scaleDenom"));
            scale.setOutputMarkupId(true);
            item.add(scale);

            name =
                new TextField<String>("name", new PropertyModel<String>(item.getModel(), "name"));
            item.add(name);

            IModel<String> tilesModel =
                new IModel<String>() {
                  private static final long serialVersionUID = 1L;

                  @Override
                  public String getObject() {
                    // resolution.processInput();
                    Double res = resolution.getModelObject();
                    GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject();
                    final ReferencedEnvelope extent = gridSetInfo.getBounds();
                    if (res == null || extent == null) {
                      return "--";
                    }
                    final int tileWidth = gridSetInfo.getTileWidth();
                    final int tileHeight = gridSetInfo.getTileHeight();
                    final double mapUnitWidth = tileWidth * res.doubleValue();
                    final double mapUnitHeight = tileHeight * res.doubleValue();

                    final long tilesWide =
                        (long) Math.ceil((extent.getWidth() - mapUnitWidth * 0.01) / mapUnitWidth);
                    final long tilesHigh =
                        (long)
                            Math.ceil((extent.getHeight() - mapUnitHeight * 0.01) / mapUnitHeight);

                    NumberFormat nf = NumberFormat.getIntegerInstance(); // so it shows grouping
                    // for large numbers
                    String tilesStr = nf.format(tilesWide) + " x " + nf.format(tilesHigh);

                    return tilesStr;
                  }

                  @Override
                  public void detach() {
                    //
                  }

                  @Override
                  public void setObject(String object) {
                    //
                  }
                };

            tiles = new Label("tiles", tilesModel);
            tiles.setOutputMarkupId(true);
            item.add(tiles);

            // remove link
            if (TileMatrixSetEditor.this.readOnly) {
              removeLink = new Label("removeLink", "");
            } else {
              removeLink =
                  new ImageAjaxLink<Void>("removeLink", GWCIconFactory.DELETE_ICON) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onClick(AjaxRequestTarget target) {
                      List<Grid> list = new ArrayList<Grid>(grids.getModelObject());
                      int index = ((Integer) getDefaultModelObject()).intValue();
                      list.remove(index);
                      grids.setModelObject(list);
                      target.add(container);
                    }
                  };
              removeLink.setDefaultModel(new Model<Integer>(Integer.valueOf(index)));
              removeLink.add(
                  new AttributeModifier(
                      "title", new ResourceModel("TileMatrixSetEditor.removeLink")));
            }
            item.add(removeLink);

            final boolean isResolutionsPreserved = preserveesolutionsModel.getObject();
            resolution.setEnabled(isResolutionsPreserved);
            scale.setEnabled(!isResolutionsPreserved);

            resolution.add(
                new AjaxFormComponentUpdatingBehavior("blur") {
                  private static final long serialVersionUID = 1L;

                  @Override
                  protected void onUpdate(AjaxRequestTarget target) {
                    resolution.processInput();
                    Double res = resolution.getModelObject();
                    Double scaleDenominator = null;
                    if (null != res) {
                      GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject();
                      Double metersPerUnit = gridSetInfo.getMetersPerUnit();
                      if (metersPerUnit != null) {
                        scaleDenominator =
                            res.doubleValue()
                                * metersPerUnit.doubleValue()
                                / GridSetFactory.DEFAULT_PIXEL_SIZE_METER;
                      }
                    }
                    scale.setModelObject(scaleDenominator);
                    target.add(resolution);
                    target.add(scale);
                    target.add(tiles);
                  }
                });

            scale.add(
                new AjaxFormComponentUpdatingBehavior("blur") {
                  private static final long serialVersionUID = 1L;

                  @Override
                  protected void onUpdate(AjaxRequestTarget target) {
                    scale.processInput();
                    final Double scaleDenominator = scale.getModelObject();
                    Double res = null;
                    if (null != scaleDenominator) {
                      GridSetInfo gridSetInfo = TileMatrixSetEditor.this.info.getObject();
                      final double pixelSize = gridSetInfo.getPixelSize();
                      Double metersPerUnit = gridSetInfo.getMetersPerUnit();
                      if (metersPerUnit != null) {
                        res = pixelSize * scaleDenominator / metersPerUnit;
                      }
                    }
                    resolution.setModelObject(res);
                    target.add(resolution);
                    target.add(scale);
                    target.add(tiles);
                  }
                });
          }
        };
    grids.setOutputMarkupId(true);
    // this is necessary to avoid loosing item contents on edit/validation checks
    grids.setReuseItems(true);
    table.add(grids);
  }
Пример #8
0
  public HNF1BMiscPanel(final String id, final Demographics demographics) {
    super(id);

    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);

    HNF1BMisc hnf1BMisc = null;

    if (demographics.hasValidId()) {
      hnf1BMisc = hnf1BMiscManager.get(demographics.getId());
    }

    if (hnf1BMisc == null) {
      hnf1BMisc = new HNF1BMisc();
      hnf1BMisc.setRadarNo(demographics.getId());
    }

    // main model for this tab
    IModel<HNF1BMisc> model = new Model<HNF1BMisc>(hnf1BMisc);

    // components to update on ajax refresh
    final List<Component> componentsToUpdateList = new ArrayList<Component>();

    // general feedback for messages that are not to do with a certain component in the form
    final FeedbackPanel formFeedback = new FeedbackPanel("formFeedbackPanel");
    formFeedback.setOutputMarkupId(true);
    formFeedback.setOutputMarkupPlaceholderTag(true);
    componentsToUpdateList.add(formFeedback);

    Form<HNF1BMisc> form =
        new Form<HNF1BMisc>("form", new CompoundPropertyModel<HNF1BMisc>(model)) {
          @Override
          protected void onSubmit() {
            HNF1BMisc hnf1BMisc = getModelObject();

            // check all the radio buttons have values
            if (hnf1BMisc.getRenalCysts() == null
                || hnf1BMisc.getSingleKidney() == null
                || hnf1BMisc.getOtherRenalMalformations() == null
                || hnf1BMisc.getDiabetes() == null
                || hnf1BMisc.getGout() == null
                || hnf1BMisc.getGenitalMalformation() == null) {
              error("Please select a value for each radio button");

            } else {
              // if all the radios are complete check that we have any additional required data
              if (hnf1BMisc.getOtherRenalMalformations().equals(YesNo.YES)
                  && !StringUtils.hasText(hnf1BMisc.getOtherRenalMalformationsDetails())) {
                error("Please provide other renal malformation details");
              }

              if (hnf1BMisc.getGenitalMalformation().equals(YesNo.YES)
                  && !StringUtils.hasText(hnf1BMisc.getGenitalMalformationDetails())) {
                error("Please provide genital malformation details");
              }
            }

            if (!hasError()) {
              hnf1BMisc.setRadarNo(demographics.getId());
              hnf1BMiscManager.save(hnf1BMisc);
            }
          }
        };

    add(form);

    int maxAge = 90;
    int minAge = 1;

    // the list has to be strings so we can have the first one as N/A
    List<String> ages = new ArrayList<String>();
    ages.add("N/A");

    for (int x = minAge; x <= maxAge; x++) {
      ages.add(Integer.toString(x));
    }

    // have to set the generic feedback panel to only pick up msgs for them form
    ComponentFeedbackMessageFilter filter = new ComponentFeedbackMessageFilter(form);
    formFeedback.setFilter(filter);
    form.add(formFeedback);

    // add the patient detail bar to the tab
    PatientDetailPanel patientDetail =
        new PatientDetailPanel("patientDetail", demographics, "HNF1B Misc");
    patientDetail.setOutputMarkupId(true);
    form.add(patientDetail);
    componentsToUpdateList.add(patientDetail);

    RadioGroup<YesNo> renalCystsRadioGroup = new RadioGroup<YesNo>("renalCysts");
    form.add(renalCystsRadioGroup);
    renalCystsRadioGroup.add(new Radio<YesNo>("renalCystsNo", new Model<YesNo>(YesNo.NO)));
    renalCystsRadioGroup.add(new Radio<YesNo>("renalCystsYes", new Model<YesNo>(YesNo.YES)));

    RadioGroup<YesNo> singleKidneyRadioGroup = new RadioGroup<YesNo>("singleKidney");
    form.add(singleKidneyRadioGroup);
    singleKidneyRadioGroup.add(new Radio<YesNo>("singleKidneyNo", new Model<YesNo>(YesNo.NO)));
    singleKidneyRadioGroup.add(new Radio<YesNo>("singleKidneyYes", new Model<YesNo>(YesNo.YES)));

    RadioGroup<YesNo> otherRenalMalformationsRadioGroup =
        new RadioGroup<YesNo>("otherRenalMalformations");
    form.add(otherRenalMalformationsRadioGroup);
    otherRenalMalformationsRadioGroup.add(
        new Radio<YesNo>("otherRenalMalformationsNo", new Model<YesNo>(YesNo.NO)));
    otherRenalMalformationsRadioGroup.add(
        new Radio<YesNo>("otherRenalMalformationsYes", new Model<YesNo>(YesNo.YES)));

    TextArea otherClinicianAndContactInfo = new TextArea("otherRenalMalformationsDetails");
    form.add(otherClinicianAndContactInfo);

    RadioGroup<YesNo> diabetesRadioGroup = new RadioGroup<YesNo>("diabetes");
    form.add(diabetesRadioGroup);
    diabetesRadioGroup.add(new Radio<YesNo>("diabetesNo", new Model<YesNo>(YesNo.NO)));
    diabetesRadioGroup.add(new Radio<YesNo>("diabetesYes", new Model<YesNo>(YesNo.YES)));

    DropDownChoice<String> ageAtDiabetesDiagnosisDropDown =
        new DropDownChoice<String>(
            "ageAtDiabetesDiagnosis",
            new PropertyModel<String>(model, "ageAtDiabetesDiagnosisAsString"),
            ages);
    form.add(ageAtDiabetesDiagnosisDropDown);

    RadioGroup<YesNo> goutRadioGroup = new RadioGroup<YesNo>("gout");
    form.add(goutRadioGroup);
    goutRadioGroup.add(new Radio<YesNo>("goutNo", new Model<YesNo>(YesNo.NO)));
    goutRadioGroup.add(new Radio<YesNo>("goutYes", new Model<YesNo>(YesNo.YES)));

    DropDownChoice<String> ageAtGoutDiagnosisDropDown =
        new DropDownChoice<String>(
            "ageAtGoutDiagnosis",
            new PropertyModel<String>(model, "ageAtGoutDiagnosisAsString"),
            ages);
    form.add(ageAtGoutDiagnosisDropDown);

    RadioGroup<YesNo> genitalMalformationRadioGroup = new RadioGroup<YesNo>("genitalMalformation");
    form.add(genitalMalformationRadioGroup);
    genitalMalformationRadioGroup.add(
        new Radio<YesNo>("genitalMalformationNo", new Model<YesNo>(YesNo.NO)));
    genitalMalformationRadioGroup.add(
        new Radio<YesNo>("genitalMalformationYes", new Model<YesNo>(YesNo.YES)));

    TextArea genitalMalformationDetails = new TextArea("genitalMalformationDetails");
    form.add(genitalMalformationDetails);

    final Label successMessageTop =
        RadarComponentFactory.getSuccessMessageLabel(
            "successMessageTop", form, componentsToUpdateList);
    Label errorMessageTop =
        RadarComponentFactory.getErrorMessageLabel("errorMessageTop", form, componentsToUpdateList);

    final Label successMessageBottom =
        RadarComponentFactory.getSuccessMessageLabel(
            "successMessageBottom", form, componentsToUpdateList);
    Label errorMessageBottom =
        RadarComponentFactory.getErrorMessageLabel(
            "errorMessageBottom", form, componentsToUpdateList);

    form.add(
        new AjaxSubmitLink("saveTop") {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
            target.add(formFeedback);
          }

          @Override
          protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.add(formFeedback);
          }
        });

    form.add(
        new AjaxSubmitLink("saveBottom") {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.appendJavaScript(RadarApplication.FORM_IS_DIRTY_FALSE_SCRIPT);
            target.add(formFeedback);
          }

          @Override
          protected void onError(AjaxRequestTarget target, Form<?> form) {
            ComponentHelper.updateComponentsIfParentIsVisible(target, componentsToUpdateList);
            target.add(formFeedback);
          }
        });
  }