Package org.apache.wicket.markup.html.form.validation

Source Code of org.apache.wicket.markup.html.form.validation.FormComponentFeedbackIndicator

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.markup.html.form.validation;

import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.feedback.IFeedback;
import org.apache.wicket.feedback.IFeedbackMessageFilter;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

/**
* A panel that hides or shows itself depending on whether there are feedback messages for a given
* message filter. If a component is set using setIndicatorFor(Component), then the indicator is
* visible when the given component has an error. The default content for this indicator is a red
* star, but you can subclass this panel and provide your own markup to give any custom look you
* desire.
*
* @author Jonathan Locke
*/
public class FormComponentFeedbackIndicator extends Panel implements IFeedback
{
  private static final long serialVersionUID = 1L;

  /** The message filter for this indicator component */
  private IFeedbackMessageFilter filter;

  /**
   * Constructor
   *
   * @param id
   *            See Component
   */
  public FormComponentFeedbackIndicator(final String id)
  {
    super(id);
  }

  /**
   * @see org.apache.wicket.Component#Component(String, IModel)
   */
  public FormComponentFeedbackIndicator(final String id, IModel model)
  {
    super(id, model);
  }

  /**
   * @param component
   *            The component to watch for messages
   */
  public void setIndicatorFor(final Component component)
  {
    filter = new ComponentFeedbackMessageFilter(component);
  }

  /**
   * Set the component's visibility according to the existence (or not) of feedback messages
   */
  public void onBeforeRender()
  {
    super.onBeforeRender();
    // Get the messages for the current page
    setVisible(Session.get().getFeedbackMessages().hasMessage(getFeedbackMessageFilter()));
  }

  protected boolean callOnBeforeRenderIfNotVisible()
  {
    return true;
  }

  /**
   * @return Let subclass specify some other filter
   */
  protected IFeedbackMessageFilter getFeedbackMessageFilter()
  {
    return filter;
  }
}
TOP

Related Classes of org.apache.wicket.markup.html.form.validation.FormComponentFeedbackIndicator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.