List of usage examples for org.apache.wicket.markup.html.form FormComponent isValid
public final boolean isValid()
From source file:au.org.theark.core.web.behavior.ArkValidationMsgBehavior.java
License:Open Source License
public void onRendered(Component c) { try {/*from www . java 2s . c o m*/ FormComponent<?> fc = (FormComponent<?>) c; if (!fc.isValid()) { String error; if (fc.hasFeedbackMessage()) { error = fc.getFeedbackMessage().getMessage().toString(); } else { error = "Your input is invalid."; } fc.getResponse().write("<div class=\"validationMsg\">" + error + "</div>"); } } catch (ClassCastException cce) { // ignore non FormComponent Objects } }
From source file:au.org.theark.core.web.component.ArkErrorHighlightBehaviour.java
License:Open Source License
public void onComponentTag(Component c, ComponentTag tag) { try {/*from w w w. j a v a2 s . c o m*/ FormComponent<?> fc = (FormComponent<?>) c; if (!fc.isValid()) { tag.put("class", "error"); } } catch (ClassCastException cce) { // ignore non FormComponent Objects } }
From source file:au.org.theark.core.web.form.AbstractArchiveDetailForm.java
License:Open Source License
protected void initialiseForm() { cancelButton = new AjaxButton(Constants.CANCEL) { private static final long serialVersionUID = 1L; @Override/*from ww w.j a v a 2s .co m*/ protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (isNew()) { editCancelProcess(target); } else { crudVO.getSearchResultPanelContainer().setVisible(true);// Hide the Search Result List Panel via the WebMarkupContainer crudVO.getDetailPanelContainer().setVisible(false);// Hide the Detail Panle via the WebMarkupContainer target.add(crudVO.getDetailPanelContainer()); target.add(crudVO.getSearchResultPanelContainer());// Attach the resultListContainer WebMarkupContainer to be re-rendered onCancelPostProcess(target); } } @Override protected void onError(AjaxRequestTarget arg0, Form<?> arg1) { } }; saveButton = new AjaxButton(Constants.SAVE) { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return ArkPermissionHelper.isActionPermitted(Constants.SAVE); } public void onSubmit(AjaxRequestTarget target, Form<?> form) { onSave(containerForm, target); target.add(crudVO.getDetailPanelContainer()); } @SuppressWarnings("unchecked") public void onError(AjaxRequestTarget target, Form<?> form) { boolean setFocusError = false; WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer"); for (Iterator iterator = wmc.iterator(); iterator.hasNext();) { Component component = (Component) iterator.next(); if (component instanceof FormComponent) { FormComponent formComponent = (FormComponent) component; if (!formComponent.isValid()) { if (!setFocusError) { // Place focus on field in error (for the first field in error) target.focusComponent(formComponent); setFocusError = true; } } } } processErrors(target); } }; addComponentsToForm(); }
From source file:au.org.theark.core.web.form.AbstractDetailForm.java
License:Open Source License
/** * Method to handle Save action, and handle for any errors, placing forcus on any component in error * /* w w w . j a v a 2 s . c o m*/ * @param target */ @SuppressWarnings("unchecked") protected void saveOnErrorProcess(AjaxRequestTarget target) { boolean setFocusError = false; WebMarkupContainer wmc = arkCrudContainerVO.getDetailPanelContainer(); for (Iterator iterator = wmc.iterator(); iterator.hasNext();) { Component component = (Component) iterator.next(); if (component instanceof FormComponent) { FormComponent formComponent = (FormComponent) component; if (!formComponent.isValid()) { if (!setFocusError) { // Place focus on field in error (for the first field in error) target.focusComponent(formComponent); setFocusError = true; } } } } processErrors(target); }
From source file:au.org.theark.core.web.form.AbstractModalDetailForm.java
License:Open Source License
protected void saveOnErrorProcess(AjaxRequestTarget target) { boolean setFocusError = false; WebMarkupContainer wmc = arkCrudContainerVo.getDetailPanelFormContainer(); for (Iterator iterator = wmc.iterator(); iterator.hasNext();) { Component component = (Component) iterator.next(); if (component instanceof FormComponent) { FormComponent formComponent = (FormComponent) component; if (!formComponent.isValid()) { if (!setFocusError) { // Place focus on field in error (for the first field in error) target.focusComponent(formComponent); setFocusError = true; }/*from w w w .jav a2 s .c om*/ } } } target.focusComponent(feedbackPanel); processErrors(target); }
From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java
License:Open Source License
/** * Initialise the form, with the general edit/save/cancel/delete buttons * //from w w w . j av a 2 s . c o m */ protected void initialiseForm() { cancelButton = new AjaxButton(Constants.CANCEL) { private static final long serialVersionUID = 1684005199059571017L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { detailContainer.setVisible(false); target.add(detailContainer); processErrors(target); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } }; saveButton = new ArkBusyAjaxButton(Constants.SAVE) { private static final long serialVersionUID = -423605230448635419L; @Override public boolean isVisible() { return ArkPermissionHelper.isActionPermitted(Constants.SAVE); } public void onSubmit(AjaxRequestTarget target, Form<?> form) { onSave(containerForm, target); target.add(detailFormContainer); target.add(containerPanel); } @SuppressWarnings("unchecked") public void onError(AjaxRequestTarget target, Form<?> form) { boolean setFocusError = false; WebMarkupContainer wmc = (WebMarkupContainer) form.get("detailFormContainer"); for (Iterator iterator = wmc.iterator(); iterator.hasNext();) { Component component = (Component) iterator.next(); if (component instanceof FormComponent) { FormComponent formComponent = (FormComponent) component; if (!formComponent.isValid()) { if (!setFocusError) { // Place focus on field in error (for the first field in error) target.focusComponent(formComponent); setFocusError = true; } } } } processErrors(target); } }; deleteButton = new AjaxDeleteButton(Constants.DELETE, new StringResourceModel("confirmDelete", this, null), new StringResourceModel(Constants.DELETE, this, null)) { private static final long serialVersionUID = 4005032637149080009L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { onDeleteConfirmed(target); target.add(feedbackPanel); detailContainer.setVisible(false); target.add(detailContainer); // remove node DefaultTreeModel treeModel = (DefaultTreeModel) tree.getDefaultModelObject(); for (Object selectedNode : tree.getTreeState().getSelectedNodes()) { treeModel.removeNodeFromParent((MutableTreeNode) selectedNode); } tree.updateTree(target); } @Override public boolean isVisible() { return (ArkPermissionHelper.isActionPermitted(Constants.DELETE) && !isNew()); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); } @Override public boolean isEnabled() { return canDelete(); } }; //editButton.setDefaultFormProcessing(false); cancelButton.setDefaultFormProcessing(false); /* Defines a edit mode */ editButtonContainer = new WebMarkupContainer("editButtonContainer"); editButtonContainer.setOutputMarkupPlaceholderTag(true); editButtonContainer.setVisible(isNew()); // Initialise in read only detailFormContainer = new WebMarkupContainer("detailFormContainer"); detailFormContainer.setOutputMarkupPlaceholderTag(true); detailFormContainer.setEnabled(isNew()); addComponentsToForm(); }
From source file:au.org.theark.lims.web.component.inventory.form.AbstractInventoryDetailForm.java
License:Open Source License
/** * Method to handle Save action, and handle for any errors, placing forcus on any component in error * //from w w w . j a v a 2s .c o m * @param target */ @SuppressWarnings("unchecked") protected void saveOnErrorProcess(AjaxRequestTarget target) { boolean setFocusError = false; WebMarkupContainer wmc = getDetailContainer(); for (Iterator iterator = wmc.iterator(); iterator.hasNext();) { Component component = (Component) iterator.next(); if (component instanceof FormComponent) { FormComponent formComponent = (FormComponent) component; if (!formComponent.isValid()) { if (!setFocusError) { // Place focus on field in error (for the first field in error) target.focusComponent(formComponent); setFocusError = true; } } } } processErrors(target); }
From source file:br.com.oak.wicket.ui.behavior.ComponentVisualErrorBehavior.java
License:Open Source License
/** * Changes the CSS class of the linked {@link FormComponent} via AJAX. * * @param ajaxRequestTarget of type AjaxRequestTarget * @param valid Was the validation succesful? * @param cssClass The CSS class that must be set on the linked {@link FormComponent} *///from w ww. ja v a 2 s. co m private void changeCssClass(AjaxRequestTarget ajaxRequestTarget, boolean valid, String cssClass) { FormComponent<?> formComponent = (FormComponent<?>) getFormComponent(); if (formComponent.isValid() == valid) { formComponent.add(new AttributeModifier("class", true, new Model("formcomponent " + cssClass))); ajaxRequestTarget.add(formComponent); } if (updateComponent != null) { ajaxRequestTarget.add(updateComponent); } }
From source file:ca.travelagency.components.decorators.FieldDecorator.java
License:Apache License
@Override public void beforeRender(Component component) { FormComponent<?> formComponent = (FormComponent<?>) component; Response response = component.getResponse(); response.write("<span id=\""); response.write(getAjaxRegionMarkupId(component)); response.write("\">"); String label = (formComponent.getLabel() != null) ? formComponent.getLabel().getObject() : null; if (!DisplayLabel.None.equals(displayLabel) && label != null) { response.write("<label for=\""); response.write(formComponent.getMarkupId()); response.write("\" class=\"label"); if (DisplayLabel.Inline.equals(displayLabel)) { response.write("Inline"); }/*from w ww . j a v a 2 s . c om*/ if (!formComponent.isValid()) { response.write(" error"); } response.write("\">"); response.write(Strings.escapeMarkup(label)); if (formComponent.isRequired()) { response.write("<span class=\"required\">*</span>"); } response.write("</label>"); } super.beforeRender(component); }
From source file:ca.travelagency.components.decorators.FieldDecorator.java
License:Apache License
@Override public void onComponentTag(Component component, ComponentTag tag) { FormComponent<?> formComponent = (FormComponent<?>) component; if (formComponent.isValid()) { return;// w ww . java 2 s . c o m } String htmlClass = tag.getAttribute("class"); if (htmlClass == null) { tag.put("class", "error"); } else { tag.put("class", "error " + htmlClass); } }