Custom Tag, Custom Rendering

I've got a custom tag thats fairly basic such as the following:
<my:page>
</my:page>Now when the PageTag class runs, I want to have it query a database and grab a list of items and print them out such as:
Item 1
Item 2
Item 3
However I want to be able to override the way it prints out a particular item, so if I do something like:
<my:page>
<my:override dbitem="Item 1" replaceTextWith="Item 4" />
</my:page>Then I want to get something like:
Item 4
Item 2
Item 3
In other words, it needs to stay in order. So what I need is control of the children rendering process so I can replace the database row with the overridden item. Now this is an over-simplified method of what I am trying to do, for instance the <my:override> tag will actually have to render HTML, it cannot just be invisible and call its parent (<my:page>) and set some flag to override, it has to be standalone as well.

I figured out how to handle all this, If you have a similar issue, look up extending BodyTagSupport instead of TagSupport. BodyTagSupport gives you much more control over the design and presentation of your tags.

Similar Messages

  • Custom tag with rendered attribute

    Is it possible to create a custom tag that operates similar to a JSF tag with the rendered attribute? Wrapping output with c:if test="..." is not as nice as the JSF rendered option, but I don't want to use JSF for this particular project.
    Edited by: black_lotus on Nov 23, 2007 12:13 PM

    TLD File, per your previous recommendation:
    <attribute>
         <name>disabled</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
         <type>boolean</type>
    </attribute>My Tag class (snippet):
    public class ButtonTag extends TagSupport
      private boolean disabled;
      public ButtonTag() {}
      public boolean isDisabled()
         return disabled;
      public void setDisabled(boolean b)
        disabled = b;
    }A sample of the jsp file invoking it:
    <c:set var="result" value="${computedValue}"/>
    <ltm:button disabled="${result}"/>Regardless of the value of result, ("true" or "false") it always passes false to the setDisabled method of the button tag class.

  • Custom Tag -- Custom Component problems with iframes

    I have a "project" component that originally iterated over a list of models and created/renderered the corresponding (and fairly complex) interactive UI components for those models. On the client-side, the output from these were then organized neatly into "tabs" via CSS ... all on one page. Since these UI Components are so hefty, when any iteraction was done on one of them, the whole page had to re-render and things got just plain slow. To get around this limitation, I decided to have my "project" component no longer create the UI components himself, but instead generate an IFRAME that points to a page that will generate a single component. This way, any iteraction will just cause that single IFRAME to refresh.
    Due to the fact that an IFRAME can only be populated by using the src attribute, I have created a page that contains a JSF View (<faces:view>) and inside is a single custom tag of mine (<mine:displayView>). Let's call this page singleDisplayView.jsf. I create iframes that point to singleDisplayView.jsf with different request params for each (singleDisplayView.jsf?modelName=Foo, singleDisplayView.jsf?modelName=Bar, etc.)
    The displayView tag has one attribute called requestQueryString and I use the tag like so:
    <t:displayView requestQueryString="<%=request.getQueryString()%>" />The displayView tag's class is DisplayViewTag. In DisplayViewTag::setProperties(UIComponent uiComponent) method, I get the model name out of the request map and set this property on the UIComponent.
    The problem is that I'm noticing that as the main page (that contains these frames) loads, setProperties() is only being called twice. After that, the components created by subsequent iframes just seem to be using the modelName from the second frame.
    Is there a syncronization issue I don't understand?
    Any ideas?
    Any help would be much appreciated.
    Thanks in advance,
    Mark

    On a possibly related note, I read this in an article of the JSF application lifecycle:
    In the first phase of the JSF lifecycle -- restore view -- a request comes
    through the FacesServlet controller. The controller examines the request and
    extracts the view ID, which is determined by the name of the JSP page.Could it be that the lifecycle is trying to reuse components from a single view, since all these iframes are pointing to the same page?

  • Custom taglib: tags not rendered in visual editor

    Hi!
    I have created a custom tag library with jsf tags. I have created one tag that extends the CoreSelectOneChoiceTag. When I drag this tag on a page, at runtime it works completely as desired.
    Only, in the visual editor the tag is invisible. With the tag library properties I have specified that the tags should be executed. In the source and structure windows the tags is visible (of course).
    What influences how a tag is rendered in the visual editor, and what content is rendered?
    Jeroen van Veldhuizen

    I know there's a recent release with a visual editor problem, but I'm not sure which one it is. This thread says you need a fresh install? Can you try that?
    Re: ADF Faces tutorial/code sample for data table?

  • Rendering Querydata in nested Custom-Tags

    Hi all
    I have built two custom-tags to render the results of a query
    in a table (a bit like the display-tag-library or the datatable-tag
    of JSF). the parent tag takes the query as attributes as well as
    some other things like records per page.
    the child-tag defines a single column. the developer can
    define a query-column-name in an attribute as well as the label and
    so on.
    the typical code looks like this and this works fine:
    <tags:dataTable collection="#AddressQuery#"
    basePath="#link.list#">
    <tags:dataTableColumn column="id" label=""
    selection="true" />
    <tags:dataTableColumn column="name" label="Name"
    sortable="true" />
    <tags:dataTableColumn column="street" label="Strasse"
    sortable="true" />
    <tags:dataTableColumn column="houseNumber"
    label="Hausnummer" sortable="true" />
    <tags:dataTableColumn column="isEnabled" label="Aktiv"
    sortable="false" />
    </tags:dataTable>
    Now, I'd like to allow the developer to write custom code to
    generate the content of a table column. For example show the value
    of a bit-field with icons:
    <tags:dataTableColumn label="my bit-column">
    <cfif #columnname# gt 0>[display image
    "active"]<cfelse>display image "inactive"</cfif>
    </tags:dataTableColumn>
    Unfortunately, this throws an error because the variable of
    the querycolumnname can't be resolved when the tag-content is
    executed (the query-loop is done when the parent's end-tag is
    processed).
    Can I prevent CF to execute the tag-content, but instead save
    the code of the developer and execute it later when processing the
    endtag of the parent?
    If not can I solve this problem otherwise?
    thanks
    stefan

    Hi Jesse.
    I'm also working on something very similar to the tab pane you are talking about. Mine was inspired by the CoreJSF book (I used some of the downloadable pre-release chapters). Great book. It's at www.corejsf.com
    The basic idea behind theirs (and mine) is that the tab pane widget maintains a collection of tabs as a property. In the tag handler class you can specify the tabs themselves as either child components or facets (they used f:selectItem and f:selectItems, along with facets). I liked the f:selectItems the best.
    All of the rendering is done in the renderer class. The book has examples of how to include additional jsp content specified as a fragment.
    I would really suggest having a look at the book.
    Regards,
    Dave Haas

  • Rendering A JPEG image with a custom tag

    Hi All,
    I have dilema. I'm trying to rendering a jpeg in IE/FireFox with a custom tag that I developed. I'm able to access the bean and invoke the getter method to return the InputStream property. But what gets rendered is the byte code not the image. I've tried just about anything I could think off. If any body has an answer I would difinitely appreciate it.
    Thanks,
    Tony
    Below is the jsp, tld, bean and tag.
    ********************************* image.jsp ****************************************
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ taglib uri="/WEB-INF/custom-chtml.tld" prefix="chtml" %>
    <html>
    <head>
    <title>HTML Page</title>
    </head>
    <body bgcolor="#FFFFFF">
    <chtml:img name="photo" property="file"/>
    </body>
    </html>
    ********************************* custom-chtml.tld **********************************
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>chtml</shortname>
    <tag>
    <name>img</name>
    <tagclass>com.struts.taglib.CustomImgTag</tagclass>
    <bodycontent>empty</bodycontent>
    <attribute>
    <name>name</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <name>property</name>
    <required>true</required>
    <rtexprvalue>true</rtexprvalue>
    </attribute>
    </tag>
    </taglib>
    **************************** MemberPhotoBean.java ******************************
    import java.io.InputStream;
    * @author tony
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class MemberPhotoValue {
         private String memberId;
         private int fileSize;
         private InputStream file;
         public MemberPhotoValue() {
         public MemberPhotoValue(String memberId, InputStream file) {
              this.memberId = memberId;
              this.file = file;
         public MemberPhotoValue(String memberId,int fileSize,InputStream file) {
              this.memberId = memberId;
              this.fileSize = fileSize;
              this.file = file;          
         public String getMemberId(){
              return memberId;
         public void setMemberId(String memberId) {
              this.memberId = memberId;
         public int getFileSize() {
              return fileSize;
         public void setFileSize(int fileSize) {
              this.fileSize = fileSize;
         public InputStream getFile(){
              return file;
         public void setFile(InputStream file) {
              this.file = file;
    *************************** CustomTagHandler.java ********************************
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import java.lang.reflect.Method;
    import java.lang.reflect.InvocationTargetException;
    import java.awt.image.*;
    import java.awt.*;
    import javax.swing.ImageIcon;
    import com.sun.image.codec.jpeg.*;
    * JSP Tag Handler class
    * @jsp.tag name = "CustomImg"
    * display-name = "Name for CustomImg"
    * description = "Description for CustomImg"
    * body-content = "empty"
    public class CustomImgTag implements Tag {
         private PageContext pageContext;
         private Tag parent;
         private String property;
         private String name;
         private Class bean;
         public int doStartTag() throws JspException {
              return SKIP_BODY;
         public int doEndTag() throws JspException {
         try {
         ServletResponse response = pageContext.getResponse();
         // read in the image from the bean
         InputStream stream = (InputStream) invokeBeanMethod();
         BufferedImage image = ImageIO.read(stream);          Image inImage = new ImageIcon(image).getImage();
         Graphics2D g = image.createGraphics();
         g.drawImage(inImage,null,null);               
         OutputStream out = response.getOutputStream();
    // JPEG-encode the image
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(image);               
         out.close();     
    } catch (IOException io) {
              throw new JspException(io.getMessage());
         return EVAL_PAGE;
         public void release(){}
    private InputStream invokeBeanMethod() throws JspException {
         try {
         Object bean = null;
         if (null != pageContext.getAttribute(name)) {
         bean = (Object) pageContext.getAttributename);
         else if (null != pageContext.getSession().getAttribute(name)) {
         bean = (Object) pageContext.getSession().getAttribute(name);
         else if (null != pageContext.getRequest().getAttribute(name)) {
         bean = (Object) pageContext.getRequest().getAttribute(name);
         else {
         throw new JspException("Bean : "+name+" is not found in any pe.");
         Class[] parameters = null;
         Object[] obj = null;               
         Method method = bean.getClass().getMethod("getFile",parameters);
         return (InputStream) method.invoke(bean,obj);
         } catch (NoSuchMethodException ne) {
         throw new JspException("No getter method "+property+" for bean : "+bean);
         } catch (IllegalAccessException ie) {
         throw new JspException(ie.getMessage());
         } catch (InvocationTargetException ie) {
         throw new JspException(ie.toString());
         public void setPageContext(PageContext pageContext) {
              this.pageContext = pageContext;
         public void setParent(Tag parent) {
              this.parent = parent;
         public Tag getParent() {
              return parent;
         public void setProperty(String property) {
              this.property = property;
         public void setName(String name) {
              this.name = name;
    **************************************************************************************

    If you have access to an image editing tool such as photoshop, I would advice you import the image into Phototshop and save it in a different format e.g, GIF format and re-import it into Final Cut Express HD. This could solve your rendering problem if all you need is to use a Still image.
    Ayemenre

  • Custom Tag output not being rendered in JSF

    Hello,
    I have the following for loop in a custom tag that I developed;
    out.println("<ul>");
    for (int i = 0; i < noOfDays; i++)
    //out.println("<li><h:commandLink value=\"" +DateHelper.addDays(dtToday, i)+ "\" action=\"#{BookingBean.showAvailability}\"/></li>");
    out.println("<li><a href=\"" +DateHelper.addDays(dtToday, i)+ "\">" DateHelper.addDays(dtToday, i) "</a></li>");
    out.println("</ul>");
    The issue I have is that the second line prints out fine whereas the first one (when uncommented) prints out the bullet points associated with a list but does not render the h:commandLink.
    Any thoughts would be great.
    Cheers,
    Rich

    Hi,
    You can not embade a JSF tag in your code as you did, try adding component as children to your custum tag
    see this code as exemple : [HTMLDataTable.java|http://www.docjar.com/html/api/org/apache/myfaces/component/html/ext/HtmlDataTable.java.html]

  • Custom Tag Attribute not correctly rendered

    Hello,
    I made a custom tag and I want the engine to parse dynamic scripts and evaluate them.
    I call the tag like this :
        <form:toolbaritem id="icon_cancelar" action="javascript:listingAction('<%= request.getContextPath() %>/logout.do');" icon="<%= request.getContextPath() %>/images/toolbar/Cancelar_32.gif"/>The icon and action attributes are declared in the tld like so :
              <attribute>
                   <name>action</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
              <attribute>
                   <name>icon</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>However, the tag is not working with the evaluated expression, receiving "<%= request.getContextPath() %>" instead.
    Any help would be very welcome :) thank you
    Eamerial

    Gotcha........
    First, this is what the jsp spec has to say in sec 1.14.1
    When using scriptlet expressions, the expression must
    appear by itself (multiple expressions, and mixing of expressions and string
    constants are not permitted). Multiple operations must be performed within the
    expression.Simple, isnt it ? All you have to is evaluate the expression as a whole.
    <form:toolbaritem id="icon_cancelar" action="<%="javascript:listingAction('" + request.getContextPath() + "/logout.do;')"%>" icon<%= request.getContextPath() + " /images/toolbar/Cancelar_32.gif " %>"/>cheers,
    ram.

  • Connection Pooling and JSP Custom Tag Library - is code (inside) the best way/correc?

    Hi, can anyone advise as to whether my tag library code (based
    on Apache Jakarta Project) will actually achieve connection
    pooling functionality across my entire JSP based application? I
    am slightly concerned that my OracleConnectionCacheImpl object
    may exist multiple times, hence rendering my conection pooling
    attempt useless.
    package com.solved.tag.dbtags.connection;
    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.servlet.jsp.tagext.TagSupport;
    import javax.servlet.jsp.JspTagException;
    import javax.sql.DataSource;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import oracle.jdbc.pool.OracleConnectionCacheImpl;
    * <p>JSP tag connection, used to get a
    * java.sql.Connection object.</p>
    * <p>JSP Tag Lib Descriptor
    * <pre>
    * &lt;name>connection&lt;/name>
    &lt;tagclass>com.solved.tag.dbtags.connection.ConnectionTag&lt;/t
    agclass>
    * &lt;bodycontent>JSP&lt;/bodycontent>
    &lt;teiclass>com.solved.tag.dbtags.connection.ConnectionTEI&lt;/t
    eiclass>
    * &lt;info>Opens a connection based on a jndiName.&lt;/info>
    * &lt;attribute>
    * &lt;name>id&lt;/name>
    * &lt;required>true&lt;/required>
    * &lt;rtexprvalue>false&lt;/rtexprvalue>
    * &lt;/attribute>
    * </pre>
    * @author Matt Shannon
    public class ConnectionTag extends TagSupport {
    static private OracleConnectionCacheImpl cache = null;
    public int doStartTag() throws JspTagException {
    try {
    Connection conn = null;
    if (cache == null) {
    try {
    InitialContext ic = new InitialContext();
    DataSource ds = (DataSource) ic.lookup
    ("jdbc/pool/OracleCache");
    cache = (OracleConnectionCacheImpl)ds;
    catch (NamingException ne) {
    throw new JspTagException(ne.toString());
    conn = cache.getConnection();
    pageContext.setAttribute(getId(),conn);
    catch (SQLException e) {
    throw new JspTagException(e.toString());
    return EVAL_BODY_INCLUDE;
    package com.solved.tag.dbtags.connection;
    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.servlet.jsp.tagext.TagSupport;
    * <p>JSP tag closeconnection, used to close the
    * specified java.sql.Connection.<p>
    * <p>JSP Tag Lib Descriptor
    * <pre>
    * &lt;name>closeConnection&lt;/name>
    &lt;tagclass>com.solved.tag.dbtags.connection.CloseConnectionTag&
    lt;/tagclass>
    * &lt;bodycontent>empty&lt;/bodycontent>
    * &lt;info>Close the specified connection. The "conn"
    attribute is the name of a
    * connection object in the page context.&lt;/info>
    * &lt;attribute>
    * &lt;name>conn&lt;/name>
    * &lt;required>true&lt;/required>
    * &lt;rtexprvalue>false&lt;/rtexprvalue>
    * &lt;/attribute>
    * </pre>
    * @author Matt Shannon
    * @see ConnectionTag
    public class CloseConnectionTag extends TagSupport {
    private String _connId = null;
    * The "conn" attribute is the name of a
    * page context object containing a
    * java.sql.Connection.
    * @param connectionId
    * attribute name of the java.sql.Connection to
    close.
    * @see ConnectionTag
    public void setConn(String connectionId) {
    _connId = connectionId;
    public int doStartTag() {
    try {
    Connection conn = (Connection)pageContext.getAttribute
    (_connId);
    conn.close();
    } catch (SQLException e) {
    // failing to close a connection is not fatal
    e.printStackTrace();
    return EVAL_BODY_INCLUDE;
    public void release() {
    _connId = null;
    package com.solved.tag.dbtags.connection;
    import javax.servlet.jsp.tagext.TagData;
    import javax.servlet.jsp.tagext.TagExtraInfo;
    import javax.servlet.jsp.tagext.VariableInfo;
    * TagExtraInfo for the connection tag. This
    * TagExtraInfo specifies that the ConnectionTag
    * assigns a java.sql.Connection object to the
    * "id" attribute at the end tag.
    * @author Matt Shannon
    * @see ConnectionTag
    public class ConnectionTEI extends TagExtraInfo {
    public final VariableInfo[] getVariableInfo(TagData data)
    return new VariableInfo[]
    new VariableInfo(
    data.getAttributeString("id"),
    "java.sql.Connection",
    true,
    VariableInfo.AT_END
    data-sources.xml:
    <?xml version="1.0"?>
    <!DOCTYPE data-sources PUBLIC "Orion data-
    sources" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
    <data-sources>
    <data-source
    class="oracle.jdbc.pool.OracleConnectionCacheImpl"
    name="jdbc/pool/OracleCache"
    location="jdbc/pool/OracleCache"
    url="jdbc:oracle:thin:@oracle1:1521:pdev"
    >
    <property name="maxLimit" value="15" />
    <property name="cacheScheme" value="2" />
    <property name="user" value="console" />
    <property name="password" value="console" />
    <description>
    This DataSource is using an Oracle-native DataSource Class so as
    to allow Oracle Specific extensions.
    A getConnection() call on this DataSource will return
    oracle.jdbc.driver.OracleConnection.
    The connection returned is a logical connection.
    The caching scheme in place is Fixed Wait. Refer below to
    possible values.
    Dynamic 1
    Fixed Wait 2
    Fixed Return Null 3
    </description>
    </data-source>
    </data-sources>
    many thanks,
    Matt.

    Hi. Show me your pool definition.
    Joe
    Ramamurthy wrote:
    I am using the jsp custom tag library from BEA called sqltags.tld which came with Weblogic 5.1. Currently I am using Weblogic6.1 sp2 on Solaris.
    I have created a Connection Pool for Sybase database using the driver com.sybase.jdbc.SybDriver.
    When I created jsp page to connect to the connection pool using sqltags custom tag library, I am getting the error
    "javax.servlet.jsp.JspException: Failed to write body content
    at weblogic.taglib.sql.ConnectionTag.doAfterBody(ConnectionTag.java:43)
    at jsp_servlet.__hubwcdata._jspService(__sampletest.java:1014)"
    After this message, whenever I try to access the same jsp page I am getting the message
    "javax.servlet.jsp.JspException: Failed to load JDBC driver: weblogic.jdbc.pool.D
    river
    at weblogic.taglib.sql.ConnectionTag.doStartTag(ConnectionTag.java:34)
    at jsp_servlet.__hubwcdata._jspService(__sampletest.java:205)".
    Can you please help me the reason why this problem is happening and how to fix this ?
    This problem doexn't happen consistently. This occurs once in a while.
    I tried to increase Login delay Seconds parameter in the Connection Pool to 15 sec. It didn't help me much.
    Thanks for your help !!!
    Ram

  • Custom tag for Marquee in JSF

    Hi,
    I am trying to develop a custom tag for Marquee in JSF, my usecase is to display a value from managed bean(Dynamically). please find the code below and guide me where i have made mistake
    regards
    Sandeep
    Component class:
    package customtags;
    import javax.el.ValueExpression;
    import javax.faces.component.UIComponentBase;
    import javax.faces.context.FacesContext;
    public class Marquee extends UIComponentBase {
         public static final String COMPONENT_TYPE = "marqueecomp";
         public static final String RENDERER_TYPE = "marqueeRenderer";
         private Object[] _state = null;
         private String value;
         public String getValue() {
              if (null != this.value) {
                   return this.value;
              ValueExpression _ve = getValueExpression("value");
              return (_ve != null) ? (String) _ve.getValue(getFacesContext()
                        .getELContext()) : null;
         public void setValue(String marquee) {
              this.value = marquee;
         public String getFamily() {
              // TODO Auto-generated method stub
              return COMPONENT_TYPE;
    //     public void encodeBegin(FacesContext context) throws IOException {
    //          ResponseWriter writer = context.getResponseWriter();
    //          writer.startElement("marquee", this);
    //          writer.write(getValue());
    //          writer.endElement("marquee");
         public void restoreState(FacesContext context, Object state) {
              this._state = (Object[]) _state;
              super.restoreState(_context, this._state[0]);
              value = (String) this._state[1];
         public Object saveState(FacesContext _context) {
              if (_state == null) {
                   _state = new Object[2];
              state[0] = super.saveState(context);
              _state[1] = value;
              return _state;
    Tag Class:
    package customtags;
    import javax.el.ValueExpression;
    import javax.faces.component.UIComponent;
    import javax.faces.webapp.UIComponentELTag;
    public class MarqueeTag extends UIComponentELTag {
         protected ValueExpression marquee;
         public String getComponentType() {
              // TODO Auto-generated method stub
              return Marquee.COMPONENT_TYPE;
         public String getRendererType() {
              // TODO Auto-generated method stub
              return Marquee.RENDERER_TYPE;
         * protected void setProperties(UIComponent component) {
         * super.setProperties(component); Marquee marqComp = (Marquee) component;
         * if (marquee != null) { marqComp.setValue(marquee); } }
         protected void setProperties(UIComponent component) {
              super.setProperties(component);
              Marquee marqComp = null;
              try {
                   marqComp = (Marquee) component;
              } catch (ClassCastException cce) {
                   throw new IllegalStateException(
                             "Component "
                                       + component.toString()
                                       + " not expected type. Expected: com.foo.Foo. Perhaps you're missing a tag?");
              if (marquee != null) {
                   //marqComp.setValueExpression("value", marquee);
                   marqComp.setValue("fsdfsdfsdfsdfsd");
         * @return the marquee
         public ValueExpression getMarquee() {
              return marquee;
         * @param marquee
         * the marquee to set
         public void setMarquee(ValueExpression marquee) {
              this.marquee = marquee;
    *.tld file*
    <?xml version="1.0" encoding="UTF-8"?>
    <taglib xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
         version="2.1">
         <tlib-version>1.0</tlib-version>
         <short-name>marqueecomp</short-name>
         <uri>http://tags.org/marquee</uri>
         <tag>
              <name>marqueeTag</name>
    <tag-class>customtags.MarqueeTag</tag-class>
    <body-content>empty</body-content>
    <attribute>
    <description><![CDATA[Your description here]]></description>
    <name>id</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
    <description><![CDATA[Your description here]]></description>
    <name>value</name>
    </attribute>
         </tag>
    </taglib>
    Renderer class:
    package customtags;
    import java.io.IOException;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    import javax.faces.render.Renderer;
    public class MarqueeRenderer extends Renderer {
         public void encodeBegin(final FacesContext facesContext,
    final UIComponent component) throws IOException {
    super.encodeBegin(facesContext, component);
    final ResponseWriter writer = facesContext.getResponseWriter();
    writer.startElement("DIV", component);
    /*String styleClass =
    (String)attributes.get(Shuffler.STYLECLASS_ATTRIBUTE_KEY);
    writer.writeAttribute("class", styleClass, null);*/
    public void encodeEnd(final FacesContext facesContext,
    final UIComponent component) throws IOException {
    final ResponseWriter writer = facesContext.getResponseWriter();
    writer.endElement("DIV");
    in Faces-Config:
    <component>
              <display-name>marqueecomp</display-name>
              <component-type>marqueecomp</component-type>
              <component-class>customtags.Marquee</component-class>
              <component-extension>
    <renderer-type>marqueeRenderer</renderer-type>
    </component-extension>
         </component>
         <render-kit>
    <renderer>
    <component-family>marqueecomp</component-family>
    <renderer-type>marqueeRenderer</renderer-type>
    <renderer-class>customtags.MarqueeRenderer</renderer-class>
    </renderer>
    </render-kit>
    In class path --->marquee.taglib.xml
    <?xml version="1.0"?>
    <!DOCTYPE facelet-taglib PUBLIC
    "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
    "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
    <facelet-taglib>
    <namespace>http://tags.org/marquee</namespace>
    <tag>
    <tag-name>marqueeTag</tag-name>
    <component>
    <component-type>marqueecomp</component-type>
    <renderer-type>marqueeRenderer</renderer-type>
    </component>
    </tag>
    </facelet-taglib>
    *.xhtml file*
    <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
         xmlns:a4j="http://richfaces.org/a4j"
         xmlns:rich="http://richfaces.org/rich" xmlns:mycomp="http://tags.org/marquee">
    <head>
    <title>DEBTDOC Home Page</title>
    <meta http-equiv="keywords" content="enter,your,keywords,here" />
    <meta http-equiv="description"
         content="A short description of this page." />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"></link>
    <script language="javascript" src="../script/common.js"></script>
    </head>
    <body>
    <f:view>
    <mycomp:marqueeTag value="hello World"></mycomp:marqueeTag>

    There exist the JSTL SQL taglib, but I don't recommend this. It should only be used for quick development and testing. For database connectivity, rather create a data layer with DAO classes which you on its turn just plug in your business layer (with servlets).

  • Custom tag - setProperties() not called

    Hi all,
    I've created my first custom tag with it's own component class, Tag Class, Renderer and TLD. However, when the JSP first loads, the encode() method fails in trying to get the attribute values from the attribute Map - the Map is empty. Upon further debugging I can see that the Tag class is called and the setter methods are called for each attribute but the setProperties() method is never called before release(), so the attributes are never stored in the UIComponent's attribute Map.
    Anybody know what I'm doing wrong?
    Some code:
    Tag Class...
    public class ListShuttleTag extends UIComponentTag
    public void setProperites(UIComponent component)
      super.setProperties(component);
      ComponentTagHelper.setString(component, "sourceValue", sourceValue);
      ComponentTagHelper.setString(component, "targetValue", targetValue);
      ComponentTagHelper.setInteger(component, "size", size);
      ComponentTagHelper.setInteger(component, "targetListWidth", targetListWidth);
      ComponentTagHelper.setInteger(component, "sourceListWidth", sourceListWidth);
      ComponentTagHelper.setString(component, "sourceCaption", sourceCaption);
      ComponentTagHelper.setString(component, "targetCaption", targetCaption);
    ...TLD...
      <taglib>
        <tlib-version>1.1</tlib-version>
        <jsp-version>2.1</jsp-version>
        <tag>
          <name>listShuttle</name>
          <tag-class>com.katun.jsf.tag.ListShuttleTag</tag-class>
          <description>A listShuttle allows the moving of items from one listBox to another</description>
          <!-- General component attributes -->
          <attribute>
            <name>binding</name>
            <description>
                 A binding that points to a bean property
            </description>     
          </attribute>
          <attribute>
            <name>id</name>
            <description>The client id of this component</description>     
          </attribute>
          <attribute>
            <name>rendered</name>
            <description>Is this component rendered?</description>     
          </attribute>
          <attribute>
            <name>disabled</name>
            <description>Is this component disabled?</description>     
          </attribute>
          <attribute>
            <name>required</name>
            <description>Is this component required?</description>     
          </attribute>
          <!-- listShuttle specific attributes -->
          <attribute>
            <name>sourceValue</name>
            <required>true</required>
            <description>A binding for the items in the source list</description>
          </attribute>
          <attribute>
            <name>targetValue</name>
            <description>A binding for the items in the target list</description>
          </attribute>
          <attribute>
            <name>size</name>
            <description>Defines the number of items visible in each list</description>
          </attribute>
          <attribute>
            <name>sourceListWidth</name>
            <description>Width of the source list</description>
          </attribute>
          <attribute>
            <name>targetListWidth</name>
            <description>Width of the target list</description>
          </attribute>
          <attribute>
            <name>sourceCaption</name>
            <description>Label displayed above the source list</description>
          </attribute>
          <attribute>
            <name>targetCaption</name>
            <description>Label displayed above the target list</description>
          </attribute>
        </tag>
    ...

    Gotcha........
    First, this is what the jsp spec has to say in sec 1.14.1
    When using scriptlet expressions, the expression must
    appear by itself (multiple expressions, and mixing of expressions and string
    constants are not permitted). Multiple operations must be performed within the
    expression.Simple, isnt it ? All you have to is evaluate the expression as a whole.
    <form:toolbaritem id="icon_cancelar" action="<%="javascript:listingAction('" + request.getContextPath() + "/logout.do;')"%>" icon<%= request.getContextPath() + " /images/toolbar/Cancelar_32.gif " %>"/>cheers,
    ram.

  • JSF custom tag body content problem

    Hi, I'm having some problem with a custom tag I built, but the body of the tag content is not rendered correctly.
    I have:<foo:bar>
        <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    </foo:bar>
    </pre>But the rendered html source look like this:    <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    <!-- beging foo tag -->
    <!-- end foo tag -->The <ul> tags are supposed to be inside of the <!-- begin foo --> & <!-- end foo -->. I've declared in TLD it has JSP content. I've compared to the J2EE tutorial and corejsp book again and again, couldn't figure where I went wrong. So, am I missing something?
    Thanks a lot.

    Use <f:verbatim> around the non-jsf content.
    I.e.<foo:bar>
    <f:verbatim>
        <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    </f:verbatim>
    </foo:bar>--
    Sergey : jsfTutorials.net

  • Parsing EL expression in custom tag 10.1.3.4

    Hello all,
    I have a custom tag that extends CoreOutputTextTag. This tag needs to resolve the El expression passed in from the value attribute and perform an operation with it. Since I this tag needs to work with adf 10.1.3.4, the jsp level is 1.2 and does not support container parsing of EL expression directly in the page ($).
    I have tried a couple approaches but both of them result in just the same EL expression I pass in being returned to me. Anyone have an idea of the proper way to resolve an EL expression within a custom tag?
    Thanks in advance,
    - Joe
    public class CoreOutputTextTag extends oracle.adfinternal.view.faces.taglib.core.output.CoreOutputTextTag {
        private String groupId;
        private String groupCode;
        private String value;
        public void setValue(String value) {
            this.value = value;
            super.setValue(value);
        public int doStartTag() throws JspException {
            super.doStartTag();
            UIComponent uiComponent = this.getComponentInstance();
            if (uiComponent instanceof CoreOutputText) {
                CoreOutputText coreOutputTextComponent =
                    (CoreOutputText)uiComponent;
                if (coreOutputTextComponent.getValue() == null) {
                    String codeValue =
                        (String)ExpressionEvaluatorManager.evaluate("value", value,
                                                                    java.lang.String.class,
                                                                    this,
                                                                    pageContext); // the page context
                    try {
                        ExpressionEvaluator expressionEvaluator =
                            pageContext.getExpressionEvaluator();
                        codeValue =
                                (String)expressionEvaluator.evaluate(value, java.lang.String.class,
                                                                     pageContext.getVariableResolver(),
                                                                     null);
                    } catch (ELException elex) {
                    SystemSettingRow row =
                        SystemSettings.getSystemSettings(groupId, groupCode, null,
                                                         value);
                    if (row != null)
                        coreOutputTextComponent.setValue(row.getShortDesc());
            return TagSupport.SKIP_BODY;
        public void setGroupId(String groupId) {
            this.groupId = groupId;
        public String getGroupId() {
            return groupId;
        public void setGroupCode(String groupCode) {
            this.groupCode = groupCode;
        public String getGroupCode() {
            return groupCode;
    <tag>
      <name>coreOutputText</name>
      <tag-class>od.adf.ics.ui.taglib.CoreOutputTextTag</tag-class>
      <body-content>empty</body-content>
      <attribute>
       <name>groupId</name>
       <required>true</required>
      </attribute>
      <attribute>
       <name>groupCode</name>
       <required>true</required>
      </attribute>
      <attribute>
       <name>id</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>truncateAt</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>description</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>escape</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>shortDesc</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>partialTriggers</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onclick</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>ondblclick</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onmousedown</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onmouseup</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onmouseover</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onmousemove</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onmouseout</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onkeypress</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onkeydown</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>onkeyup</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>styleClass</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>inlineStyle</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>value</name>
       <rtexprvalue>true</rtexprvalue>
      </attribute>
      <attribute>
       <name>converter</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>rendered</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>binding</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
      <attribute>
       <name>attributeChangeListener</name>
       <rtexprvalue>false</rtexprvalue>
      </attribute>
    </tag>

    I also would like to know how to accomplish this. I have a similar requirement and need to set the "disable" attribute on a commandbutton and requires an el statement that calls a methodAction defined on the pageDef.
    I followed the great instructions over on this thread:
    ADF FACES:Creating custom component on top of adf
    on how to create custom adf tags for JDeveloper 10.1.3.4.
    many thanks!
    Wes
    Edited by: Wes Fang on Sep 16, 2010 5:39 AM

  • Custom tag library called multiple times

    Hi ppl ,
    I have a custom tag library which i use to populate some menu components. When i do call my custom tag library though , it is called multiple times, use case is as follows.
    I have menu tabs and menu bars which thanks to Mr.Brenden is working splendidly as so:-
    <af:menuTabs>
    <af:forEach var="menuTab" items="#{bindings.menu.vwUserMenuTabRenderer.rangeSet}">
    <af:commandMenuItem text="#{menuTab.MenuLabel}"
    shortDesc="#{menuTab.MenuHint}"
    rendered="true"
    immediate="true"
    selected="#{sessionScope.selectedMenuId == menuTab.MenuId }"
    onclick="fnSetSelectedValue('#{menuTab.MenuId}')" >
    </af:commandMenuItem>
    </af:forEach>
    </af:menuTabs>
    <af:menuBar>
    <af:forEach var="menuBar" items="#{bindings.menu.vwUserMenuBarRenderer.rangeSet}">
    <af:commandMenuItem onclick="return clickreturnvalue()"
    onmouseover="dropdownmenu(this, event,#{menuBar.MenuId}, '150px')"
    onmouseout="delayhidemenu()"
    text="#{menuBar.MenuLabel}"
    action="#{menuBar.MenuUri}"
    rendered="#{menuBar.ParentId == sessionScope.selectedMenuId}"
    immediate="true" />
    </af:forEach>
    </af:menuBar>
    </afc:cache>
    now all of this code is within a subview , and just directly below the subview tag , i have the call to my custom tag library:-
    <myCustomTagLib:menuCascade />
    only issue now is that assuming i have in all 7 menu bar components, the doStartTag is called 7 times. the relevant code within my custom tag class is as follows :-
    public int doStartTag() throws JspException {
    return (EVAL_BODY_INCLUDE);
    public int doEndTag() throws JspException {
    try {
    declareVariables();
    return EVAL_PAGE;
    }catch (Exception ioe) {
    throw new JspException(ioe.getMessage());
    and within my declareVariables method i do an out of the jscript ( out.print(jscript.toString()); ) which is a simple string generated based on certain conditions...
    now it seems to be working fine on the front end , but when i view the source of the page, i notice that the declaration is called multiple times, and this happens because the doStartTag method is called multiple times, i haven't even nested the call to the custom tag within the menu components , any clue as to whats going wrong ?
    Cheers
    K

    Hi,
    if you add the following print statement
    System.out.println("rendering "+FacesContext.getCurrentInstance().getViewRoot().getViewId());
    Then the output in my case is
    07/04/24 08:14:04 rendering /BrowsePage.jsp
    07/04/24 08:14:05 rendering /otn_logo_small.gif
    The image comes from the file system, which means it is rendered by the JSF lifecycle. If you reference the image with a URL then the lifecycle doesn't render the image but only refrences it.
    To avoid your prepare render code to be executed multiple times, just check for jsp and jspx file extensions, which will guarantee that your code only executes for JSF pages, not for loaded files.
    The reason why this happens is because the JSF filter is set to /faces , which means all files that are loaded through that path
    Frank

  • In custom tag, trying to include JSP Page, not processing tags

    Now I have this in the correct forum!
    I am in a custom tag where one of my attributes (myIncludePage) is the name of another JSP file that I want to include. So, in my custom tag doStartTag() I have:
    out.println("<td>");
    pageContext.include(myIncludePage);
    out.println("</td>");
    The included page is rendered with the custom tags in it not processed (I see my tags in the generated HTML)
    How do I get the included page to be "processed"?
    Thanks in advance,
    Sam

    Sorry, wrong forum, should be in the JSP forum. Hope someone can still help!

Maybe you are looking for