Author: ivaynberg
Date: Fri Aug 17 14:12:41 2007
New Revision: 567146
URL: http://svn.apache.org/viewvc?view=rev&rev=567146
Log:
WICKET-850 localizer fix
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java?view=diff&rev=567146&r1=567145&r2=567146
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
(original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Localizer.java
Fri Aug 17 14:12:41 2007
@@ -179,22 +179,29 @@
{
final IResourceSettings resourceSettings =
Application.get().getResourceSettings();
- if (component.findParent(Page.class) == null)
+ boolean addedToPage = (null !=
component.findParent(Page.class));
+ if (!addedToPage)
{
logger
.warn(
"Tried to retrieve a
localized string for a component that has not yet been added to the page. "
- + "This
can sometimes lead to an invalid localized resource returned. "
+ + "This
can sometimes lead to an invalid or no localized resource returned. "
+ "Make
sure you are not calling Component#getString() inside your Component's
constructor. "
+
"Offeding component: {}", component);
}
- // Check the cache first
- String cacheKey = getCacheKey(key, component);
+ String cacheKey = null;
String string = null;
+ // If this component is not yet added to page we do not want to
check
+ // cache as we can generate an invalid cache key
+ if (addedToPage)
+ {
+ cacheKey = getCacheKey(key, component);
+ }
+
// Value not found are cached as well (value = null)
- if (cache.containsKey(cacheKey))
+ if (cacheKey != null && cache.containsKey(cacheKey))
{
string = getFromCache(cacheKey);
}
@@ -215,7 +222,10 @@
}
// Cache the result incl null if not found
- putIntoCache(cacheKey, string);
+ if (cacheKey != null)
+ {
+ putIntoCache(cacheKey, string);
+ }
}
if ((string == null) && (defaultValue != null))
@@ -260,10 +270,7 @@
*/
protected void putIntoCache(final String cacheKey, final String string)
{
- if (cacheKey != null)
- {
- cache.put(cacheKey, string);
- }
+ cache.put(cacheKey, string);
}
/**