List of usage examples for org.apache.wicket PageReference getPage
public Page getPage()
From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java
License:Apache License
public static <T extends Component> T theSameForPage(T object, PageReference containingPageReference) { Page containingPage = containingPageReference.getPage(); if (containingPage == null) { return object; }/*from w ww.j ava 2 s . c o m*/ String path = object.getPageRelativePath(); T retval = (T) containingPage.get(path); if (retval == null) { return object; // throw new IllegalStateException("There is no component like " + // object + " (path '" + path + "') on " + containingPage); } return retval; }
From source file:guru.mmp.application.web.template.pages.AddCodeCategoryPage.java
License:Apache License
/** * Constructs a new <code>AddCodeCategoryPage</code>. * * @param previousPage the previous page *///from ww w . j av a 2 s .co m AddCodeCategoryPage(PageReference previousPage) { super("Add Code Category"); try { Form<CodeCategory> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new CodeCategory()))); addForm.getModelObject().setId(UUID.randomUUID()); addForm.add(new CodeCategoryInputPanel("codeCategory", false)); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { LocalDateTime created = LocalDateTime.now(); CodeCategory codeCategory = addForm.getModelObject(); codeCategory.setUpdated(created); if (codeCategory.getCategoryType() != CodeCategoryType.LOCAL_CUSTOM) { codeCategory.setCodeData(null); } if ((codeCategory.getCategoryType() != CodeCategoryType.REMOTE_HTTP_SERVICE) && (codeCategory.getCategoryType() != CodeCategoryType.REMOTE_WEB_SERVICE)) { codeCategory.setEndPoint(null); codeCategory.setIsEndPointSecure(false); codeCategory.setIsCacheable(false); codeCategory.setCacheExpiry(null); } if (!codeCategory.getIsCacheable()) { codeCategory.setCacheExpiry(null); } codesService.createCodeCategory(codeCategory); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the code category: " + e.getMessage(), e); AddCodeCategoryPage.this.error("Failed to add the code category"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddCodeCategoryPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddCodePage.java
License:Apache License
/** * Constructs a new <code>AddCodePage</code>. * * @param previousPage the previous page * @param codeCategoryId the ID uniquely identifying the code category for the code *//*from ww w . jav a 2s . com*/ AddCodePage(PageReference previousPage, UUID codeCategoryId) { super("Add Code"); try { Form<Code> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new Code()))); addForm.getModelObject().setCategoryId(codeCategoryId); addForm.add(new CodeInputPanel("code", false)); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { codesService.createCode(addForm.getModelObject()); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the code: " + e.getMessage(), e); AddCodePage.this.error("Failed to add the code"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddCodePage", e); } }
From source file:guru.mmp.application.web.template.pages.AddConfigurationValuePage.java
License:Apache License
/** * Constructs a new <configurationValue>AddConfigurationPage</configurationValue>. * * @param previousPage the previous page *///from www.j a v a 2s. com AddConfigurationValuePage(PageReference previousPage) { super("Add Configuration Value"); try { Form<ConfigurationValue> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new ConfigurationValue()))); addForm.add(new ConfigurationValueInputPanel("configurationValue", false)); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { ConfigurationValue configurationValue = addForm.getModelObject(); configurationService.setValue(configurationValue.getKey(), configurationValue.getValue(), configurationValue.getDescription()); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the configuration value: " + e.getMessage(), e); AddConfigurationValuePage.this.error("Failed to add the configuration value"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddConfigurationValuePage", e); } }
From source file:guru.mmp.application.web.template.pages.AddGroupPage.java
License:Apache License
/** * Constructs a new <code>AddGroupPage</code>. * * @param previousPage the previous page * @param userDirectoryId the Universally Unique Identifier (UUID) used to uniquely identify the * user directory */// w w w. j a v a 2s. c o m AddGroupPage(PageReference previousPage, UUID userDirectoryId) { super("Add Group"); try { Form<Group> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new Group()))); addForm.add(new GroupInputPanel("group", false)); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { Group group = addForm.getModelObject(); // Check if a group with the specified code already exists and if so return an error try { securityService.getGroup(userDirectoryId, group.getGroupName()); AddGroupPage.this.error("A group with the specified group name already exists."); return; } catch (GroupNotFoundException e) { // Do nothing, this is not an error } securityService.createGroup(userDirectoryId, group); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the group: " + e.getMessage(), e); AddGroupPage.this.error("Failed to add the group"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddGroupPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddJobPage.java
License:Apache License
/** * Constructs a new <code>AddJobPage</code>. * * @param previousPage the previous page *//*from w ww . j a va 2 s. c o m*/ public AddJobPage(PageReference previousPage) { super("Add Job"); try { Form<Job> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new Job()))); addForm.getModelObject().setId(UUID.randomUUID()); // The "id" field TextField<String> idField = new TextFieldWithFeedback<>("id"); idField.setRequired(true); addForm.add(idField); // The "name" field TextField<String> nameField = new TextFieldWithFeedback<>("name"); nameField.setRequired(true); addForm.add(nameField); // The "schedulingPattern" field TextField<String> schedulingPatternField = new TextFieldWithFeedback<>("schedulingPattern"); schedulingPatternField.setRequired(true); addForm.add(schedulingPatternField); // The "jobClass" field TextField<String> jobClassField = new TextFieldWithFeedback<>("jobClass"); jobClassField.setRequired(true); addForm.add(jobClassField); // The "status" field DropDownChoice<Job.Status> statusField = new DropDownChoiceWithFeedback<>("status", getStatusOptions(), new JobStatusChoiceRenderer()); statusField.setRequired(true); addForm.add(statusField); // The "isEnabled" field CheckBox isEnabledField = new CheckBox("isEnabled"); addForm.add(isEnabledField); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { Job job = addForm.getModelObject(); schedulerService.createJob(job); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the job: " + e.getMessage(), e); error("Your request could not be processed at this time."); error("Please contact your administrator."); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddJobPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddOrganisationPage.java
License:Apache License
/** * Constructs a new <code>AddOrganisationPage</code>. * * @param previousPage the previous page */// w w w . ja v a2s . c o m AddOrganisationPage(PageReference previousPage) { super("Add Organisation"); try { Form<Organisation> addForm = new Form<>("addForm", new CompoundPropertyModel<>( new Model<>(new Organisation(UUID.randomUUID(), "", OrganisationStatus.ACTIVE)))); // The "id" field TextField<UUID> idField = new TextFieldWithFeedback<>("id"); idField.setRequired(true); addForm.add(idField); // The "name" field TextField<String> nameField = new TextFieldWithFeedback<>("name"); nameField.setRequired(true); addForm.add(nameField); // The "createUserDirectory" field CheckBox createUserDirectoryCheckbox = new CheckBox("createUserDirectory", new PropertyModel<>(this, "createUserDirectory")); createUserDirectoryCheckbox.setRequired(false); addForm.add(createUserDirectoryCheckbox); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { Organisation organisation = addForm.getModelObject(); try { securityService.createOrganisation(organisation, createUserDirectory); } catch (DuplicateOrganisationException e) { AddOrganisationPage.this .error("An organisation with the specified code already exists."); return; } setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the organisation: " + e.getMessage(), e); AddOrganisationPage.this.error("Failed to add the organisation"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddOrganisationPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddReportDefinitionPage.java
License:Apache License
/** * Constructs a new <code>AddReportDefinitionPage</code>. * * @param previousPage the previous page */// w w w . j a v a2s . co m AddReportDefinitionPage(PageReference previousPage) { super("Add Report Definition"); try { Form<ReportDefinition> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new ReportDefinition()))); addForm.getModelObject().setId(UUID.randomUUID()); ReportDefinitionInputPanel reportDefinitionInputPanel = new ReportDefinitionInputPanel( "reportDefinition", false); addForm.add(reportDefinitionInputPanel); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { FileUpload fileUpload = null; try { ReportDefinition reportDefinition = addForm.getModelObject(); fileUpload = reportDefinitionInputPanel.getFileUpload(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int numberOfBytesRead; InputStream in = new BufferedInputStream(fileUpload.getInputStream()); byte[] buffer = new byte[512]; while ((numberOfBytesRead = in.read(buffer)) != -1) { baos.write(buffer, 0, numberOfBytesRead); } reportDefinition.setTemplate(baos.toByteArray()); reportingService.saveReportDefinition(reportDefinition); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the report definition: " + e.getMessage(), e); AddReportDefinitionPage.this.error("Failed to add the report definition"); } finally { try { if (fileUpload != null) { // Delete the uploaded file fileUpload.delete(); } } catch (Throwable e) { logger.error(String.format("Failed to delete the uploaded file (%s)", fileUpload.getClientFileName()), e); } } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddReportDefinitionPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddUserDirectoryPage.java
License:Apache License
/** * Constructs a new <code>AddUserDirectoryPage</code>. * * @param previousPage the previous page * @param userDirectoryType the user directory type *///w w w .j a v a 2 s . c om AddUserDirectoryPage(PageReference previousPage, UserDirectoryType userDirectoryType) { super("Add User Directory"); try { UserDirectory userDirectory = new UserDirectory(); userDirectory.setTypeId(userDirectoryType.getId()); userDirectory.setType(userDirectory.getType()); IModel<UserDirectory> userDirectoryModel = new Model<>(userDirectory); Form<UserDirectory> addForm = new Form<>("addForm", new CompoundPropertyModel<>(userDirectoryModel)); addForm.getModelObject().setId(UUID.randomUUID()); // The "id" field TextField<UUID> idField = new TextFieldWithFeedback<>("id"); idField.setRequired(true); addForm.add(idField); // The "name" field TextField<String> nameField = new TextFieldWithFeedback<>("name"); nameField.setRequired(true); addForm.add(nameField); // The "userDirectoryTypeName" field TextField<String> userDirectoryTypeNameField = new TextField<>("userDirectoryTypeName", new Model<>(userDirectoryType.getName())); userDirectoryTypeNameField.setRequired(false); userDirectoryTypeNameField.setEnabled(false); addForm.add(userDirectoryTypeNameField); Class<? extends UserDirectoryAdministrationPanel> userDirectoryAdministrationPanelClass = userDirectoryType .getAdministrationClass().asSubclass(UserDirectoryAdministrationPanel.class); Constructor<? extends UserDirectoryAdministrationPanel> constructor = userDirectoryAdministrationPanelClass .getConstructor(String.class, IModel.class); UserDirectoryAdministrationPanel userDirectoryAdministrationPanel = constructor .newInstance("userDirectoryAdministrationPanel", userDirectoryModel); addForm.add(userDirectoryAdministrationPanel); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { UserDirectory userDirectory = addForm.getModelObject(); securityService.createUserDirectory(userDirectory); setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the user directory: " + e.getMessage(), e); AddUserDirectoryPage.this.error("Failed to add the user directory"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddUserDirectoryPage", e); } }
From source file:guru.mmp.application.web.template.pages.AddUserPage.java
License:Apache License
/** * Constructs a new <code>AddUserPage</code>. * * @param previousPage the previous page * @param userDirectoryId the Universally Unique Identifier (UUID) used to uniquely identify the * user directory *//* w w w. j a v a 2 s .c om*/ AddUserPage(PageReference previousPage, UUID userDirectoryId) { super("Add User"); try { Form<User> addForm = new Form<>("addForm", new CompoundPropertyModel<>(new Model<>(new User()))); // The "username" field TextField<String> usernameField = new TextFieldWithFeedback<>("username"); usernameField.setRequired(true); addForm.add(usernameField); // The "firstName" field TextField<String> firstNameField = new TextFieldWithFeedback<>("firstName"); firstNameField.setRequired(true); addForm.add(firstNameField); // The "lastName" field TextField<String> lastNameField = new TextFieldWithFeedback<>("lastName"); lastNameField.setRequired(true); addForm.add(lastNameField); // The "email" field TextField<String> emailField = new TextFieldWithFeedback<>("email"); emailField.add(EmailAddressValidator.getInstance()); emailField.setRequired(true); addForm.add(emailField); // The "phoneNumber" field TextField<String> phoneNumberField = new TextFieldWithFeedback<>("phoneNumber"); phoneNumberField.setRequired(false); addForm.add(phoneNumberField); // The "mobileNumber" field TextField<String> mobileNumberField = new TextFieldWithFeedback<>("mobileNumber"); mobileNumberField.setRequired(false); addForm.add(mobileNumberField); // The "password" field PasswordTextFieldWithFeedback passwordField = new PasswordTextFieldWithFeedback("password"); passwordField.setRequired(true); passwordField.add(StringValidator.minimumLength(6)); passwordField.add(new PasswordPolicyValidator()); passwordField.setLabel(Model.of("Password")); addForm.add(passwordField); // The "confirmPassword" field PasswordTextFieldWithFeedback confirmPasswordField = new PasswordTextFieldWithFeedback( "confirmPassword", Model.of("")); confirmPasswordField.setRequired(true); addForm.add(confirmPasswordField); addForm.add(new EqualPasswordInputValidator(passwordField, confirmPasswordField)); // The "expiredPassword" field CheckBox expiredPasswordCheckbox = new CheckBox("expiredPassword", new PropertyModel<>(this, "expiredPassword")); expiredPasswordCheckbox.setRequired(false); addForm.add(expiredPasswordCheckbox); // The "userLocked" field CheckBox userLockedCheckbox = new CheckBox("userLocked", new PropertyModel<>(this, "userLocked")); userLockedCheckbox.setRequired(false); addForm.add(userLockedCheckbox); // The "groupName" field DropDownChoice<String> groupNameField = new DropDownChoiceWithFeedback<>("groupName", new PropertyModel<>(this, "groupName"), getGroupOptions(userDirectoryId)); groupNameField.setRequired(false); addForm.add(groupNameField); // The "addButton" button Button addButton = new Button("addButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { try { User user = addForm.getModelObject(); // Check if a user with the specified username already exists and if so return an error try { securityService.getUser(userDirectoryId, user.getUsername()); error("A user with the specified username already exists."); return; } catch (UserNotFoundException ignored) { } securityService.createUser(userDirectoryId, user, expiredPassword, userLocked); if (!StringUtil.isNullOrEmpty(groupName)) { securityService.addUserToGroup(userDirectoryId, user.getUsername(), groupName); } setResponsePage(previousPage.getPage()); } catch (Throwable e) { logger.error("Failed to add the user: " + e.getMessage(), e); AddUserPage.this.error("Failed to add the user"); } } }; addButton.setDefaultFormProcessing(true); addForm.add(addButton); // The "cancelButton" button Button cancelButton = new Button("cancelButton") { private static final long serialVersionUID = 1000000; @Override public void onSubmit() { setResponsePage(previousPage.getPage()); } }; cancelButton.setDefaultFormProcessing(false); addForm.add(cancelButton); add(addForm); } catch (Throwable e) { throw new WebApplicationException("Failed to initialise the AddUserPage", e); } }