java - Using dynamic Wicket-Resources the right way -
i'm trying create simple application based on wicket. want place panel on page indicates if user logged in. sadly, unable find working example of problem: want label display username if logged on , message, if no user logged on. guess i'm missing something.
here comes code:
panel:
public class header extends panel { imodel<stringresourcemodel> usernamemodel = new loadabledetachablemodel<stringresourcemodel>() { @override protected stringresourcemodel load() { final user user = mysession.get().getauthenticateduser(); if (user==null){ return new stringresourcemodel("username.nouser", header.this , null); }else{ return new stringresourcemodel("username.user", header.this, model.of(user)); } } }; public header(final string id) { super(id); } @override protected void oninitialize() { super.oninitialize(); add(new label("username", usernamemodel)); } }
properties:
username.nouser=you not logged in username.user=welcome, ${name}
markup:
<wicket:panel> <wicket:label class="username" wicket:id="username" /> </wicket:panel>
the rendered text is
stringresourcemodel[key:username.nouser,default:null,params:[]]
the behaviour makes sense. how can fix desired text rendered?
you should return string #load()
method:
imodel<string> usernamemodel = new loadabledetachablemodel<string>() { @override protected string load() { final user user = mysession.get().getauthenticateduser(); if (user==null){ return new stringresourcemodel("username.nouser", header.this , null).getobject(); }else{ return new stringresourcemodel("username.user", header.this, model.of(user)).getobject(); } } };
note call stringresourcemodel#getobject()
.
Comments
Post a Comment