List of usage examples for org.apache.wicket.markup.html.form FormComponent isRequired
public boolean isRequired()
From source file:au.org.theark.core.web.behavior.ArkRequiredFieldHintBehavior.java
License:Open Source License
public void afterRender(Component component) { try {// w w w .j av a 2 s. c om FormComponent<?> fc = (FormComponent<?>) component; if (fc.isRequired()) { // Append the span and img icon right after the rendering of the // component. Not as pretty as working with a panel etc, but works // for behaviors and is more efficient org.apache.wicket.request.Response response = component.getResponse(); response.write("<span class=\"requiredHint\">*</span>"); } } catch (ClassCastException cce) { // ignore non FormComponent Objects } }
From source file:au.org.theark.core.web.component.ArkRequiredBorder.java
License:Open Source License
@Override public void afterRender(Component component) { try {//from w w w .ja v a 2 s . c o m FormComponent<?> fc = (FormComponent<?>) component; if (fc.isRequired()) { super.afterRender(component); } } catch (ClassCastException cce) { // ignore non FormComponent Objects } }
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 www .j av a2 s .c o m 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:com.francetelecom.clara.cloud.presentation.tools.FieldFeedbackDecorator.java
License:Apache License
public void beforeRender(Component component) { FormComponent<?> fc = (FormComponent<?>) component; Response r = component.getResponse(); String label = (fc.getLabel() != null) ? fc.getLabel().getObject() : null; if (label != null) { r.write("<span class=\"param\">"); r.write("<label for=\""); r.write(fc.getMarkupId());/* ww w.j ava 2s.co m*/ r.write("\""); if (!fc.isValid()) { r.write(" class=\"error\""); } r.write(" />"); r.write(Strings.escapeMarkup(label)); r.write("</label>"); r.write("</span>"); NotNull clazz; try { Field field = fc.getForm().getModelObject().getClass().getDeclaredField(fc.getInputName()); clazz = field.getAnnotation(NotNull.class); } catch (NoSuchFieldException e) { clazz = null; } if (clazz != null || fc.isRequired()) { r.write("<span class=\"required\" title=\""); r.write(fc.getString("portal.error.required.field.title")); r.write("\">"); r.write(fc.getString("portal.required.field") + "</span>"); } else { r.write("<span class=\"notrequired\"></span>"); } r.write("<span class=\"value\">"); } super.beforeRender(component); }
From source file:com.pushinginertia.wicket.core.form.behavior.InputDecorator.java
License:Open Source License
@Override public void onConfigure(final Component component) { final FormComponent<?> fc = (FormComponent<?>) component; if (maxLength > 0) { fc.add(StringValidator.MaximumLengthValidator.maximumLength(maxLength)); fc.add(new AttributeModifier(ATTR_MAXLENGTH, new Model<Integer>(maxLength))); }/* w w w .j a va 2s . co m*/ if (fc.isRequired() && html5RequiredModifierSupport()) { // append html5 'required' attribute fc.add(REQUIRED_MODIFIER); } super.onConfigure(component); }
From source file:cz.zcu.kiv.eegdatabase.wui.components.utils.WicketUtils.java
License:Apache License
/** * Adds labels and feedback panels for input fields to the given form * The label ids are of the form <original id>.label * The feedback ids are of the form <original id>.feedback * * FormComponentPanel instances wont get a label or a feedback unless they * implement ISingleLabelFormComponentPanel interface. * If they do, their children dont get any labels or feedbacks. * * @param form//from w ww . j ava 2 s .com */ public static void addLabelsAndFeedback(Form<?> form) { final Set<String> ids = new HashSet<String>(); final Map<String, MarkupContainer> parents = new HashMap<String, MarkupContainer>(); final Map<String, ComponentFeedbackPanel> feedbacks = new HashMap<String, ComponentFeedbackPanel>(); final Map<String, FormComponentLabel> labels = new HashMap<String, FormComponentLabel>(); form.visitFormComponents(new IVisitor<FormComponent<?>, Void>() { @Override public void component(FormComponent<?> object, IVisit<Void> visit) { if (object instanceof FormComponent && !(object instanceof Button) && object.findParent(FormComponentPanel.class) == null) { ids.add(object.getId()); parents.put(object.getId(), object.getParent()); //create a feedback panel for the component ComponentFeedbackPanel temp = new ComponentFeedbackPanel(object.getId() + ".feedback", object); temp.setVisible(object.isVisible()); //do not display component if field is not visible feedbacks.put(object.getId(), temp); if (object.isRequired()) { String lab = object.getLabel().getObject(); object.setLabel(new Model<String>(lab.concat("*"))); } FormComponentLabel lab = new MyFormComponentLabel(object.getId() + ".label", object); lab.setVisible(object.isVisible()); labels.put(object.getId(), lab); } } }); for (String id : ids) { parents.get(id).addOrReplace(labels.get(id)); parents.get(id).addOrReplace(feedbacks.get(id)); } }
From source file:org.xaloon.wicket.component.jquery.tab.ValidatedForm.java
License:Apache License
public boolean hasRequiredFields() { final BooleanHolder result = new BooleanHolder(); visitFormComponents(new FormComponent.IVisitor() { @SuppressWarnings("unchecked") public Object formComponent(IFormVisitorParticipant formComponent) { if (result.value) { return null; }/* w w w . java 2 s . c om*/ if (formComponent instanceof FormComponent) { FormComponent c = (FormComponent) formComponent; if (c.isRequired()) { result.value = true; } } return null; } }); return result.value; }
From source file:ro.nextreports.server.web.common.form.AdvancedFormComponentLabel.java
License:Apache License
public AdvancedFormComponentLabel(String id, FormComponent<?> component) { super(id, component); component.setLabel(new ResourceModel(component.getId())); if (component.isRequired()) { add(AttributeModifier.replace("class", "requiredHint")); }/*from www . j a v a 2s. co m*/ }
From source file:ro.nextreports.server.web.common.form.AdvancedFormComponentLabel.java
License:Apache License
@Override public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { super.onComponentTagBody(markupStream, openTag); FormComponent<?> fc = getFormComponent(); if (fc.isRequired()) { fc.getResponse().write(new ResourceModel("required.indicator").getObject().toString()); }//w w w . j av a 2s .c o m }