RE: Probable bug with nested:root and tiles context

2004-09-02 Thread Maurice Nicholson
Hi Jimmy,

It's a bug in my opinion. We use Struts 1.1, but it could be fixed in newer
versions (?).

A workaround is to just re-nest the same root context (using the special "/"
syntax), so the root context isn't deleted until you've finished with the
form, ie:


  

 
 

  


in your main layout tile. Then sub-tiles that use nested tags can never
reach the top-level nesting, and therefore, the context isn't deleted
prematurely.

HTH,
Maurice


-Original Message-
From: VAN BROECK Jimmy [mailto:[EMAIL PROTECTED]
Sent: 02 September 2004 14:37
To: [EMAIL PROTECTED]
Subject: Probable bug with nested:root and tiles context


Hi,
 
I think i discovered a bug in the nested:root tag when used in combination
with tiles or even dynamic includes of jsp pages.
 
Let's considere the following scenario :
 
You have a main tile where your nested:form tag is defined and there you
include you tiles through tiles:input
 

 

 

 

 
In the tiles you want to refere to the actionForm bean of your nested:form.
This can be done easily just through  without specifying a
name.
 
tile1:


 


 
Tile2: the same thing as tile1:
 

 


 
 
The problem here is, that in the doEndTag, there is only checked if previous
nesting is null and then to delete the nestedreference from the request.
 
 public int doEndTag() throws JspException {
/* reset the reference */
HttpServletRequest request =
(HttpServletRequest)pageContext.getRequest();
 
if (originalNesting == null) {
  NestedPropertyHelper.deleteReference(request);
} else {
  NestedPropertyHelper.setName(request, originalNestingName);
  NestedPropertyHelper.setProperty(request, "nestOne");
}
this.name = originalName;
 
return (EVAL_PAGE);
}
 
I think the first bug is that the end of a root tag should not check the
originalNesting==null, but the originalNestingName==null, because the
property would always be null?? (You're on the root right??).
 
The second bug or remark, would be that if you didn't specify a bean Name,
you absolutely don't want the nestedReference being deleted, because you are
depending on another reference, declared above this root tag.
 
 
 
Please post your opinions, and if enough people think this is a bug, i will
make a bugzilla report of this.
 
Greetings
jimmy
 

Jimmy Van Broeck 

email:   [EMAIL PROTECTED] 
Consultant 
BT 

CITS 
DE POST - LA POSTE 
ICT-Development 
WTC II - Kantoor 307 
email: [EMAIL PROTECTED] 

 


STRICTLY PERSONAL AND CONFIDENTIAL
This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.

Ce Message est uniquement destiné aux destinataires indiqués et peut
contenir des informations confidentielles. Si vous n'êtes pas le
destinataire, vous ne devez pas révéler le contenu de ce message ou en
prendre copie. Si vous avez reçu ce message par erreur, veuillez en informer
l'expéditeur, ou La Poste immédiatement, avant de le supprimer.

Dit bericht is enkel bestemd voor de aangeduide ontvangers en kan
vertrouwelijke informatie bevatten. Als u niet de ontvanger bent, dan mag u
de inhoud van dit bericht niet bekendmaken noch kopiëren. Als u dit bericht
per vergissing heeft ontvangen, gelieve er de afzender of De Post
onmiddellijk van op de hoogte te brengen en het bericht vervolgens te
verwijderen.


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Using within other nested tags

2004-07-28 Thread Maurice Nicholson
Hi Paul,

yes, it looks like it may have been fixed in 1.2 already:

http://www.mail-archive.com/[EMAIL PROTECTED]/msg22036.html

Thanks,
Maurice


-Original Message-
From: Paul McCulloch [mailto:[EMAIL PROTECTED]
Sent: 27 July 2004 11:35
To: 'Struts Users Mailing List'
Subject: RE: Using  within other nested tags


Hi Maurice,

I've made a similar change to my version of the nested:errors tag as well.
As far as I can tell the nested version of this tag behaves exactly the same
as the normal version. 

Perhaps this is a bug. Have you checked the bug tracking system?

Paul



> -Original Message-----
> From: Maurice Nicholson [mailto:[EMAIL PROTECTED]
> Sent: 19 July 2004 17:32
> To: '[EMAIL PROTECTED]'
> Subject: Using  within other nested tags
> 
> 
> Hi all,
>  
> would someone be able to tell me the correct way to do this, taking
> advantage of the nesting?
>  
> I expected that after adding errors with the same nested 
> property names as
> the nested tags use (eg, "person[0].username"), it might be 
> something like:
>  
> 
> ...
>   
> User name:
>   property="username" />
>   
> ...
> 
>  
> and the nested property for the errors tag would use the same 
> "nesting" as
> the other nested tags (ie, "person[0]" in this case), but not 
> so, at least
> in my version of Struts, circa 1.1.
>  
> I have it working like this now, with a few changes to 
> NestedPropertyHelper
> (see below), but I can't help thinking I've missed the point.
>  
> Thanks in advance,
> Maurice
>  
>  
> =
>  
>  
> Changes to two methods (complete file below):
>  
>   public static void setNestedProperties(HttpServletRequest request,
>  NestedPropertySupport tag) {
> boolean adjustProperty = true;
> /* if the tag implements NestedNameSupport, set the name 
> for the tag
> also */
> if (tag instanceof NestedNameSupport) {
>   NestedNameSupport nameTag = (NestedNameSupport)tag;
>   if (nameTag.getName() == null
>   || Constants.BEAN_KEY.equals(nameTag.getName())
>   || Globals.ERROR_KEY.equals(nameTag.getName())) { 
> // ADDED THIS
> LINE TO SO THAT THE CURRENT NESTING IS PREPENDED TO THE PROPERTY
> nameTag.setName(getCurrentName(request, 
> (NestedNameSupport) tag));
>   } else {
> adjustProperty = false;
>   }
> }
>  
> /* get and set the relative property, adjust if required */
> String property = tag.getProperty();
> if (adjustProperty) {
>   property = getAdjustedProperty(request, property);
> }
> tag.setProperty(property);
>   }
> 
>   public static final String 
> getCurrentName(HttpServletRequest request,
> NestedNameSupport 
> nested) {
>  
> // Error Tag?
> if (nested instanceof NestedErrorsTag) {   // ADDED THESE 
> LINES SO THE
> *ERRORS* BEAN IS USED, RATHER THAN THE BEAN USED BY OTHER NESTED TAGS
>   return Globals.ERROR_KEY;
> }
> 
> // Rest as before
> 
>   }
>  
> =
>  
> Complete file:
>  
> /*
>  * $Header:
> /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/ne
> sted/NestedPro
> pertyHelper.java,v 1.14 2003/04/22 02:28:52 dgraham Exp $
>  * $Revision: 1.14 $
>  * $Date: 2003/04/22 02:28:52 $
>  * 
> 
>  *
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above 
> copyright
>  *notice, this list of conditions and the following disclaimer in
>  *the documentation and/or other materials provided with the
>  *distribution.
>  *
>  * 3. The end-user documentation included with the redistribution, if
>  *any, must include the following acknowlegement:
>  *   "This product includes software developed by the
>  *Apache Software Foundation ( http://www.apache.org/
> <http://www.apache.org/> )."
>  *Alternately, this acknowlegement may appear in the 
> software itself,
>  *if and wherever such third-party acknowlegements 
> normally app

Using within other nested tags

2004-07-19 Thread Maurice Nicholson
eference from the request object.
   * @param request object to remove the reference from
   */
  public static final void deleteReference(HttpServletRequest request) {
// delete the reference
request.removeAttribute(NESTED_INCLUDES_KEY);
  }
 
  /**
   * Helper method that will set all the relevant nesting properties for the
   * provided tag reference depending on the implementation.
   * @param request object to pull references from
   * @param tag to set the nesting values into
   */
  public static void setNestedProperties(HttpServletRequest request,
 NestedPropertySupport tag) {
boolean adjustProperty = true;
/* if the tag implements NestedNameSupport, set the name for the tag
also */
if (tag instanceof NestedNameSupport) {
  NestedNameSupport nameTag = (NestedNameSupport)tag;
  if (nameTag.getName() == null ||
  Constants.BEAN_KEY.equals(nameTag.getName()) ||
  Globals.ERROR_KEY.equals(nameTag.getName())) {
nameTag.setName(getCurrentName(request, (NestedNameSupport) tag));
  } else {
adjustProperty = false;
  }
}
 
/* get and set the relative property, adjust if required */
String property = tag.getProperty();
if (adjustProperty) {
  property = getAdjustedProperty(request, property);
}
tag.setProperty(property);
  }
 

  /**
   * Pulls the current nesting reference from the request object, and if
there
   * isn't one there, then it will create one and set it.
   * @param request object to manipulate the reference into
   * @return current nesting reference as stored in the request object
   */
  private static final NestedReference referenceInstance(HttpServletRequest
request) {
/* get the old one if any */
NestedReference nr = (NestedReference)
request.getAttribute(NESTED_INCLUDES_KEY);
// make a new one if required
if (nr == null) {
  nr = new NestedReference();
  request.setAttribute(NESTED_INCLUDES_KEY, nr);
}
// return the reference
return nr;
  }
 
  /* This property, providing the property to be appended, and the parent
tag
   * to append the property to, will calculate the stepping of the property
   * and return the qualified nested property
   *
   * @param property the property which is to be appended nesting style
   * @param parent the "dot notated" string representing the structure
   * @return qualified nested property that the property param is to the
parent
   */
  private static String calculateRelativeProperty(String property,
  String parent) {
if (parent == null) { parent = ""; }
if (property == null) { property = ""; }
 
/* Special case... reference my parent's nested property.
   Otherwise impossible for things like indexed properties */
if ("./".equals(property) || "this/".equals(property)) {
  return parent;
}
 
/* remove the stepping from the property */
String stepping;
 
/* isolate a parent reference */
if (property.endsWith("/")) {
  stepping = property;
  property = "";
} else {
  stepping = property.substring(0, property.lastIndexOf('/') + 1);
  /* isolate the property */
  property = property.substring(property.lastIndexOf('/') + 1,
property.length());
}
 
if (stepping.startsWith("/")) {
  /* return from root */
  return property;
} else {
  /* tokenize the nested property */
  StringTokenizer proT = new StringTokenizer(parent, ".");
  int propCount = proT.countTokens();
 
  /* tokenize the stepping */
  StringTokenizer strT = new StringTokenizer(stepping, "/");
  int count = strT.countTokens();
 
  if (count >= propCount) {
/* return from root */
return property;
 
  } else {
/* append the tokens up to the token difference */
count = propCount - count;
StringBuffer result = new StringBuffer();
for (int i = 0; i < count; i++) {
  result.append(proT.nextToken());
  result.append('.');
    }
result.append(property);
 
/* parent reference will have a dot on the end. Leave it off */
if (result.charAt(result.length()-1) == '.') {
  return result.substring(0,result.length()-1);
} else {
  return result.toString();
}
  }
}
  }
}

 
 
 
 
Maurice Nicholson
Java Developer
Opodo Limited
Direct Tel +44 (0) 870 099 5153
Fax +44 (0) 870 099 5127
 <http://www.opodo.com/>  <http://www.opodo.com/> www.opodo.com 
 
Opodo - Travel your way  
Flights, Hotels, Cars, Holidays and Insurance 
 <http://www.opodo.de/> www.opodo.de,,  <http://www.opodo.co.uk/>
www.opodo.co.uk and  <http://www.opodo.fr/> www.opodo.fr
The information in this e-mail is