Avec Google.fr Rechercher sur ce site :

annuaire gratuit
Tous les Partenaires

Exemple : action personnalisée avec corps 

Voyant comment construire la classe d'une action opérant une addition sur deux opérandes qui doivent être obligatoirement spécifié.

package com.BSHome.jsp.tags;
  
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class tagOperator extends BodyTagSupport {
    private int operand_1;
    private int operand_2;
       
    public void setOperand_1 (int value_1) { 
       this.operand_1 = value_1; 
    }
    public void setOperand_2 (int value_2) { 
       this.operand_2 = value_2; 
    }   
      
    /** **/
    public int doStartTag() 
       throws JspException {
       return EVAL_BODY_BUFFERED;
    }
          
    /** **/
    public int doAfterBody() 
       throws JspException {
       return SKIP_BODY;
    }    
          
    /** 
     *
     */
    public int doEndTag() 
       throws JspException {
       try {
          JspWriter myOut = pageContext.getOut();
                    
          String strOp = getBodyContent().getString();
          StrOp = strOp.trim();
          
          MyOut.print( 
               Integer.toString( operand_1 )
             + " " + strOp + " "
             + Integer.toString( operand_2 )                    
             + " = " );
                         
          if ( strOp.equals( "+" ) == true ) {              
             myOut.println( 
               Integer.toString( operand_1 + operand_2 ) );
          }
          else if ( strOp.equals( "-" ) == true ) {              
             myOut.println( 
               Integer.toString( operand_1 - operand_2 ) );
          }
          else if ( strOp.equals( "*" ) == true ) {              
             myOut.println( 
               Double.toString( operand_1 * operand_2 ) );
          }
          else if ( strOp.equals( "/" ) == true ) {              
             myOut.println( 
               Double.toString( operand_1 / operand_2 ) );
          }
          else {              
             myOut.println( "Indefined Operator" );
          }
       }
       catch (IOException e) { 
      System.out.println( e.toString() ); 
       }
       return EVAL_PAGE;
    }
          
    /**
     */
    public void release() {
       super.release();
    }
}

La description xml de la balise pour cette action qui doit faire partie du fichier TLD global

<tag>
   <name>Operator</name>
   <tagclass>com.BSHome.jsp.tags.tagOperator</tagclass>
   <bodycontent>JSP</bodycontent>
   <info> What My action do </info>
   <attribute>
      <name>operand_1</name>
      <required>true</required>
   </attribute>
   <attribute>
      <name>operand_2</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
   </attribute>
</tag>

Created by BSA XMLSolution v1.7
© 2003-2024 B. SANTAROSSA Tous droits réservés.