Example usage for org.apache.wicket.util.string StringValue toLong

List of usage examples for org.apache.wicket.util.string StringValue toLong

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValue toLong.

Prototype

public final long toLong() throws StringValueConversionException 

Source Link

Document

Convert this text to a long.

Usage

From source file:com.cubeia.backoffice.web.operator.EditOperator.java

License:Open Source License

private Long getOperatorId(PageParameters params) {
    StringValue id = params.get("id");
    return id.toLong();
}

From source file:com.romeikat.datamessie.core.base.ui.page.AbstractAuthenticatedPage.java

License:Open Source License

private void initialize() {
    // Active project
    final IModel<ProjectDto> activeProjectModel = new LoadableDetachableModel<ProjectDto>() {

        private static final long serialVersionUID = 1L;

        @Override//from   ww w.ja v  a2  s . c  o  m
        protected ProjectDto load() {
            // Determine requested project id
            final StringValue projectParameter = getRequest().getRequestParameters()
                    .getParameterValue("project");
            // Load respective project
            ProjectDto activeProject;
            if (projectParameter.isNull()) {
                activeProject = getDefaultProject();
            } else {
                final Long userId = DataMessieSession.get().getUserId();
                activeProject = projectDao.getAsDto(sessionFactory.getCurrentSession(),
                        projectParameter.toLong(), userId);
                if (activeProject == null) {
                    activeProject = getDefaultProject();
                }
            }
            // Ensure project parameter
            if (activeProject != null) {
                getPageParameters().set("project", activeProject.getId());
                DataMessieSession.get().getDocumentsFilterSettings().setProjectId(activeProject.getId());
            }
            // Done
            return activeProject;
        }
    };

    aciveProjectDropDownChoice = new ProjectSelector("activeProjectSelector", activeProjectModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSelectionChanged(final ProjectDto newSelection) {
            if (newSelection == null) {
                return;
            }

            final PageParameters projectPageParameters = new PageParameters();
            final Long selectedProjectId = newSelection.getId();
            projectPageParameters.set("project", selectedProjectId);
            final Class<? extends Page> responsePage = AbstractAuthenticatedPage.this.getNavigationLinkClass();
            final PageParameters pageParameters = getDefaultPageParameters(projectPageParameters);
            AbstractAuthenticatedPage.this.setResponsePage(responsePage, pageParameters);
        }

        @Override
        protected boolean wantOnSelectionChangedNotifications() {
            return true;
        }
    };
    add(aciveProjectDropDownChoice);

    // Navigation links
    final List<NavigationLink<? extends Page>> navigationLinks = getDataMessieApplication()
            .getNavigationLinks();
    final ListView<NavigationLink<? extends Page>> navigationLinksListView = new ListView<NavigationLink<? extends Page>>(
            "navigationLinks", navigationLinks) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<NavigationLink<? extends Page>> item) {
            // Link
            final NavigationLink<? extends Page> navigationLink = item.getModelObject();
            final PageParameters projectPageParameters = createProjectPageParameters();
            final BookmarkablePageLink<? extends Page> bookmarkablePageLink = createBookmarkablePageLink(
                    "navigationLink", navigationLink, projectPageParameters);
            final Label bookmarkablePageLinkLabel = new Label("navigationLinkLabel", navigationLink.getLabel());
            // Active link
            if (AbstractAuthenticatedPage.this.getNavigationLinkClass() == navigationLink.getPageClass()) {
                markLinkSelected(bookmarkablePageLink);
            }
            // Done
            bookmarkablePageLink.add(bookmarkablePageLinkLabel);
            item.add(bookmarkablePageLink);
        }
    };
    add(navigationLinksListView);

    // Sign out link
    signOutLink = new Link<SignInPage>("signOutLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            AuthenticatedWebSession.get().invalidate();
            setResponsePage(getApplication().getHomePage());
        }
    };
    add(signOutLink);

    // Side panels
    final List<SidePanel> sidePanels = getDataMessieApplication().getSidePanels();
    final ListView<SidePanel> sidePanelsListView = new ListView<SidePanel>("sidePanels", sidePanels) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<SidePanel> item) {
            // Link
            final SidePanel sidePanel = item.getModelObject();
            final Panel panel = sidePanel.getPanel();
            item.add(panel);
        }
    };
    add(sidePanelsListView);

    // Task executions container
    final WebMarkupContainer taskExecutionsContainer = new WebMarkupContainer("taskExecutionsContainer");
    taskExecutionsContainer.setOutputMarkupId(true);
    taskExecutionsContainer.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(selfUpdatingInterval)));
    add(taskExecutionsContainer);
    // Task executions
    taskExecutionsPanel = new AjaxLazyLoadPanel("taskExecutionsPanel") {
        private static final long serialVersionUID = 1L;

        @Override
        public Component getLazyLoadComponent(final String id) {
            final TaskExecutionsPanel taskExecutionsPanel = new TaskExecutionsPanel(id);
            return taskExecutionsPanel;
        }

    };
    taskExecutionsContainer.add(taskExecutionsPanel);
}

From source file:com.romeikat.datamessie.core.base.ui.page.AbstractDocumentsFilterPage.java

License:Open Source License

private void applyRequestParametersToDocumentsFilterSettings() {
    final DocumentsFilterSettings dfs = DataMessieSession.get().getDocumentsFilterSettings();
    final IRequestParameters requestParameters = getRequest().getRequestParameters();
    // Project//from  ww  w .j  ava 2s.c o  m
    final Long projectId = getActiveProjectId();
    dfs.setProjectId(projectId);
    // Source
    final StringValue sourceParameter = getParameterValue(requestParameters, "source");
    final Long sourceId = sourceParameter == null ? null : sourceParameter.toLong();
    dfs.setSourceId(sourceId);
    // Source visible (fixed)
    final Boolean sourceVisible = true;
    dfs.setSourceVisible(sourceVisible);
    // Source type
    final StringValue sourceTypesParameter = getParameterValue(requestParameters, "sourcetypes");
    final Collection<Long> sourceTypeIds = sourceTypesParameter == null ? null
            : parseSourceTypeIds(sourceTypesParameter);
    dfs.setSourceTypeIds(sourceTypeIds);
    // Crawling
    final StringValue crawlingParameter = getParameterValue(requestParameters, "crawling");
    final Long crawlingId = crawlingParameter == null ? null : crawlingParameter.toLong();
    dfs.setCrawlingId(crawlingId);
    // From date
    final StringValue fromDateParameter = getParameterValue(requestParameters, "from");
    final LocalDate fromDate = parseLocalDate(fromDateParameter);
    dfs.setFromDate(fromDate);
    // To date
    final StringValue toDateParameter = getParameterValue(requestParameters, "to");
    final LocalDate toDate = parseLocalDate(toDateParameter);
    dfs.setToDate(toDate);
    // Cleaned content is not processed as it is not included in the URL
    // Document IDs are not processed as they are not included in the URL
    // States
    final StringValue statesParameter = getParameterValue(requestParameters, "states");
    final Collection<DocumentProcessingState> states = statesParameter == null ? null
            : parseStates(statesParameter);
    dfs.setStates(states);
}

From source file:com.romeikat.datamessie.core.view.ui.page.DocumentPage.java

License:Open Source License

private void initialize() {
    // Document// w w w.  j a v  a  2s. com
    documentModel = new LoadableDetachableModel<DocumentDto>() {
        private static final long serialVersionUID = 1L;

        @Override
        public DocumentDto load() {
            final StringValue idParameter = getRequest().getRequestParameters().getParameterValue("id");
            return idParameter.isNull() ? null
                    : documentDao.getAsDto(sessionFactory.getCurrentSession(), idParameter.toLong());
        }
    };
    final DocumentDto document = documentModel.getObject();

    // Table
    final WebMarkupContainer documentWmc = new WebMarkupContainer("document") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(documentModel.getObject() != null);
        }
    };
    add(documentWmc);

    // ID
    final Label idLabel = new Label("idLabel", new PropertyModel<Long>(documentModel, "id"));
    documentWmc.add(idLabel);
    // Title
    final Label titleLabel = new Label("titleLabel", new PropertyModel<String>(documentModel, "title"));
    documentWmc.add(titleLabel);
    // Stemmed title
    final Label stemmedTitleLabel = new Label("stemmedTitleLabel",
            new PropertyModel<String>(documentModel, "stemmedTitle"));
    documentWmc.add(stemmedTitleLabel);
    // URLs
    urlLink = new ExternalLink("urlLink", new PropertyModel<String>(documentModel, "url"),
            new PropertyModel<String>(documentModel, "url"));
    urlLink.setContextRelative(false);
    documentWmc.add(urlLink);
    // Description
    final Label descriptionLabel = new Label("descriptionLabel",
            new PropertyModel<String>(documentModel, "description"));
    documentWmc.add(descriptionLabel);
    // Stemmed description
    final Label stemmedDescriptionLabel = new Label("stemmedDescriptionLabel",
            new PropertyModel<String>(documentModel, "stemmedDescription"));
    documentWmc.add(stemmedDescriptionLabel);
    // Published
    final Label publishedLabel = new Label("publishedLabel",
            new PropertyModel<LocalDateTime>(documentModel, "published"));
    documentWmc.add(publishedLabel);
    // Downloaded
    final Label downloadedLabel = new Label("downloadedLabel",
            new PropertyModel<LocalDateTime>(documentModel, "downloaded"));
    documentWmc.add(downloadedLabel);
    // Link to source
    final PageParameters sourcePageParameters = createProjectPageParameters();
    sourcePageParameters.set("id", document.getSourceId());
    final Label sourceNameLabel = new Label("sourceNameLabel",
            new PropertyModel<String>(documentModel, "sourceName"));
    final Link<SourcePage> sourceLink = new BookmarkablePageLink<SourcePage>("sourceLink", SourcePage.class,
            sourcePageParameters);
    sourceLink.add(sourceNameLabel);
    documentWmc.add(sourceLink);
    // Status code
    final Label statusCodeLabel = new Label("statusCodeLabel",
            new PropertyModel<Integer>(documentModel, "statusCode"));
    documentWmc.add(statusCodeLabel);
    // State
    final Label stateLabel = new Label("stateLabel",
            new PropertyModel<DocumentProcessingState>(documentModel, "state"));
    documentWmc.add(stateLabel);
    // Raw content
    final TextArea<String> rawContentTextArea = new TextArea<String>("rawContentTextArea",
            new PropertyModel<String>(documentModel, "rawContent"));
    documentWmc.add(rawContentTextArea);
    // Cleaned content
    final TextArea<String> cleanedContentTextArea = new TextArea<String>("cleanedContentTextArea",
            new PropertyModel<String>(documentModel, "cleanedContent"));
    documentWmc.add(cleanedContentTextArea);
    // Stemmed content
    final TextArea<String> stemmedContentTextArea = new TextArea<String>("stemmedContentTextArea",
            new PropertyModel<String>(documentModel, "stemmedContent"));
    documentWmc.add(stemmedContentTextArea);
    // Named entities
    final TextArea<String> namedEntitiesTextArea = new TextArea<String>("namedEntitiesTextArea",
            new PropertyModel<String>(documentModel, "namedEntities"));
    documentWmc.add(namedEntitiesTextArea);
}

From source file:com.romeikat.datamessie.core.view.ui.page.SourcePage.java

License:Open Source License

private void initialize() {
    final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(sessionFactory);

    // Source//from  w w w . ja  v  a 2  s .  c  o  m
    final StringValue idParameter = getRequest().getRequestParameters().getParameterValue("id");
    final Long userId = DataMessieSession.get().getUserId();
    final SourceDto source = idParameter.isNull() ? null
            : sourceDao.getAsDto(sessionProvider.getStatelessSession(), userId, idParameter.toLong());
    // Model cannot be a LoadableDetachableModel as the contained DTO will be edited across
    // multiple Ajax requests (by RedirectingRulesPanel and TagSelectingRulesPanel)
    sourceModel = new Model<SourceDto>(source) {
        private static final long serialVersionUID = 1L;

        @Override
        public SourceDto getObject() {
            final SourceDto oldSource = super.getObject();
            // If a valid new source is requested, return that one
            final StringValue idParameter = getRequest().getRequestParameters().getParameterValue("id");
            if (!idParameter.isNull() && oldSource != null) {
                if (oldSource.getId() != idParameter.toLong()) {
                    final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(
                            sessionFactory);
                    final SourceDto newSource = sourceDao.getAsDto(sessionProvider.getStatelessSession(),
                            userId, idParameter.toLong());
                    sessionProvider.closeStatelessSession();
                    if (newSource != null) {
                        return newSource;
                    }
                }
            }
            // Return old source
            return oldSource;
        }
    };

    // Form
    final Form<SourceDto> sourceForm = new Form<SourceDto>("source",
            new CompoundPropertyModel<SourceDto>(sourceModel)) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            final HibernateSessionProvider sessionProvider = new HibernateSessionProvider(sessionFactory);
            new ExecuteWithTransaction(sessionProvider.getStatelessSession()) {
                @Override
                protected void execute(final StatelessSession statelessSession) {
                    sourceService.updateSource(statelessSession, getModelObject());
                }
            }.execute();
            sessionProvider.closeStatelessSession();
        }

        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(getModelObject() != null);
        }
    };
    add(sourceForm);

    // ID
    final Label idLabel = new Label("id");
    sourceForm.add(idLabel);
    // Name
    final TextField<String> nameTextField = new TextField<String>("name");
    sourceForm.add(nameTextField);
    // Language
    final Label languageLabel = new Label("language");
    sourceForm.add(languageLabel);
    // Types
    final SourceTypeChoice typesChoice = new SourceTypeChoice("types").setWidth(320);
    sourceForm.add(typesChoice);
    // URL
    final TextField<String> urlTextField = new TextField<String>("url");
    sourceForm.add(urlTextField);
    // Link to URL
    final ExternalLink urlLink = new ExternalLink("urlLink", new PropertyModel<String>(sourceModel, "url"));
    sourceForm.add(urlLink);
    // URL extracting rules
    final IModel<List<RedirectingRuleDto>> redirectingRulesModel = new PropertyModel<List<RedirectingRuleDto>>(
            sourceModel, "redirectingRules");
    final RedirectingRulesPanel redirectingRulesPanel = new RedirectingRulesPanel("redirectingRules",
            redirectingRulesModel);
    sourceForm.add(redirectingRulesPanel);
    // Tag selecting rules
    final IModel<List<TagSelectingRuleDto>> tagSelectingRulesModel = new PropertyModel<List<TagSelectingRuleDto>>(
            sourceModel, "tagSelectingRules");
    final TagSelectingRulesPanel tagSelectingRulesPanel = new TagSelectingRulesPanel("tagSelectingRules",
            tagSelectingRulesModel);
    sourceForm.add(tagSelectingRulesPanel);
    // Visible
    final CheckBox visibleCheckBox = new CheckBox("visible");
    sourceForm.add(visibleCheckBox);

    sessionProvider.closeStatelessSession();
}

From source file:eu.uqasar.web.pages.processes.ProcessAddEditPage.java

License:Apache License

/**
 * /*from w w  w. ja  va 2 s  .com*/
 * @param idParam
 */
private void loadProcess(final StringValue idParam) {
    // If no id is provided
    if (idParam.isEmpty()) {
        setPageTitle(new StringResourceModel("page.create.title", this, null));
        add(new Label("header", new StringResourceModel("form.create.header", this, null)));
        process = new Process();
    }
    // Attempt to load the process by the id
    else {
        process = processService.getById(idParam.toLong());
        if (process == null) {
            throw new EntityNotFoundException(Process.class, idParam.toOptionalString());
        }

        setPageTitle(new StringResourceModel("page.edit.title", this, null));
        add(new Label("header", new StringResourceModel("form.edit.header", this, null)));
    }
}

From source file:eu.uqasar.web.pages.products.ProductAddEditPage.java

License:Apache License

/**
 * /*from  www  . j  ava  2  s .c  o  m*/
 * @param idParam
 */
private void loadProduct(final StringValue idParam) {
    // If no ID is provided
    if (idParam.isEmpty()) {
        setPageTitle(new StringResourceModel("page.create.title", this, null));
        add(new Label("header", new StringResourceModel("form.create.header", this, null)));
        product = new Product();
    }
    // If a parameter is provided, attempt to load the product
    else {
        product = productService.getById(idParam.toLong());
        if (product == null) {
            throw new EntityNotFoundException(Product.class, idParam.toOptionalString());
        }

        setPageTitle(new StringResourceModel("page.edit.title", this, null));
        add(new Label("header", new StringResourceModel("form.edit.header", this, null)));
    }
}

From source file:org.devgateway.toolkit.forms.wicket.page.user.EditUserPage.java

License:Open Source License

@Override
protected void onInitialize() {
    Person person = SecurityUtil.getCurrentAuthenticatedPerson();

    if (!SecurityUtil.isCurrentUserAdmin()) {
        if (person.getId() != getPageParameters().get(WebConstants.PARAM_ID).toLong()) {
            setResponsePage(getApplication().getHomePage());
        }//  ww w .j av a 2  s  .  c  o m
    }

    super.onInitialize();

    userName.required();
    userName.getField().add(new UsernamePatternValidator());
    StringValue idPerson = getPageParameters().get(WebConstants.PARAM_ID);
    if (!idPerson.isNull()) {
        userName.getField().add(new UniqueUsernameValidator(idPerson.toLong()));
    } else {
        userName.getField().add(new UniqueUsernameValidator());
    }
    userName.setIsFloatedInput(true);
    editForm.add(userName);
    MetaDataRoleAuthorizationStrategy.authorize(userName, Component.ENABLE, SecurityConstants.Roles.ROLE_ADMIN);

    firstName.required();
    firstName.setIsFloatedInput(true);
    editForm.add(firstName);

    lastName.required();
    lastName.setIsFloatedInput(true);
    editForm.add(lastName);

    email.required();
    email.getField().add(EmailAddressValidator.getInstance());
    if (!idPerson.isNull()) {
        email.getField().add(new UniqueEmailAddressValidator(idPerson.toLong()));
    } else {
        email.getField().add(new UniqueEmailAddressValidator());
    }
    email.setIsFloatedInput(true);
    editForm.add(email);

    title.setIsFloatedInput(true);
    editForm.add(title);

    group.required();
    group.setIsFloatedInput(true);
    editForm.add(group);
    MetaDataRoleAuthorizationStrategy.authorize(group, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    editForm.add(defaultDashboard);
    MetaDataRoleAuthorizationStrategy.authorize(defaultDashboard, Component.ENABLE,
            SecurityConstants.Roles.ROLE_ADMIN);

    roles.required();
    roles.getField().setOutputMarkupId(true);
    roles.setIsFloatedInput(true);
    editForm.add(roles);
    MetaDataRoleAuthorizationStrategy.authorize(roles, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    // stop resetting the password fields each time they are rendered
    password.getField().setResetPassword(false);
    cpassword.getField().setResetPassword(false);
    if (SecurityUtil.isCurrentUserAdmin() && !SecurityUtil.isUserAdmin(compoundModel.getObject())
            && idPerson.isNull()) {
        // hide the change password checkbox and set it's model to true
        compoundModel.getObject().setChangePass(true);
        changePass.setVisibilityAllowed(false);
    } else {
        compoundModel.getObject().setChangePass(compoundModel.getObject().getChangePassword());
        password.getField().setEnabled(compoundModel.getObject().getChangePassword());
        cpassword.getField().setEnabled(compoundModel.getObject().getChangePassword());
    }

    changePass.setIsFloatedInput(true);
    editForm.add(changePass);

    password.getField().add(new PasswordPatternValidator());
    password.setOutputMarkupId(true);
    password.setIsFloatedInput(true);
    editForm.add(password);

    cpassword.setOutputMarkupId(true);
    cpassword.setIsFloatedInput(true);
    editForm.add(cpassword);

    editForm.add(new EqualPasswordInputValidator(password.getField(), cpassword.getField()));

    enabled.setIsFloatedInput(true);
    editForm.add(enabled);
    MetaDataRoleAuthorizationStrategy.authorize(enabled, Component.RENDER, SecurityConstants.Roles.ROLE_ADMIN);

    changePassword.setIsFloatedInput(true);
    editForm.add(changePassword);
    MetaDataRoleAuthorizationStrategy.authorize(changePassword, Component.RENDER,
            SecurityConstants.Roles.ROLE_ADMIN);

    MetaDataRoleAuthorizationStrategy.authorize(deleteButton, Component.RENDER,
            SecurityConstants.Roles.ROLE_ADMIN);
}

From source file:org.patientview.radar.web.pages.admin.AdminConsultantPage.java

License:Open Source License

public AdminConsultantPage(PageParameters parameters) {
    super();// ww w .j a v a2 s . c  o  m

    final Consultant consultant;

    // if id is empty or -1 then its a new consultant else try pull back record
    StringValue idValue = parameters.get(PARAM_ID);
    if (idValue.isEmpty() || idValue.toLong() == -1) {
        consultant = new Consultant();
        newConsultant = true;
    } else {
        consultant = utilityManager.getConsultant(idValue.toLongObject());
    }

    CompoundPropertyModel<Consultant> consultantModel = new CompoundPropertyModel<Consultant>(consultant);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    feedback.setOutputMarkupPlaceholderTag(true);
    add(feedback);

    final Form<Consultant> userForm = new Form<Consultant>("consultantForm", consultantModel) {
        protected void onSubmit() {
            try {
                utilityManager.saveConsultant(getModelObject());

                if (newConsultant) {
                    setResponsePage(AdminConsultantsPage.class);
                }
            } catch (Exception e) {
                error("Could not save consultant: " + e.toString());
            }
        }
    };
    add(userForm);

    userForm.add(new RequiredTextField("forename"));
    userForm.add(new RequiredTextField("surname"));

    // get centres and sort by name
    List<Centre> centres = utilityManager.getCentres();
    Collections.sort(centres, Centre.getComparator());

    DropDownChoice<Centre> centre = new DropDownChoice<Centre>("centre", centres,
            new ChoiceRenderer<Centre>("name", "id"));
    centre.setRequired(true);
    userForm.add(centre);

    AjaxLink delete = new AjaxLink("delete") {
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            try {
                utilityManager.deleteConsultant(consultant);
                setResponsePage(AdminConsultantsPage.class);
            } catch (Exception e) {
                error("Could not delete consultant " + e);
                ajaxRequestTarget.add(feedback);
            }

        }
    };
    delete.setVisible(!newConsultant);
    userForm.add(delete);

    userForm.add(new AjaxSubmitLink("saveTop") {
        protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            setResponsePage(AdminConsultantsPage.class);
        }

        protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            ajaxRequestTarget.add(feedback);
        }
    });

    userForm.add(new AjaxLink("cancelTop") {
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            setResponsePage(AdminConsultantsPage.class);
        }
    });

    userForm.add(new AjaxSubmitLink("saveBottom") {
        protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            setResponsePage(AdminConsultantsPage.class);
        }

        protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            ajaxRequestTarget.add(feedback);
        }
    });

    userForm.add(new AjaxLink("cancelBottom") {
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            setResponsePage(AdminConsultantsPage.class);
        }
    });
}

From source file:org.patientview.radar.web.pages.admin.AdminIssuePage.java

License:Open Source License

public AdminIssuePage(PageParameters parameters) {
    super();//from ww w  .  j  ava  2s .  c  o m

    final Issue issue;

    // if id is empty or -1 then its a new consultant else try pull back record
    StringValue idValue = parameters.get(PARAM_ID);
    if (idValue.isEmpty() || idValue.toLong() == -1) {
        issue = new Issue();
    } else {
        issue = issueManager.getIssue(idValue.toLongObject());
    }

    CompoundPropertyModel<Issue> issueModel = new CompoundPropertyModel<Issue>(issue);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    feedback.setOutputMarkupPlaceholderTag(true);
    add(feedback);

    final Form<Issue> issueForm = new Form<Issue>("issueForm", issueModel) {
        protected void onSubmit() {
            try {
                issueManager.saveIssue(getModelObject());
                setResponsePage(AdminIssuesPage.class);
            } catch (Exception e) {
                error("Could not save issue: " + e.toString());
            }
        }
    };
    add(issueForm);

    DropDownChoice<IssueType> type = new DropDownChoice<IssueType>("type", Arrays.asList(IssueType.values()));
    type.setRequired(true);
    issueForm.add(type);

    issueForm.add(new RequiredTextField("page"));

    DateTextField dateLogged = new DateTextField("dateLogged", RadarApplication.DATE_PATTERN);
    dateLogged.setRequired(true);
    dateLogged.add(new DatePicker());
    issueForm.add(dateLogged);

    DateTextField dateResolved = new DateTextField("dateResolved", RadarApplication.DATE_PATTERN);
    dateResolved.add(new DatePicker());
    issueForm.add(dateResolved);

    TextArea description = new TextArea("description");
    description.setRequired(true);
    issueForm.add(description);

    TextArea comments = new TextArea("comments");
    issueForm.add(comments);

    DropDownChoice<IssuePriority> priority = new DropDownChoice<IssuePriority>("priority",
            Arrays.asList(IssuePriority.values()));
    priority.setRequired(true);
    issueForm.add(priority);

    DropDownChoice<IssueStatus> status = new DropDownChoice<IssueStatus>("status",
            Arrays.asList(IssueStatus.values()));
    status.setRequired(true);
    issueForm.add(status);

    DateTextField updated = new DateTextField("updated", RadarApplication.DATE_PATTERN);
    updated.add(new DatePicker());
    issueForm.add(updated);

    issueForm.add(new AjaxSubmitLink("saveTop") {
        protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            setResponsePage(AdminIssuesPage.class);
        }

        protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            ajaxRequestTarget.add(feedback);
        }
    });

    issueForm.add(new AjaxLink("cancelTop") {
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            setResponsePage(AdminIssuesPage.class);
        }
    });

    issueForm.add(new AjaxSubmitLink("saveBottom") {
        protected void onSubmit(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            setResponsePage(AdminIssuesPage.class);
        }

        protected void onError(AjaxRequestTarget ajaxRequestTarget, Form<?> form) {
            ajaxRequestTarget.add(feedback);
        }
    });

    issueForm.add(new AjaxLink("cancelBottom") {
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            setResponsePage(AdminIssuesPage.class);
        }
    });
}