You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Frank Nestel <do...@bigfoot.com> on 2000/06/25 21:07:54 UTC
Mixed Pickles
Hi,
I'm having a hard time keeping up with you. Currently I
try to get my two weeks old first test case up again. I found
varous minor thingies:
* I DO CARE ABOUT JDK 1.1 compatibility. I'm developing under
OS/2!! OS2 IBM JDK 1.3 is scheduled for end of June, but
supposed to contain minor problems for servlets ... Concerning the
new container classes, there is this jdk12.jar from sun which
contains versions of the container classes for jdk1.1. I
wouldn't object to a 1.2 version as long as this archive
allows me to run struts under jdk1.1.x.
* Documentation: "redirect" is not described, but somehow "link"
is twice, I guess this belongs in the cathegory cut-and-paste :-)
* In the cute little ErrorMessages Class I find the snippet
String array[] = new String[errors.size()];
for (int i = 0; i < array.length; i++)
array[i] = (String) errors.elementAt(i);
having written similar things as
String array[] = new String[errors.size()];
errors.copyInto(array);
quite often. Are there any objections to the latter way
to do it. I thought it is shorter and probably slightly
more efficient?!
The only thing I dislike with those ErrorMessages are their
name, since they present a general way to collect strings
and I can imagine other userful applications. Maybe there
should als be a means to obtain single message strings and
not the complete array
public String getError(int i)
{
return errors.ElementAt(i);
}
* Trying to start the demo under resin1.1x works, until I try
to edit a subscription, then I get
/struts/subscription.jsp:43: Nicht definierte Variable oder nicht
definierter Klassenname: user
out.print(user.getUsername());
which is German and says, that the classname user is not
defined.
* I still vote for a modified MessageResources with an additional
instance variable
private boolean returnNulls = true;
which can be set to false from extern and a global application
setting which allows me to set that flag for all resources in the
application. This flag should be used in getMessage();
public String getMessage(Locale locale, String key, Object args[])
{
// Cache MessageFormat instances as they are accessed
MessageFormat format = null;
String messageKey = getResourceKey(locale, key);
synchronized (formats)
{
format = (MessageFormat) formats.get(messageKey);
if (format == null)
{
String formatString = (String) getResource(locale, key);
if (formatString == null)
{
if ( returnsNull )
return null;
else
return "??? "+messageKey;
}
format = new MessageFormat(formatString);
formats.put(messageKey, format);
}
}
return (format.format(args));
}
Setting returnsNull = false would make debugging of text resources
easier IMHO and also allow to create new messages on the fly while
coding
without having to worry to stop the whole application from working
later on.
In fact it could even be a NTH debug feature, to set the application
that it
only returns the messageKeys (and not the message)...
An alternative approach to obtain above debug information might be the
class below. If your application uses resources
ApplicationResources_en.properties
ApplicationResources_de.properties
...
do NOT provide a ApplicationResources.properties, but provide a class
ApplicationResources.class from
public class ApplicationResources
extends EmptyApplicationResources
{
}
with a helper class that returns a String resource for any key:
import java.util.*;
public class EmptyApplicationResources
extends ResourceBundle
{
public Enumeration getKeys() { return null; }
protected Object handleGetObject(String key)
{
return "???["+key+"]";
}
}
maybe the latter class is a candidate for com.apache.struts.util ???
OK, I guess this is long enough for a posting, though my test case is
still
not running again :-)
Frank
Re: Mixed Pickles
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Frank Nestel wrote:
> Hi,
>
> I'm having a hard time keeping up with you. Currently I
> try to get my two weeks old first test case up again. I found
> varous minor thingies:
>
> * I DO CARE ABOUT JDK 1.1 compatibility. I'm developing under
> OS/2!! OS2 IBM JDK 1.3 is scheduled for end of June, but
> supposed to contain minor problems for servlets ... Concerning the
> new container classes, there is this jdk12.jar from sun which
> contains versions of the container classes for jdk1.1. I
> wouldn't object to a 1.2 version as long as this archive
> allows me to run struts under jdk1.1.x.
>
For now, I'm trying to create 1.1-compatible versions of tags that use
Java2
features, and avoiding Java2-isms in the underlying framework.
Last time I looked, the collection classes download used a different
package
name, so these classes would be required even for Java2 platform users.
>
> * Documentation: "redirect" is not described, but somehow "link"
> is twice, I guess this belongs in the cathegory cut-and-paste :-)
Yep. :-)
>
> * In the cute little ErrorMessages Class I find the snippet
>
> String array[] = new String[errors.size()];
> for (int i = 0; i < array.length; i++)
> array[i] = (String) errors.elementAt(i);
>
> having written similar things as
>
> String array[] = new String[errors.size()];
> errors.copyInto(array);
>
> quite often. Are there any objections to the latter way
> to do it. I thought it is shorter and probably slightly
> more efficient?!
No matter how many lines of code you write, there's always something new
to
learn .... Thanks -- I had never thought to see if Vector could do this.
>
> The only thing I dislike with those ErrorMessages are their
> name, since they present a general way to collect strings
> and I can imagine other userful applications. Maybe there
> should als be a means to obtain single message strings and
> not the complete array
>
> public String getError(int i)
> {
> return errors.ElementAt(i);
> }
>
Just added this one.
>
> * Trying to start the demo under resin1.1x works, until I try
> to edit a subscription, then I get
>
> /struts/subscription.jsp:43: Nicht definierte Variable oder nicht
> definierter Klassenname: user
> out.print(user.getUsername());
>
> which is German and says, that the classname user is not
> defined.
>
I think that is due to a problem I fixed in an earlier commit today.
Please
try tonight's nightly build (it will be dated 20000630) and all of the
known
bugs should have been whacked.
>
> * I still vote for a modified MessageResources with an additional
> instance variable
>
> private boolean returnNulls = true;
>
> which can be set to false from extern and a global application
> setting which allows me to set that flag for all resources in the
> application. This flag should be used in getMessage();
>
> public String getMessage(Locale locale, String key, Object args[])
> {
> // Cache MessageFormat instances as they are accessed
> MessageFormat format = null;
> String messageKey = getResourceKey(locale, key);
> synchronized (formats)
> {
> format = (MessageFormat) formats.get(messageKey);
> if (format == null)
> {
> String formatString = (String) getResource(locale, key);
> if (formatString == null)
> {
> if ( returnsNull )
> return null;
> else
> return "??? "+messageKey;
> }
> format = new MessageFormat(formatString);
> formats.put(messageKey, format);
> }
> }
> return (format.format(args));
> }
>
> Setting returnsNull = false would make debugging of text resources
> easier IMHO and also allow to create new messages on the fly while
> coding
> without having to worry to stop the whole application from working
> later on.
> In fact it could even be a NTH debug feature, to set the application
> that it
> only returns the messageKeys (and not the message)...
>
Added this pretty much the way you proposed it. The controller servlet
has a
new initialization parameter "null" that you can use to set the
returnNull
property for the application resources object that it loads.
>
> An alternative approach to obtain above debug information might be the
> class below. If your application uses resources
>
> ApplicationResources_en.properties
> ApplicationResources_de.properties
> ...
> do NOT provide a ApplicationResources.properties, but provide a class
> ApplicationResources.class from
>
> public class ApplicationResources
> extends EmptyApplicationResources
> {
> }
>
> with a helper class that returns a String resource for any key:
>
> import java.util.*;
>
> public class EmptyApplicationResources
> extends ResourceBundle
> {
> public Enumeration getKeys() { return null; }
>
> protected Object handleGetObject(String key)
> {
> return "???["+key+"]";
> }
> }
>
> maybe the latter class is a candidate for com.apache.struts.util ???
>
> OK, I guess this is long enough for a posting, though my test case is
> still
> not running again :-)
>
> Frank