/** * Copyright (C) 2008-2010, Squale Project - http://www.squale.org * * This file is part of Squale. * * Squale is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or any later version. * * Squale is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Squale. If not, see <http://www.gnu.org/licenses/>. */ /* * Cr�� le 4 mars 05 * * Pour changer le mod�le de ce fichier g�n�r�, allez � : * Fen�tre>Pr�f�rences>Java>G�n�ration de code>Code et commentaires */ package org.squale.welcom.taglib.table; import java.lang.reflect.InvocationTargetException; import javax.servlet.jsp.JspException; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.validator.GenericValidator; import org.squale.welcom.outils.Util; import org.squale.welcom.outils.WelcomConfigurator; import org.squale.welcom.struts.bean.WIEditable; /** * @author M327837 Pour changer le mod�le de ce commentaire de type g�n�r�, allez � : * Fen�tre>Pr�f�rences>Java>G�n�ration de code>Code et commentaires */ public class ColEdit extends ColDisabled implements ICol { /** logger */ private static Log log = LogFactory.getLog( ColEdit.class ); /** ordre ascendant */ protected String titleEdit = ""; /** ordre descendant */ protected String titleCancel = ""; /** From (pour revenir sur la table ) */ protected String from; /** Base URL */ protected String baseURL = ""; /** RequestURI */ protected String requestURI = ""; /** * Constructeur */ public ColEdit() { } /** * @see org.squale.welcom.taglib.table.ICol#getCurrentValue(int, java.lang.Object, int, java.lang.String, * java.lang.String) */ public String getSpecificContent( final int position, final Object bean, final int idIndex, final String style, final String styleSelect, final int pageLength ) throws JspException { final StringBuffer s = new StringBuffer(); final String formName = getCols().getTable().getFormName(); if ( GenericValidator.isBlankOrNull( formName ) ) { throw new JspException( "ColEditTag must be used inside a form tag." ); } if ( bean instanceof WIEditable ) { if ( ( !getProperty().equals( "" ) ) && ( !getProperty().equals( "edited" ) ) ) { return ( "Attention, le bean '" + bean.getClass() + "' impl�mente d�j� WIEditable, on ne tient donc pas compte de la property '" + getProperty() + "'" ); } setProperty( "edited" ); } else if ( GenericValidator.isBlankOrNull( getProperty() ) ) { return ( "le bean '" + bean.getClass() + "' doit impl�menter WIEditable, ou l'attribut property du tag <ColEdit> doit �tre renseigner" ); } String result = ""; try { result = BeanUtils.getProperty( bean, getProperty() ); } catch ( final IllegalAccessException e ) { log.error( e, e ); } catch ( final InvocationTargetException e ) { log.error( e, e ); } catch ( final NoSuchMethodException e ) { log.error( e, e ); } s.append( "<a href=\"" ); if ( Util.isTrue( result ) ) { s.append( "javascript:tableForward('" + formName + "','" + getHref( "false", idIndex, pageLength ) + "')\">" ); s.append( "<img src=\"" ); s.append( WelcomConfigurator.getMessageWithCfgChartePrefix( ".htmltable.images.coledit.cancel" ) ); s.append( "\"" ); if ( !GenericValidator.isBlankOrNull( titleCancel ) ) { s.append( " title=\"" ); s.append( titleCancel ); s.append( "\"" ); } } else { s.append( "javascript:tableForward('" + formName + "','" + getHref( "true", idIndex, pageLength ) + "')\">" ); s.append( "<img src=\"" ); s.append( WelcomConfigurator.getMessageWithCfgChartePrefix( ".htmltable.images.coledit.edit" ) ); s.append( "\"" ); if ( !GenericValidator.isBlankOrNull( titleEdit ) ) { s.append( " title=\"" ); s.append( titleEdit ); s.append( "\"" ); } } s.append( " border=0>" ); s.append( "</a>" ); return s.toString(); } /** * @param position la position de la colonne * @param edited en edition * @return href en rajoutant le sens */ private String getHref( final String edited, final int position, final int pageLength ) { final StringBuffer s = new StringBuffer(); s.append( baseURL ); s.append( "/" ); s.append( Util.SERVEPATH ); s.append( "?requestURI=" ); s.append( Util.encode( getRequestURI() ) ); s.append( "&from=" ); if ( from == null ) { s.append( ( position / pageLength ) * pageLength ); } else { s.append( getFrom() ); } s.append( "&" ); s.append( getCols().getPropertyFull( position ) ); s.append( "." ); s.append( getProperty() ); s.append( "=" ); s.append( edited ); s.append( "&" ); s.append( getCols().getPropertyFull( position ) ); s.append( ".changed=true" ); return s.toString(); } /** * @return accesseur */ public String getTitleCancel() { return titleCancel; } /** * @return accesseur */ public String getTitleEdit() { return titleEdit; } /** * @param string accesseur */ public void setTitleCancel( final String string ) { titleCancel = string; } /** * @param string accesseur */ public void setTitleEdit( final String string ) { titleEdit = string; } /** * @return accesseur */ public String getFrom() { if ( from == null ) { return "0"; } return from; } /** * @param string accesseur */ public void setFrom( final String string ) { from = string; } /** * @return accesseur */ public String getBaseURL() { return baseURL; } /** * @param string accesseur */ public void setBaseURL( final String string ) { baseURL = string; } /** * @return accesseur */ public String getRequestURI() { return requestURI; } /** * @param string accesseur */ public void setRequestURI( final String string ) { requestURI = string; } }