001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup.html.form; 018 019import java.io.Serializable; 020 021import org.apache.wicket.Component; 022import org.apache.wicket.util.io.IClusterable; 023import org.apache.wicket.util.lang.Args; 024import org.apache.wicket.validation.IValidationError; 025 026 027/** 028 * This class is the parameter to {@link Component#error(Serializable)} instead of the generated 029 * error string itself (when {@link FormComponent#error(IValidationError)} is called). The advantage 030 * is that a custom feedback panel would still have access to the underlying 031 * {@link IValidationError} that generated the error message - providing much more context. 032 * 033 * @author Igor Vaynberg (ivaynberg) 034 */ 035public class ValidationErrorFeedback implements IClusterable 036{ 037 private static final long serialVersionUID = 1L; 038 039 /** error object */ 040 private final IValidationError error; 041 042 /** error message */ 043 private final Serializable message; 044 045 /** 046 * Construct. 047 * 048 * @param error 049 * @param message 050 */ 051 public ValidationErrorFeedback(final IValidationError error, final Serializable message) 052 { 053 this.error = Args.notNull(error, "error"); 054 this.message = message; 055 } 056 057 /** 058 * Gets error. 059 * 060 * @return error 061 */ 062 public IValidationError getError() 063 { 064 return error; 065 } 066 067 /** 068 * Gets message. 069 * 070 * @return message 071 */ 072 public Serializable getMessage() 073 074 { 075 return message; 076 } 077 078 @Override 079 public String toString() 080 { 081 return message != null ? message.toString() : ""; 082 } 083}