RE: Nested logic:iterate tags

2001-06-06 Thread Amos Shapira

Hi,

I just had bad experience with ServletExec 3.0E and nested
iterate tags.  When I changed the inner iterate tag back to
scriptlets things startted working again (the code worked fine
under Tomcat 3.2.1).

Is anyone aware of problems with NewAtlanta's handling of custom
tags in general or Struts in particular?

My env:

1. Sun JDK 1.2.2_5/6
2. New Atlanta ServletExec 3.0E
3. Windows 2000 Professional or Sparc Solaris 2.6
4. Jakarta Struts and Jakarta Taglib

Thanks,

--Amos

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 06, 2001 5:59 PM
To: [EMAIL PROTECTED]
Subject: Re: Nested logic:iterate tags


Marc,
Here's a sample of nested iterate tags IterateForm.java and
TimeNavDblIter.jsp.
Thanks to Craig et al  it's a piece of cake.


john ware



/   TimeNavDblIter.jsp




<%@ page language="java" import = "com.jdware.beans.*" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>



<%
IterateForm instance = new IterateForm();
instance.setName( "yeh baby" );

 pageContext.setAttribute("instance", instance,
PageContext.PAGE_SCOPE);


%>



Name: 
Address  

  TypeSize
<% int h = 0; %>

  

  
  <% h++; %>

  
  
<% int i = 0; %>
  
  

  


  


  <% int j = 0; %>
  

  

<% j++; %>
  
  
<% i++; %>


  
   



//  end
TimeNavDblIter.jsp

// IterateForm.java

package com.jdware.beans;


import java.util.*;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import com.jdware.util.Trace;


public class IterateForm  extends ActionForm {

public String name = "TestMe";
public String address = "Sischo Dr";
public IterateForm(){
foos = Foo.getFoosByMagic();
}

public static class Foo implements Comparable {
public String type;
public int size;
public Foo(){
type="foo";
size=0;
bars = Bar.getBarsByMagic();
}
public Foo( String type, int size ){
bars = Bar.getBarsByMagic();
this.type = type;
this.size = size;
}
public static ArrayList getFoosByMagic(){
ArrayList rtn = new ArrayList();
rtn.add( new Foo("typeA", 42));
rtn.add( new Foo("typeF", 2));
rtn.add( new Foo("typeW", 4));
rtn.add( new Foo("typeH", 0));
rtn.add( new Foo("typeX", 77));

return rtn;
}
public String getType(){return type;}
public void setType( String type ){ this.type = type; }

public int getSize(){ return size; }
public void setSize( int size ){ this.size = size; }
public int compareTo(Object o){
return type.compareTo( ((Foo)o).type );
}
public static class Bar implements Comparable{
/**
 *
 */
public String date;
public String getDate(){ return date; }
public void setDate( String date ){ this.date = date; }
/**
 *
 */
public String activity;
public String getActivity(){ return activity; }
public void setActivity( String activity ){ this.activity =
activity; }

/**
 *
 */
public double hours;
public double getHours(){ return hours; }
public void   setHours( double hours ) { this.hours = hours; }

public Bar(){
date = "8/5/50";
activity = "nonsense";
hours = 8.5;
}
public Bar( String date, String activity, double hours ){
this.date = date;
this.activity = activity;
this.hours = hours;
}
public static ArrayList getBarsByMagic(){
ArrayList rtn = new ArrayList();
rtn.add( new Bar("4/3/54", "chores", 8.5));
rtn.add( new Bar("2/5/85", "hotguys", 0.5));
rtn.add( new Bar("6/4/88", "battle", 3.5));
rtn.add( new Bar("8/5/50", "fun", 18.5));
return rtn;
}
public int compareTo(Object o){
return date.compareTo( ((Bar)o).date );
}
public String toString(){
StringBuffer buf = new StringBuffer();
buf.append( " date : " ).append( 

RE: Help me defend Struts taglibs!!!

2001-05-31 Thread Amos Shapira

As the local neighborhood taglibs pusher in my company, I came
under some scrutiny about the lack of an Else in tags and realised
the difficulty about nesting XML tags legally, just as described by
Craig in his message below.

What I pretty quickly came up with is a "switch" syntax:


  
...
  
  
  


It's not stright-forward if/else, but it is (IMHO):

1. Legal XML
2. Relatively clear as an if/else clause
3. Provides a solution for a more general case of switch/case

What do you think?

Cheers,

--Amos Shapira
WebCollage

-Original Message-
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 31, 2001 6:18 AM
To: '[EMAIL PROTECTED]'
Subject: RE: Help me defend Struts taglibs!!!




On Thu, 26 Apr 2001, Scott Cressler wrote:

> One thing this argument might come down to is why custom tags, especially
> for "if...else" stuff (which, BTW, IMHO is not handled real well by the
> struts tags...would be nicer to have more flexibility in the conditions
you
> can check and to have the ability to do else, rather than
> .but
> that's another discussion :-).  In other words, if it is so easy to just
> slap some Java in their to do some conditional stuff, why use a clumsy
tag.
> 

It turns out to be surprisingly difficult to come up with syntax for an
"else" construct that is legal XML syntax and isn't really ugly.

There's currently work going on in the JSP Standard Tag Library effort
(JSR-052) to create tags that will eventually be known to all containters
in the same way that tags like  are -- which will also deal
with a lot of the performance related concerns.  It looks like there will
be reasonable ways to do "switch" and "if-else" type processing with them.

In the mean time, we can reconsider adding an "else" capability in Struts
1.1, if someone can come up with a good syntax.

Craig



RE: How to use the new iterate tag?

2001-05-23 Thread Amos Shapira

Hi,

Thanks a lot!  That's exactly what I wanted.

You said that it seems like an overkill to use a tag, is there
another way to access this index?

What are the chances to see this tag in the library?

Cheers,

--Amos

> -Original Message-
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 23, 2001 7:29 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: RE: How to use the new iterate tag?
> 
> 
> Do you just want to display the index? If you do, I just 
> wrote a custom tag that does that. It allows me to remove one 
> of the last instances of scriptlets that I have in my jsps. 
> It's seems overkill to have a tag that just displays the 
> iterate counter but oh well. If nothing else, you can use it 
> as an example of how to access the index of the iterate tag. 

[ rest deleted ]



RE: Iterating on an Iterator?

2001-05-23 Thread Amos Shapira

Thanks,

I mnissed that part - but Iterate can also take an iterator.

Sorry about the noise...

--Amos

> -Original Message-
> From: Jim Richards [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 23, 2001 12:45 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Iterating on an Iterator?
> 
> 
> 
>  takes a collection and can do that for you.
> 
> >Our object model provides an Iterator interface to walk along
> >lists (properties of an object or lists of objects).
> >
> >Does anyone know how can I take advantage of a tag library to
> >accept an iterator an iterate using Iterator.hasNext() and
> >Iterator.next()?
> 
> 
> --
> Kumera - a new Open Source Content Management System
> for small to medium web sites written in Perl and using XML
> http://www.cyber4.org/kumera/index.html
> 



Iterating on an Iterator?

2001-05-23 Thread Amos Shapira

Hello,

Our object model provides an Iterator interface to walk along
lists (properties of an object or lists of objects).

Does anyone know how can I take advantage of a tag library to
accept an iterator an iterate using Iterator.hasNext() and
Iterator.next()?

Thanks,

--Amos Shapira



RE: How to use the new iterate tag?

2001-05-22 Thread Amos Shapira

Thanks, I just tried this and it works great!

I still wander how should I go about accessing the index in
an "iterate" tag.

Cheers,

--Amos

> -Original Message-
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 22, 2001 11:37 PM
> To: [EMAIL PROTECTED]
> Subject: RE: How to use the new iterate tag?
> 
> 
> You should be using struts-logic.tld, not struts.tld. Never 
> use struts.tld.
> 
> > -----Original Message-
> > From: Amos Shapira [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, May 22, 2001 1:16 PM
> > To: '[EMAIL PROTECTED]'
> > Subject: RE: How to use the new iterate tag?
> > 
> > 
> > I use the TLD extracted from the .jar file, as far as I can
> > tell.
> > 
> > > -Original Message-
> > > From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> > > Sent: Tuesday, May 22, 2001 6:14 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: How to use the new iterate tag?
> > > 
> > > 
> > > Type should be available as an attribute of the iterate tag. 
> > > Which tld are you using? The tld and the documentation are 
> > > generated from the same xml file so they shouldn't be out 
> of sync. 
> > > 
> > > I think the iterate tag exposes the index for use by nested 
> > > custom tags, but I don't know if any tags in struts make use 
> > > of the exposed index. Maybe you have to write your own tag to 
> > > access it?
> > > 
> > > Hal
> > > 
> > > > -Original Message-
> > > > From: Amos Shapira [mailto:[EMAIL PROTECTED]]
> > > > Sent: Tuesday, May 22, 2001 7:19 AM
> > > > To: '[EMAIL PROTECTED]'
> > > > Subject: How to use the new iterate tag?
> > > > 
> > > > 
> > > > Hello,
> > > > 
> > > > I'm using Struts-1.0-b2.
> > > > 
> > > > I'm trying to iterate over an array of objects using the 
> > iterate tag
> > > > as follows:
> > > > 
> > > >  > > >collection = "<%= headers %>"
> > > >type   = "some.class">
> > > > 
> > > > But I get an error like:
> > > > 
> > > > Attribute type invalid according to the specified TLD
> > > > 
> > > > And indeed it looks like the "type" attribute is not specified
> > > > in the TLD, contrary to what the documentation says.
> > > > When I try to drop the "type" attribute I see in the .java class
> > > > that Tomcat defines "header" as a "java.lang.Object" 
> and obviously
> > > > fails later when I access class methods. I also tried to declare
> > > > "header" using "useBean", but I get a "variable already defined"
> > > > error.
> > > > 
> > > > Does anyone know what am I doing wrong?
> > > > 
> > > > Also, I read in the documentation that now the iteration tag
> > > > exposes the current index number, can anyone show me how can
> > > > I access this from a JSP page?  I couldn't find an example in
> > > > the distribution.
> > > > 
> > > > Thanks,
> > > > 
> > > > --Amos Shapira
> > > > 
> > > 
> > 
> 




RE: How to use the new iterate tag?

2001-05-22 Thread Amos Shapira

I use the TLD extracted from the .jar file, as far as I can
tell.

> -Original Message-
> From: Deadman, Hal [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 22, 2001 6:14 PM
> To: [EMAIL PROTECTED]
> Subject: RE: How to use the new iterate tag?
> 
> 
> Type should be available as an attribute of the iterate tag. 
> Which tld are you using? The tld and the documentation are 
> generated from the same xml file so they shouldn't be out of sync. 
> 
> I think the iterate tag exposes the index for use by nested 
> custom tags, but I don't know if any tags in struts make use 
> of the exposed index. Maybe you have to write your own tag to 
> access it?
> 
> Hal
> 
> > -Original Message-
> > From: Amos Shapira [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, May 22, 2001 7:19 AM
> > To: '[EMAIL PROTECTED]'
> > Subject: How to use the new iterate tag?
> > 
> > 
> > Hello,
> > 
> > I'm using Struts-1.0-b2.
> > 
> > I'm trying to iterate over an array of objects using the iterate tag
> > as follows:
> > 
> >  >collection = "<%= headers %>"
> >type   = "some.class">
> > 
> > But I get an error like:
> > 
> > Attribute type invalid according to the specified TLD
> > 
> > And indeed it looks like the "type" attribute is not specified
> > in the TLD, contrary to what the documentation says.
> > When I try to drop the "type" attribute I see in the .java class
> > that Tomcat defines "header" as a "java.lang.Object" and obviously
> > fails later when I access class methods. I also tried to declare
> > "header" using "useBean", but I get a "variable already defined"
> > error.
> > 
> > Does anyone know what am I doing wrong?
> > 
> > Also, I read in the documentation that now the iteration tag
> > exposes the current index number, can anyone show me how can
> > I access this from a JSP page?  I couldn't find an example in
> > the distribution.
> > 
> > Thanks,
> > 
> > --Amos Shapira
> > 
> 



How to use the new iterate tag?

2001-05-22 Thread Amos Shapira

Hello,

I'm using Struts-1.0-b2.

I'm trying to iterate over an array of objects using the iterate tag
as follows:



But I get an error like:

Attribute type invalid according to the specified TLD

And indeed it looks like the "type" attribute is not specified
in the TLD, contrary to what the documentation says.
When I try to drop the "type" attribute I see in the .java class
that Tomcat defines "header" as a "java.lang.Object" and obviously
fails later when I access class methods. I also tried to declare
"header" using "useBean", but I get a "variable already defined"
error.

Does anyone know what am I doing wrong?

Also, I read in the documentation that now the iteration tag
exposes the current index number, can anyone show me how can
I access this from a JSP page?  I couldn't find an example in
the distribution.

Thanks,

--Amos Shapira