List of usage examples for org.apache.wicket.markup.html.form Form getInnermostModel
public final IModel<?> getInnermostModel()
From source file:org.devgateway.eudevfin.dim.pages.transaction.crs.TransactionPage.java
License:Open Source License
@SuppressWarnings("unchecked") public TransactionPage(final PageParameters parameters) { super(parameters); //override the title pageTitle.setDefaultModel(new StringResourceModel( parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString(""), this, null, null)); try {// ww w . j ava 2 s . c o m // check if the key is missing in the resource file getString(parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".note"); note = new Label("note", new StringResourceModel( parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".note", this, null, null)); } catch (MissingResourceException mre) { note = new Label("note", new Model<String>(" ")); note.add(new AttributeAppender("class", new Model<String>("hide"), " ")); } add(note.setEscapeModelStrings(false)); try { // check if the key is missing in the resource file getString(parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".subnote"); subnote = new Label("subnote", new StringResourceModel( parameters.get(Constants.PARAM_TRANSACTION_TYPE).toString("") + ".subnote", this, null, null)); } catch (MissingResourceException mre) { subnote = new Label("subnote", new Model<String>(" ")); subnote.add(new AttributeAppender("class", new Model<String>("hide"), " ")); } add(subnote.setEscapeModelStrings(false)); onUnloadScript = "window.onbeforeunload = function(e) {\n" + " var message = '" + new StringResourceModel("leaveMessage", this, null, null).getObject() + "';\n" + " e = e || window.event;\n" + " if(e) {\n" + " e.returnValue = message;\n" + // For IE 8 and old Firefox " }\n" + " return message;\n" + "};"; // TODO: check that transactionType in the request parameters is the // same as the loaded transaction's type FinancialTransaction financialTransaction = null; if (!parameters.get(PARAM_TRANSACTION_ID).isNull()) { long transactionId = parameters.get(PARAM_TRANSACTION_ID).toLong(); financialTransaction = financialTransactionService.findOne(transactionId).getEntity(); } else { financialTransaction = getFinancialTransaction(); initializeFinancialTransaction(financialTransaction, parameters); } CompoundPropertyModel<FinancialTransaction> model = new CompoundPropertyModel<FinancialTransaction>( financialTransaction); setModel(model); form = new Form("form"); add(form); List<ITabWithKey> tabList = populateTabList(parameters); BootstrapJSTabbedPanel<ITabWithKey> bc = new BootstrapJSTabbedPanel<>("bc", tabList) .positionTabs(BootstrapJSTabbedPanel.Orientation.RIGHT); form.add(bc); submitButton = new TransactionPageSubmitButton("submit", new StringResourceModel("button.submit", this, null, null)) { private static final long serialVersionUID = -1909494416938537482L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { logger.info("Submit pressed"); FinancialTransaction transaction = (FinancialTransaction) form.getInnermostModel().getObject(); Message message = prepareMessage(transaction); super.onSubmit(target, form); message = checkNewId(message, transaction); if (!form.hasError()) { //send the message if any if (message != null) mxService.save(message); setResponsePage(HomePage.class); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { super.onError(target, form); target.appendJavaScript(onUnloadScript); } }; submitButton .add(new AttributePrepender("onclick", new Model<String>("window.onbeforeunload = null;"), " ")); form.add(submitButton); TransactionPageSubmitButton saveButton = new TransactionPageSubmitButton("save", new StringResourceModel("button.save", this, null, null)) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (TransactionPage.this instanceof CustomTransactionPage) { CustomTransactionPage ctp = (CustomTransactionPage) TransactionPage.this; ctp.getApproved().getField().setModelObject(false); ctp.getDraft().getField().setModelObject(true); target.add(ctp.getDraft().getField()); target.add(ctp.getApproved().getField()); } super.onSubmit(target, form); } }; saveButton.setDefaultFormProcessing(false); form.add(saveButton); TransactionPageDeleteButton transactionPageDeleteButton = new TransactionPageDeleteButton("delete", new StringResourceModel("button.delete", this, null, null)); MetaDataRoleAuthorizationStrategy.authorize(transactionPageDeleteButton, Component.ENABLE, AuthConstants.Roles.ROLE_TEAMLEAD); form.add(transactionPageDeleteButton); form.add(new BootstrapCancelButton("cancel", new StringResourceModel("button.cancel", this, null, null)) { private static final long serialVersionUID = -3097577464142022353L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { logger.info("Cancel pressed"); setResponsePage(HomePage.class); } }); feedbackPanel = new NotificationPanel("feedback"); feedbackPanel.setOutputMarkupId(true); feedbackPanel.hideAfter(Duration.seconds(5)); add(feedbackPanel); }
From source file:org.devgateway.eudevfin.mcm.pages.EditOrganizationPage.java
License:Open Source License
public EditOrganizationPage(final PageParameters parameters) { super(parameters); final Organization org; if (Strings.isEqual(parameters.get(PARAM_ORG_ID).toString(), PARAM_ORG_ID_VALUE_NEW)) { org = new Organization(); org.setDac(false);// w ww . j av a2 s. c o m Organization organizationForCurrentUser = AuthUtils.getOrganizationForCurrentUser(); org.setDonorCode(organizationForCurrentUser.getDonorCode()); org.setDonorName(organizationForCurrentUser.getDonorName()); } else { long orgId = parameters.get(PARAM_ORG_ID).toLong(); org = organizationService.findOne(orgId).getEntity(); } Form<Organization> form = new Form<Organization>("form"); CompoundPropertyModel<Organization> model = new CompoundPropertyModel<>(org); setModel(model); TextInputField<String> name = new TextInputField<>("name", new RWComponentPropertyModel<String>("name")) .required().typeString(); form.add(name); TextInputField<String> acronym = new TextInputField<>("acronym", new RWComponentPropertyModel<String>("acronym")).required().typeString(); form.add(acronym); TextInputField<String> code = new TextInputField<>("code", new RWComponentPropertyModel<String>("code")) .required().typeString(); form.add(code); TextInputField<String> donorName = new TextInputField<>("donorName", new RWComponentPropertyModel<String>("donorName")).required().typeString(); donorName.getField().setEnabled(false); form.add(donorName); form.add(new BootstrapSubmitButton("submit", new StringResourceModel("button.submit", this, null, (Object) null)) { private static final long serialVersionUID = 1748161296530970075L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { // TODO Auto-generated method stub super.onError(target, form); target.add(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { logger.info("Submitted ok!"); logger.info("Object:" + getModel().getObject()); organizationService.save(org); mondrianCacheUtil.flushMondrianCDACache(); setResponsePage(ListOrganizationsPage.class); } }); form.add(new BootstrapDeleteButton("delete", new StringResourceModel("button.delete", this, null)) { private static final long serialVersionUID = 6700688063444818086L; protected void onSubmit(AjaxRequestTarget target, Form<?> form) { Organization org = (Organization) form.getInnermostModel().getObject(); logger.debug("Object:" + org); logger.info("Deleting!"); target.add(feedbackPanel); try { if (org.getId() == null) return; organizationService.delete(org); info(new NotificationMessage( new StringResourceModel("notification.deleted", EditOrganizationPage.this, null))); mondrianCacheUtil.flushMondrianCDACache(); } catch (Exception e) { logger.error("Exception while trying to delete:", e); error(new NotificationMessage( new StringResourceModel("notification.cannotdelete", EditOrganizationPage.this, null))); return; } setResponsePage(ListOrganizationsPage.class); logger.info("Deleted ok!"); }; }); form.add(new BootstrapCancelButton("cancel", new StringResourceModel("button.cancel", this, null, (Object) null)) { private static final long serialVersionUID = 6700688063444818086L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { logger.info("Cancel pressed"); setResponsePage(ListOrganizationsPage.class); } }); form.add(new UniqueOrganizationCodeAndDonorCodeValidator(code.getField(), donorName.getField(), org.getId())); add(form); feedbackPanel = new NotificationPanel("feedback"); feedbackPanel.setOutputMarkupId(true); feedbackPanel.hideAfter(Duration.seconds(4)); add(feedbackPanel); }
From source file:org.devgateway.eudevfin.ui.common.validators.DuplicateCurrencyValidator.java
License:Open Source License
@Override public void validate(IValidatable<CurrencyUnit> validatable) { Form<?> form = this.formComponent.findParent(Form.class); IModel<FinancialTransaction> tx = (IModel<FinancialTransaction>) form.getInnermostModel(); if (tx.getObject().getCurrency().equals(validatable.getValue())) { ValidationError error = new ValidationError(this); error.addKey("currencies.duplicate"); validatable.error(error);// w ww . jav a 2 s .c o m //this.formComponent.clearInput(); } }