jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Bondi" <rbo...@gmail.com>
Subject Convert scoped attributes to scripting variables?
Date Tue, 14 Mar 2006 17:31:30 GMT
Dear All,

This email has a summary, background, and code.

1. How can I turn a scoped attribute (defined in a c:set or c:if tag) into a
scripting variable? I need to pass it into a tiles:put tag.
2. Where is there a definition of "scoped attribute"?

Java limits the size of bytecode bytes in a try{} to 64K. I have a page with
a huge form that keeps growing beyond that. It's five years old, and too
complicated for me to understand given my deadline (using
spring/hibernate/struts/ajax/i8n/spaghetti code), so I just need to break
out chunks of it into either servlet methods and/or separate servlets.
Furthermore, everything is inside a large logic:iterate loop liberally
sprinkled with c: and c-rt: tags.

My plan is to move chunks into tiles using code like this:

<tiles:insert page="tile1.jsp">
  <tiles:put name="somebean" beanName="somebean" beanScope="page"/>
  <tiles:put name="somebean" beanName="somebean" beanScope="page"/>

(tile1.jsp contains a tiles:useAttribute tag that plucks the named bean out
of the context specified in beanScope.)

This works just fine for old tags like logic:iterate.

For c: tags, it fails. There are plenty of variables defined with c:if that
I need to pass to the tile.

But I can't: because those variables are "scoped attributes". As best I can
tell, a scoped attribute is (1) a name/value pair that c: tags can pass
along to each other as long as they use them in their attributes, (2) that
cannot be accessed from scripting variables, and (3) are not kept in the
same context objects that Beans are, so eg pageContext.findAttributes() can'
get at them.

Take the struts-blank webapp that comes with struts, and add the relevant
tags. Then use these jsps and class:

<%@ page import=" aspen.Pebble" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c-rt" uri=" http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fmt" uri=" http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql " %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri=" http://jakarta.apache.org/struts/tags-bean" prefix="bean"
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"

<html:html locale="true">
    <title><bean:message key="welcome.title"/></title>

  <body bgcolor="white">

    ArrayList pebbles = new ArrayList();
    pebbles.add( new Pebble( "one" ) );
    pebbles.add( new Pebble( "two" ) );
    pebbles.add( new Pebble( "three" ) );


    <logic:iterate id="pebble" collection="<%=pebbles%>" type=" aspen.Pebble

    <%--<bean:define id="pebble" name="pebble" type="aspen.Pebble"/>--%>
    <tiles:insert page="tile.jsp" flush="false">
      <tiles:put name="pebble" beanName="pebble" beanScope="page"/>
    <li>From jsp: <%=pebble%></li>



<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<tiles:useAttribute name="pebble" classname="aspen.Pebble"/>
<h1>I came from a tile: <%=pebble%></h1>

Pebble class:
package aspen;

import java.io.Serializable;

public class Pebble implements Serializable {
  private String owner = "";

  public Pebble( String owner ) {
    this.owner = owner;

  public String getOwner() {
    return owner;

  public void setOwner( String owner ) {
    this.owner = owner;

  public String toString() {
    return owner;

Thanks much,

Richard Bondi
33 Royal Ave #3
Cambridge, MA 02138-1301
Email: rbondi at gmail.com
Phone: (617) 938-9562

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message