Java Doc for StringResourceModel.java in  » J2EE » wicket » org » apache » wicket » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » org.apache.wicket.model 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.wicket.model.AbstractReadOnlyModel
      org.apache.wicket.model.LoadableDetachableModel
         org.apache.wicket.model.StringResourceModel

StringResourceModel
public class StringResourceModel extends LoadableDetachableModel (Code)
This model class encapsulates the full power of localization support within the Wicket framework. It combines the flexible Wicket resource loading mechanism with property expressions, property models and standard Java MessageFormat substitutions. This combination should be able to solve any dynamic localization requirement that a project has.

The model should be created with four parameters, which are described in detail below:

  • resourceKey - This is the most important parameter as it contains the key that should be used to obtain resources from any string resource loaders. This paramater is mandatory: a null value will throw an exception. Typically it will contain an ordinary string such as "label.username". To add extra power to the key functionality the key may also contain a property expression which will be evaluated if the model parameter (see below) is not null. This allows keys to be changed dynamically as the application is running. For example, the key could be "product.${product.id}" which prior to rendering will call model.getObject().getProduct().getId() and substitute this value into the resource key before is is passed to the loader.
  • component - This parameter should be a component that the string resource is relative to. In a simple application this will usually be the Page on which the component resides. For reusable components/containers that are packaged with their own string resource bundles it should be the actual component/container rather than the page. For more information on this please see org.apache.wicket.resource.loader.ComponentStringResourceLoader . The relative component may actually be null when all resource loading is to be done from a global resource loader. However, we recommend that a relative component is still supplied even in these cases in order to 'future proof' your application with regards to changing resource loading strategies.
  • model - This parameter is mandatory if either the resourceKey, the found string resource (see below) or any of the substitution parameters (see below) contain property expressions. Where property expressions are present they will all be evaluated relative to this model object. If there are no property expressions present then this model parameter may be null
  • parameters - The parameters parameter allows an array of objects to be passed for substitution on the found string resource (see below) using a standard java.text.MessageFormat object. Each parameter may be an ordinary Object, in which case it will be processed by the standard formatting rules associated with java.text.MessageFormat. Alternatively, the parameter may be an instance of IModel in which case the getObject() method will be applied prior to the parameter being passed to the java.text.MessageFormat. This allows such features dynamic parameters that are obtained using a PropertyModel object or even nested string resource models.
As well as the supplied parameters, the found string resource can contain formatting information. It may contain property expressions in which case these are evaluated using the model object supplied when the string resource model is created. The string resource may also contain java.text.MessageFormat style markup for replacement of parameters. Where a string resource contains both types of formatting information then the property expression will be applied first.

Example 1

In its simplest form, the model can be used as follows:

 public MyPage extends WebPage 
 {
 public MyPage(final PageParameters parameters) 
 {
 add(new Label("username", new StringResourceModel("label.username", this, null)));
 }
 }
 
Where the resource bundle for the page contains the entry label.username=Username

Example 2

In this example, the resource key is selected based on the evaluation of a property expression:

 public MyPage extends WebPage 
 {
 public MyPage(final PageParameters parameters) 
 {
 WeatherStation ws = new WeatherStation();
 add(new Label("weatherMessage",
 new StringResourceModel("weather.${currentStatus}", this, new Model(ws)));
 }
 }
 
Which will call the WeatherStation.getCurrentStatus() method each time the string resource model is used and where the resource bundle for the page contains the entries:
 weather.sunny=Don't forget sunscreen!
 weather.raining=You might need an umberella
 weather.snowing=Got your skis?
 weather.overcast=Best take a coat to be safe
 

Example 3

In this example the found resource string contains a property expression that is substituted via the model:

 public MyPage extends WebPage 
 {
 public MyPage(final PageParameters parameters) 
 {
 WeatherStation ws = new WeatherStation();
 add(new Label("weatherMessage",
 new StringResourceModel("weather.message", this, new Model(ws)));
 }
 }
 
Where the resource bundle contains the entry weather.message=Weather station reports that the temperature is ${currentTemperature} ${units}

Example 4

In this example, the use of substitution parameters is employed to format a quite complex message string. This is an example of the most complex and powerful use of the string resource model:

 public MyPage extends WebPage 
 {
 public MyPage(final PageParameters parameters) 
 {
 WeatherStation ws = new WeatherStation();
 Model model = new Model(ws);
 add(new Label("weatherMessage",
 new StringResourceModel(
 "weather.detail", this, model,
 new Object[] 
 {
 new Date(),
 new PropertyModel(model, "currentStatus"),
 new PropertyModel(model, "currentTemperature"),
 new PropertyModel(model, "units")
 }));
 }
 }
 
And where the resource bundle entry is:
 weather.detail=The report for {0,date}, shows the temperature as {2,number,###.##} {3} \
 and the weather to be {1}
 

author:
   Chris Turner



Constructor Summary
public  StringResourceModel(String resourceKey, Component component, IModel model)
     Construct.
public  StringResourceModel(String resourceKey, Component component, IModel model, String defaultValue)
     Construct.
public  StringResourceModel(String resourceKey, Component component, IModel model, Object[] parameters)
     Creates a new string resource model using the supplied parameters.

The relative component parameter should generally be supplied, as without it resources can not be obtained from resouce bundles that are held relative to a particular component or page.

public  StringResourceModel(String resourceKey, Component component, IModel model, Object[] parameters, String defaultValue)
     Creates a new string resource model using the supplied parameters.

The relative component parameter should generally be supplied, as without it resources can not be obtained from resouce bundles that are held relative to a particular component or page.


Method Summary
public  LocalizergetLocalizer()
     Gets the localizer that is being used by this string resource model.
protected  Object[]getParameters()
     Gets the Java MessageFormat substitution parameters.
final protected  StringgetResourceKey()
     Gets the resource key for this string resource.
final public  StringgetString()
     Gets the string currently represented by this string resource model.
protected  Objectload()
     Gets the string that this string resource model currently represents.
final protected  voidonDetach()
    
public  voidsetLocalizer(Localizer localizer)
     Sets the localizer that is being used by this string resource model.
public  StringtoString()
     Override of the default method to return the resource string represented by this string resource model.


Constructor Detail
StringResourceModel
public StringResourceModel(String resourceKey, Component component, IModel model)(Code)
Construct.
Parameters:
  resourceKey - The resource key for this string resource
Parameters:
  component - The component that the resource is relative to
Parameters:
  model - The model to use for property substitutions
See Also:   StringResourceModel.StringResourceModel(String,Component,IModel,Object[])



StringResourceModel
public StringResourceModel(String resourceKey, Component component, IModel model, String defaultValue)(Code)
Construct.
Parameters:
  resourceKey - The resource key for this string resource
Parameters:
  component - The component that the resource is relative to
Parameters:
  model - The model to use for property substitutions
Parameters:
  defaultValue - The default value if the resource key is not found.
See Also:   StringResourceModel.StringResourceModel(String,Component,IModel,Object[])



StringResourceModel
public StringResourceModel(String resourceKey, Component component, IModel model, Object[] parameters)(Code)
Creates a new string resource model using the supplied parameters.

The relative component parameter should generally be supplied, as without it resources can not be obtained from resouce bundles that are held relative to a particular component or page. However, for application that use only global resources then this parameter may be null.

The model parameter is also optional and only needs to be supplied if value substitutions are to take place on either the resource key or the actual resource strings.

The parameters parameter is also optional and is used for substitutions.
Parameters:
  resourceKey - The resource key for this string resource
Parameters:
  component - The component that the resource is relative to
Parameters:
  model - The model to use for property substitutions
Parameters:
  parameters - The parameters to substitute using a Java MessageFormat object




StringResourceModel
public StringResourceModel(String resourceKey, Component component, IModel model, Object[] parameters, String defaultValue)(Code)
Creates a new string resource model using the supplied parameters.

The relative component parameter should generally be supplied, as without it resources can not be obtained from resouce bundles that are held relative to a particular component or page. However, for application that use only global resources then this parameter may be null.

The model parameter is also optional and only needs to be supplied if value substitutions are to take place on either the resource key or the actual resource strings.

The parameters parameter is also optional and is used for substitutions.
Parameters:
  resourceKey - The resource key for this string resource
Parameters:
  component - The component that the resource is relative to
Parameters:
  model - The model to use for property substitutions
Parameters:
  parameters - The parameters to substitute using a Java MessageFormat object
Parameters:
  defaultValue - The default value if the resource key is not found.





Method Detail
getLocalizer
public Localizer getLocalizer()(Code)
Gets the localizer that is being used by this string resource model. The localizer



getParameters
protected Object[] getParameters()(Code)
Gets the Java MessageFormat substitution parameters. The substitution parameters



getResourceKey
final protected String getResourceKey()(Code)
Gets the resource key for this string resource. If the resource key contains property expressions and the model is null then the returned value is the actual resource key with all substitutions undertaken. The (possibly substituted) resource key



getString
final public String getString()(Code)
Gets the string currently represented by this string resource model. The string that is returned may vary for each call to this method depending on the values contained in the model and an the parameters that were passed when this string resource model was created. The string



load
protected Object load()(Code)
Gets the string that this string resource model currently represents. The string is returned as an object to allow it to be used generically within components.



onDetach
final protected void onDetach()(Code)
Detaches from the given session



setLocalizer
public void setLocalizer(Localizer localizer)(Code)
Sets the localizer that is being used by this string resource model. This method is provided to allow the default application localizer to be overridden if required.
Parameters:
  localizer - The localizer to use



toString
public String toString()(Code)
Override of the default method to return the resource string represented by this string resource model. Useful in debugging and so on, to avoid the explicit need to call the getString() method. The string for this model object



Methods inherited from org.apache.wicket.model.LoadableDetachableModel
public void detach()(Code)(Java Doc)
public Object getObject()(Code)(Java Doc)
final public boolean isAttached()(Code)(Java Doc)
abstract protected Object load()(Code)(Java Doc)
protected void onAttach()(Code)(Java Doc)
protected void onDetach()(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from org.apache.wicket.model.AbstractReadOnlyModel
public void detach()(Code)(Java Doc)
abstract public Object getObject()(Code)(Java Doc)
final public Object getObject(Component component)(Code)(Java Doc)
final public void setObject(Object object)(Code)(Java Doc)
public String toString()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.