Dealing with transient and persistent objects in Wicket sessions and models

2015-06-18 Thread Urbani, Edmund

Hello all,

this question is not directed solely at Wicket, but extends beyond that to web 
app architecture and best practices.
I have been working mostly with the open-session-in-view pattern and Wicket's 
loadable detachable models backed with Hibernate or similar ORM for my 
applications.


This combination works fairly well until one starts to deal with transient 
objects that may at some point become persistent, and have references to other 
objects that already are persistent in the database. This object graph composed 
of a mix of persistent and transient cannot safely be serialized, nor can 
references to transient objects be removed at detach phase as they would then be 
lost.


These situations usually arise in AJAX or Wizard-style scenarios. I have dealt 
with them in various ways, but have not yet found a way that I am really 
satisfied with:
1) always persist objects (undesirable in many cases as it might require you to 
drop integrity constraints and do additional filtering when fetching objects 
from the database to avoid incomplete instances or additional tables and 
therefore overhead)
2) clear references to persistent objects and store that information elsewhere 
(eg. in the model)
3) avoid setting references to the persistent instances in the transient one to 
begin with (and again store IDs or models of selected persistent objects elsewhere)
4) deviate from open-session-in-view pattern on certain pages (may cause you to 
run out of database connections or force you to deal with database timeouts etc.)


I don't think I am the only one running into these kinds of issues, so I'd like 
to hear which patterns other developers apply or what they consider best practices.


Kind regards,
 Edmund

--

Mit freundlichen Grüßen
Edmund Urbani
Liland IT Team

Email: edmund.urb...@lilandit.com mailto:edmund.urb...@lilandit.com

Liland IT GmbH ...does IT better
Tel: +43 463 220111
Fax: +43 463 220111-33
Tel(GER): +49 221 65028588

Find us at Facebook http://facebook.com/Lilandit
http://green-badges.com
http://iventcloud.com
http://Lilandit.com

http://www.LilandIT.com http://www.LilandIT.com

Copyright © 2015, Liland IT GmbH

Diese Mail enthaelt vertrauliche und/oder rechtlich geschuetzte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese Email irrtuemlich erhalten 
haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. 
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht 
gestattet.


This email may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this email in error) 
please notify the sender immediately and destroy this email. Any unauthorised 
copying, disclosure or distribution of the material in this email is strictly 
forbidden.




Making a datatable more accessible

2015-06-18 Thread Steve Swinsburg
Hi all,

I have a datatable and need to make it more accessible for screenreaders.

I am using an AbstractColumn and setting the getHeader and populateItem
methods with the contents.

In a particular row I want to change the markup of the cells from TD to TH,
as they are header type content. Is this possible in Wicket, to change the
HTML tag? This is generated markup within the DataTable component so I'm
wondering if we can influence the HTML tag that is output.

The second issue is that when using getHeader to set the header cell
contents, it outputs this into a span within the TH, not directly within
the TH itself. I need to add the 'scope=col' ARIA attribute to the TH but
cannot access it (even via getParent()). Again, generated markup.

Thanks for any assistance.

regards,
Steve


Wicket 6 + string resource caching

2015-06-18 Thread Tobias Gierke

Hi,

I'm working on a 'themeable' (does this word exist ?) application were 
some string resources differ based on the currently active user's theme. 
Since (at least during development) each user can freely switch between 
different themes, I need Wicket to not cache these string resources.


I implemented a custom IStringResourceLoader to locate the .properties 
file associated with the current user's UI theme but it seems Wicket is 
caching the String property values and only calls my 
IStringResourceLoader once for every String property.


How can I disable this caching for my IStringResourceLoader ? I suspect 
Wicket thinks of .properties files as static resources so maybe I'm 
stretching the design a bit ;)


Cheers,
Tobias


Currently my WicketApplication class looks like this:

---8--8--8--8--8--8---
getResourceSettings().getStringResourceLoaders().add( new 
UIThemeStringResourceLoader() );

---8--8--8--8--8--8---

...and the the IStringResourceLoader looks like this

---8--8--8--8--8--8---
protected final class UIThemeStringResourceLoader implements 
IStringResourceLoader

{
// cache to avoid reloading properties over and over when not 
in debug mode
private final MapString,CacheEntry properties = new 
HashMap(); // Key is UI theme name, value is properties file


@Override
public String loadStringResource(Class? clazz, String key, 
Locale locale, String style, String variation)

{
return loadStringResource( (Component) null , key  , locale 
,style , variation );

}

@Override
public String loadStringResource(Component component, String 
key, Locale locale, String style, String variation)

{
synchronized( properties )
{
CacheEntry props = properties.get( 
getUITheme().getName() );
if ( props == null || ( isDebugModeEnabled()  
props.isOlderThan( java.time.Duration.ofSeconds( 2 ) ) ) ) // discard 
stale properties when running in debug mode

{
final UserSession session = (UserSession) 
Session.get();
final Locale locale = session.isUserLoggedIn() ? 
session.getCurrentUser().getLocale() : 
applicationSettings.getDefaultLocale();
final String path = 
getUITheme().getStringPropertiesPath( locale );


try ( final InputStream stream = 
getServletContext().getResourceAsStream( path ) )

{
if ( stream == null ) {
return null;
}

final Properties tmp = new Properties();
tmp.load( stream );

props = new CacheEntry( tmp );
properties.put( getUITheme().getName() , props );
}
catch (IOException e) {
LOG.warn(getString(): Failed to load string 
properties for UI theme '+getUITheme().getName()+' from '+path+',e);

}
}
return props.properties.getProperty( key );
}
}
}

--
Tobias Gierke
Development

VOIPFUTURE GmbH   Wendenstraße 4   20097 Hamburg,  Germany
Phone +49 40 688 900 164 Fax +49 40 688 900 199
Email tobias.gie...@voipfuture.com   Web http://www.voipfuture.com
 
CEO Jan Bastian


Commercial Court AG Hamburg   HRB 109896, VAT ID DE263738086



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Custom Url mapping and encoding makes the project fail in deployment mode

2015-06-18 Thread jayeshps
Hello,

I have added certain custom url mapping and rewriting to show the language
tag in the url before mounted pages, which was working really well during
development mode, however in deployment mode, the application does not start
at all. I get an exception: 

Problem accessing /gymwatch/login. Reason:

Server Error

Caused by:

java.lang.NoSuchMethodError:
org.apache.wicket.util.resource.ResourceUtils.getMinifiedName(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
at
org.apache.wicket.request.resource.PackageResourceReference.getMinifiedName(PackageResourceReference.java:220)
at
org.apache.wicket.request.resource.PackageResourceReference.internalGetMinifiedName(PackageResourceReference.java:196)
at
org.apache.wicket.request.resource.PackageResourceReference.getName(PackageResourceReference.java:236)
at
org.apache.wicket.request.resource.PackageResourceReference.getUrlAttributes(PackageResourceReference.java:162)
at
org.apache.wicket.request.resource.PackageResourceReference.getUrlAttributes(PackageResourceReference.java:266)
at
org.apache.wicket.core.request.mapper.AbstractResourceReferenceMapper.encodeResourceReferenceAttributes(AbstractResourceReferenceMapper.java:162)
at
org.apache.wicket.core.request.mapper.BasicResourceReferenceMapper.mapHandler(BasicResourceReferenceMapper.java:215)
at
org.apache.wicket.request.mapper.ParentPathReferenceRewriter.mapHandler(ParentPathReferenceRewriter.java:91)
at
org.apache.wicket.request.mapper.CompoundRequestMapper.mapHandler(CompoundRequestMapper.java:215)
at
org.apache.wicket.protocol.https.HttpsMapper.mapHandler(HttpsMapper.java:174)
at
org.apache.wicket.protocol.https.HttpsMapper.mapHandler(HttpsMapper.java:122)
at
org.apache.wicket.request.mapper.CompoundRequestMapper.mapHandler(CompoundRequestMapper.java:215)
at
org.apache.wicket.request.cycle.RequestCycle.mapUrlFor(RequestCycle.java:429)
at
org.apache.wicket.request.cycle.RequestCycle.urlFor(RequestCycle.java:529)
at
org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem.getUrl(JavaScriptReferenceHeaderItem.java:138)
at
org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem.getRenderTokens(JavaScriptReferenceHeaderItem.java:121)
at
org.apache.wicket.markup.head.internal.HeaderResponse.wasItemRendered(HeaderResponse.java:61)
at
org.apache.wicket.markup.head.internal.HeaderResponse.render(HeaderResponse.java:52)
at
org.apache.wicket.markup.head.ResourceAggregator.renderHeaderItems(ResourceAggregator.java:311)
at
org.apache.wicket.markup.head.ResourceAggregator.close(ResourceAggregator.java:280)
at
org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:175)
at
org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
at 
org.apache.wicket.Component.internalRenderComponent(Component.java:2536)
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
at org.apache.wicket.Component.internalRender(Component.java:2366)
at org.apache.wicket.Component.render(Component.java:2294)
at 
org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
at 
org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
at org.apache.wicket.Page.onRender(Page.java:887)
at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:142)
at org.apache.wicket.Component.internalRender(Component.java:2366)
at org.apache.wicket.Component.render(Component.java:2294)
at org.apache.wicket.Page.renderPage(Page.java:1024)
at
org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:139)
at
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:284)
at
org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
at
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:890)
at
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261)
at
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
at
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
at
org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
at
org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282)
at
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at

Re: Dealing with transient and persistent objects in Wicket sessions and models

2015-06-18 Thread wix
Urbani, Edmund wrote
 I don't think I am the only one running into these kinds of issues, so I'd
 like 
 to hear which patterns other developers apply or what they consider best
 practices.

 Would like to hear the same. I've attempted to work through this in the
most Wicket-way I know how.

 The approach so far is a kind of LoadableDetachableModel that tries to be
smart about the persistent state of the underlying entity/object. A
persistence provider (entitymanager or such) would be injected into the
model or requested by the model, and a flag or flags used to track the state
of the underlying entity - is the entity currently managed? is the entity to
be retained (that is, not automatically detached)? is the entity currently
attached?

 So at the start of a wizard, the model is given a new entity and told that
it is un-managed and retained. As the model is passed to the next page or to
a previous page, the entity is serialized (not detached) and treated as
though it doesn't belong to a persistence context. At the end of the wizard
the model is told to persist the entity at which time it becomes managed but
not retained (so it detaches, and would be re-attached via persistence id
lookup when the model is next deserialized/loaded).

 A wizard or other set of pages working with an existing entity that was
selected from persistence just tells the model that it is managed and
retained. Then the model still doesn't detach in the sense of setting the
underlying entity to null, but it does detach from the JPA context and is
safely(?) serialized. Thereby changes made in wizard pages ride along to the
end as in the new entity case above, and aren't merged til whatever final
page/part logic says so. Cancelling out in the middle is simple since no
changed would have been persisted.

 It works for any generic entity in my projects so far, however my use case
right now isn't complicated by multi-entity editing; only one entity (one
model's underlying object) is being modified by a single form submission in
the open-session-in-view cycle.

 If there are other drawbacks to this approach or a better way (a more
Wicket-way)...


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Dealing-with-transient-and-persistent-objects-in-Wicket-sessions-and-models-tp4671222p4671240.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Making a datatable more accessible

2015-06-18 Thread Sven Meier

Hi,

it's a little bit finicky, but it can be done:

DataTable dataTable = new DefaultDataTableContact, 
String(table, columns, new SortableContactDataProvider(), 8) {
protected ItemIColumnContact, String newCellItem(final 
String id, final int index, final IModelIColumnContact, String model)

{
return new ItemIColumnContact, String(id, 
index, model) {

@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);

// parent is the repeater for the cells, 
its parent is the row
Contact contact = (Contact) 
getParent().getParent().getDefaultModelObject();

if (contact.isSpecíal()) {
tag.setName(th);
}
}
};
}
};

In a future version we might want to change #newCellItem() to get a 
reference to the row's model - that would remove the need to lookup the 
row object from the  grandparent.


Have fun
Sven


On 18.06.2015 14:15, Steve Swinsburg wrote:

Hi all,

I have a datatable and need to make it more accessible for screenreaders.

I am using an AbstractColumn and setting the getHeader and populateItem
methods with the contents.

In a particular row I want to change the markup of the cells from TD to TH,
as they are header type content. Is this possible in Wicket, to change the
HTML tag? This is generated markup within the DataTable component so I'm
wondering if we can influence the HTML tag that is output.

The second issue is that when using getHeader to set the header cell
contents, it outputs this into a span within the TH, not directly within
the TH itself. I need to add the 'scope=col' ARIA attribute to the TH but
cannot access it (even via getParent()). Again, generated markup.

Thanks for any assistance.

regards,
Steve




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 6 + string resource caching

2015-06-18 Thread Sven Meier

Hi,

Wicket includes the session's style when generating the cache key*. Why 
don't you use this to identify your current 'theme'? Then theme-specific 
string resources should work out-of-the-box.


Have fun
Sven

*See Localizer#getCacheKey()


On 18.06.2015 16:39, Tobias Gierke wrote:

Hi,

I'm working on a 'themeable' (does this word exist ?) application were 
some string resources differ based on the currently active user's 
theme. Since (at least during development) each user can freely switch 
between different themes, I need Wicket to not cache these string 
resources.


I implemented a custom IStringResourceLoader to locate the .properties 
file associated with the current user's UI theme but it seems Wicket 
is caching the String property values and only calls my 
IStringResourceLoader once for every String property.


How can I disable this caching for my IStringResourceLoader ? I 
suspect Wicket thinks of .properties files as static resources so 
maybe I'm stretching the design a bit ;)


Cheers,
Tobias


Currently my WicketApplication class looks like this:

---8--8--8--8--8--8---
getResourceSettings().getStringResourceLoaders().add( new 
UIThemeStringResourceLoader() );

---8--8--8--8--8--8---

...and the the IStringResourceLoader looks like this

---8--8--8--8--8--8---
protected final class UIThemeStringResourceLoader implements 
IStringResourceLoader

{
// cache to avoid reloading properties over and over when not 
in debug mode
private final MapString,CacheEntry properties = new 
HashMap(); // Key is UI theme name, value is properties file


@Override
public String loadStringResource(Class? clazz, String key, 
Locale locale, String style, String variation)

{
return loadStringResource( (Component) null , key  , 
locale ,style , variation );

}

@Override
public String loadStringResource(Component component, String 
key, Locale locale, String style, String variation)

{
synchronized( properties )
{
CacheEntry props = properties.get( 
getUITheme().getName() );
if ( props == null || ( isDebugModeEnabled()  
props.isOlderThan( java.time.Duration.ofSeconds( 2 ) ) ) ) // discard 
stale properties when running in debug mode

{
final UserSession session = (UserSession) 
Session.get();
final Locale locale = session.isUserLoggedIn() ? 
session.getCurrentUser().getLocale() : 
applicationSettings.getDefaultLocale();
final String path = 
getUITheme().getStringPropertiesPath( locale );


try ( final InputStream stream = 
getServletContext().getResourceAsStream( path ) )

{
if ( stream == null ) {
return null;
}

final Properties tmp = new Properties();
tmp.load( stream );

props = new CacheEntry( tmp );
properties.put( getUITheme().getName() , props );
}
catch (IOException e) {
LOG.warn(getString(): Failed to load string 
properties for UI theme '+getUITheme().getName()+' from '+path+',e);

}
}
return props.properties.getProperty( key );
}
}
}




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Custom Url mapping and encoding makes the project fail in deployment mode

2015-06-18 Thread Martin Grigorov
Hi,

It looks like a build problem. Maybe you have an older version of
wicket-core.jar in your classpath in production.
The method is definitely there [1]

1.
https://github.com/apache/wicket/blob/edcbd4e849378a5aba9ee2d5e4f954bce904af52/wicket-util/src/main/java/org/apache/wicket/util/resource/ResourceUtils.java#L55

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Jun 18, 2015 at 7:50 PM, jayeshps jayeshpsars...@gmail.com wrote:

 Hello,

 I have added certain custom url mapping and rewriting to show the language
 tag in the url before mounted pages, which was working really well during
 development mode, however in deployment mode, the application does not
 start
 at all. I get an exception:

 Problem accessing /gymwatch/login. Reason:

 Server Error

 Caused by:

 java.lang.NoSuchMethodError:

 org.apache.wicket.util.resource.ResourceUtils.getMinifiedName(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 at

 org.apache.wicket.request.resource.PackageResourceReference.getMinifiedName(PackageResourceReference.java:220)
 at

 org.apache.wicket.request.resource.PackageResourceReference.internalGetMinifiedName(PackageResourceReference.java:196)
 at

 org.apache.wicket.request.resource.PackageResourceReference.getName(PackageResourceReference.java:236)
 at

 org.apache.wicket.request.resource.PackageResourceReference.getUrlAttributes(PackageResourceReference.java:162)
 at

 org.apache.wicket.request.resource.PackageResourceReference.getUrlAttributes(PackageResourceReference.java:266)
 at

 org.apache.wicket.core.request.mapper.AbstractResourceReferenceMapper.encodeResourceReferenceAttributes(AbstractResourceReferenceMapper.java:162)
 at

 org.apache.wicket.core.request.mapper.BasicResourceReferenceMapper.mapHandler(BasicResourceReferenceMapper.java:215)
 at

 org.apache.wicket.request.mapper.ParentPathReferenceRewriter.mapHandler(ParentPathReferenceRewriter.java:91)
 at

 org.apache.wicket.request.mapper.CompoundRequestMapper.mapHandler(CompoundRequestMapper.java:215)
 at

 org.apache.wicket.protocol.https.HttpsMapper.mapHandler(HttpsMapper.java:174)
 at

 org.apache.wicket.protocol.https.HttpsMapper.mapHandler(HttpsMapper.java:122)
 at

 org.apache.wicket.request.mapper.CompoundRequestMapper.mapHandler(CompoundRequestMapper.java:215)
 at

 org.apache.wicket.request.cycle.RequestCycle.mapUrlFor(RequestCycle.java:429)
 at
 org.apache.wicket.request.cycle.RequestCycle.urlFor(RequestCycle.java:529)
 at

 org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem.getUrl(JavaScriptReferenceHeaderItem.java:138)
 at

 org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem.getRenderTokens(JavaScriptReferenceHeaderItem.java:121)
 at

 org.apache.wicket.markup.head.internal.HeaderResponse.wasItemRendered(HeaderResponse.java:61)
 at

 org.apache.wicket.markup.head.internal.HeaderResponse.render(HeaderResponse.java:52)
 at

 org.apache.wicket.markup.head.ResourceAggregator.renderHeaderItems(ResourceAggregator.java:311)
 at

 org.apache.wicket.markup.head.ResourceAggregator.close(ResourceAggregator.java:280)
 at

 org.apache.wicket.markup.html.internal.HtmlHeaderContainer.onComponentTagBody(HtmlHeaderContainer.java:175)
 at

 org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
 at
 org.apache.wicket.Component.internalRenderComponent(Component.java:2536)
 at
 org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1496)
 at org.apache.wicket.Component.internalRender(Component.java:2366)
 at org.apache.wicket.Component.render(Component.java:2294)
 at
 org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1392)
 at
 org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1557)
 at org.apache.wicket.Page.onRender(Page.java:887)
 at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:142)
 at org.apache.wicket.Component.internalRender(Component.java:2366)
 at org.apache.wicket.Component.render(Component.java:2294)
 at org.apache.wicket.Page.renderPage(Page.java:1024)
 at

 org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:139)
 at

 org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:284)
 at

 org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
 at

 org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:890)
 at

 org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
 at
 

Re: Wicket 6 + string resource caching

2015-06-18 Thread Martin Grigorov
Also see Localizer#clearCache() [1]
When changing the theme use getApplication().getLocalizer().clearCache()

1.
https://github.com/apache/wicket/blob/edcbd4e849378a5aba9ee2d5e4f954bce904af52/wicket-core/src/main/java/org/apache/wicket/Localizer.java#L90

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Jun 18, 2015 at 9:14 PM, Sven Meier s...@meiers.net wrote:

 Hi,

 Wicket includes the session's style when generating the cache key*. Why
 don't you use this to identify your current 'theme'? Then theme-specific
 string resources should work out-of-the-box.

 Have fun
 Sven

 *See Localizer#getCacheKey()



 On 18.06.2015 16:39, Tobias Gierke wrote:

 Hi,

 I'm working on a 'themeable' (does this word exist ?) application were
 some string resources differ based on the currently active user's theme.
 Since (at least during development) each user can freely switch between
 different themes, I need Wicket to not cache these string resources.

 I implemented a custom IStringResourceLoader to locate the .properties
 file associated with the current user's UI theme but it seems Wicket is
 caching the String property values and only calls my IStringResourceLoader
 once for every String property.

 How can I disable this caching for my IStringResourceLoader ? I suspect
 Wicket thinks of .properties files as static resources so maybe I'm
 stretching the design a bit ;)

 Cheers,
 Tobias


 Currently my WicketApplication class looks like this:

 ---8--8--8--8--8--8---
 getResourceSettings().getStringResourceLoaders().add( new
 UIThemeStringResourceLoader() );
 ---8--8--8--8--8--8---

 ...and the the IStringResourceLoader looks like this

 ---8--8--8--8--8--8---
 protected final class UIThemeStringResourceLoader implements
 IStringResourceLoader
 {
 // cache to avoid reloading properties over and over when not in
 debug mode
 private final MapString,CacheEntry properties = new
 HashMap(); // Key is UI theme name, value is properties file

 @Override
 public String loadStringResource(Class? clazz, String key,
 Locale locale, String style, String variation)
 {
 return loadStringResource( (Component) null , key  , locale
 ,style , variation );
 }

 @Override
 public String loadStringResource(Component component, String key,
 Locale locale, String style, String variation)
 {
 synchronized( properties )
 {
 CacheEntry props = properties.get( getUITheme().getName()
 );
 if ( props == null || ( isDebugModeEnabled() 
 props.isOlderThan( java.time.Duration.ofSeconds( 2 ) ) ) ) // discard stale
 properties when running in debug mode
 {
 final UserSession session = (UserSession)
 Session.get();
 final Locale locale = session.isUserLoggedIn() ?
 session.getCurrentUser().getLocale() :
 applicationSettings.getDefaultLocale();
 final String path =
 getUITheme().getStringPropertiesPath( locale );

 try ( final InputStream stream =
 getServletContext().getResourceAsStream( path ) )
 {
 if ( stream == null ) {
 return null;
 }

 final Properties tmp = new Properties();
 tmp.load( stream );

 props = new CacheEntry( tmp );
 properties.put( getUITheme().getName() , props );
 }
 catch (IOException e) {
 LOG.warn(getString(): Failed to load string
 properties for UI theme '+getUITheme().getName()+' from '+path+',e);
 }
 }
 return props.properties.getProperty( key );
 }
 }
 }



 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org