All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.knowgate.stripes.BaseAjaxBean Maven / Gradle / Ivy

Go to download

KnowGate wrapper over Stripes Framework. Base beans, caching and encoding filters.

There is a newer version: 9.1.0
Show newest version
package com.knowgate.stripes;

/**
 * © Copyright 2016 the original author.
 * This file is licensed under the Apache License version 2.0.
 * 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.
 */

import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.AbstractMap.SimpleImmutableEntry;

import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.LocalizableError;
import net.sourceforge.stripes.validation.SimpleError;
import net.sourceforge.stripes.validation.ValidationError;
import net.sourceforge.stripes.validation.ValidationErrors;

/**
 * 

Base class for beans serving a response to AJAX requests

* @author Sergio Montoro Ten * @version 1.0 */ public abstract class BaseAjaxBean extends BaseStripesBean { private String template; private ArrayList infos = new ArrayList(); private ArrayList errors = new ArrayList(); private ArrayList> datavalues = new ArrayList>(); public BaseAjaxBean(String template) { this.template = template; } public List> getResponseData() { return datavalues; } public List getInformationMessages() { return infos; } public int getInformationMessagesCount() { return infos.size(); } public List getErrors() { return errors; } public int getErrorsCount() { return errors.size(); } public ValidationError addError(String f, SimpleError e, ValidationErrors v) { errors.add(e); if (v!=null) if (f!=null) if (f.length()>0) v.add(f, e); else v.addGlobalError(e); else v.addGlobalError(e); return e; } public ValidationError addError(String f, SimpleError e) { return addError(f, e, null); } public ValidationError addError(SimpleError e, ValidationErrors v) { return addError(e.getFieldName(), e, null); } public ValidationError addError(SimpleError e) { return addError(e.getFieldName(), e, null); } public ValidationError addError(String f, LocalizableError l, ValidationErrors v) { SimpleError e = new SimpleError(l.getMessage(getContext().getLocale()), l.getReplacementParameters()); if (l.getFieldName()!=null) e.setFieldName(l.getFieldName()); if (l.getFieldValue()!=null) e.setFieldValue(l.getFieldValue()); return addError(f, e, v); } public ValidationError addError(LocalizableError l, ValidationErrors v) { SimpleError e = new SimpleError(l.getMessage(getContext().getLocale()), l.getReplacementParameters()); if (l.getFieldName()!=null) e.setFieldName(l.getFieldName()); if (l.getFieldValue()!=null) e.setFieldValue(l.getFieldValue()); return addError(e, v); } public ValidationError addError(LocalizableError l) { return addError(l, null); } public ValidationError addInformationMessage(SimpleError m) { infos.add(m); return m; } public Entry addDataLine(String sCode, String sText) { SimpleImmutableEntry nv = new SimpleImmutableEntry(sCode,sText); datavalues.add(nv); return nv; } public Resolution AjaxResponseResolution() { return new ForwardResolution(template); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy