Generating Custom Resource Bundle Entries

In JHeadstart jspx pages, you can reference entries in the JHeadstart resource bundle (usually called ApplicationResources.properties), using the EL expression #{nls['KEY']}, where KEY is the key of the desired resource bundle entry.

Manually adding your own message

If you want to add your own message, you can of course write an entry in the resource bundle:

CONFIRM_DELETE=Are you sure you want to delete this row?

Then you can use this message in your JSF page by specifying:

#{nls['CONFIRM_DELETE']}

Generating the message into the page

The next level is to include this EL expression in a custom Generator Template. For example when adding a warning message to a delete button, which is also described in Lucas Jellema's post Generate 'Delete with Confirmation' in JHeadstart applications.

In the Velocity Generator Template for your custom Delete Button you could use something like:

onclick="return confirm('#{nls['CONFIRM_DELETE']}');"

That way you can generate the page, but you would still have to add the message manually to the ApplicationResources.properties file.

Generating the message into the Resource Bundle

One step further is to use the JHeadstart routine JHS.nls in your Velocity template. This method in the JhsVelocityContext class (see the JDeveloper Help menu, JHeadstart Documentation Index, Javadoc of the JHeadstart Application Generator) has many overloaded variations. The simplest takes two String arguments:

nls(java.lang.String s, java.lang.String key)

It creates a resource bundle entry KEY=s, and returns #{nls['KEY']}. In the delete warning example you would put in the generator template:

onclick="return confirm('${JHS.nls("Are you sure you want to delete this row?", "CONFIRM_DELETE")}');"

And it would create a resource bundle entry

CONFIRM_DELETE=Are you sure you want to delete this row?

You can make it more specific for each group while keeping it generic, by changing it to (suggested by Aino Andriessen):

onclick="return confirm('${JHS.nls("Are you sure you want to delete this ${JHS.current.group.displayTitleSingular}?", "${JHS.current.group.name}_CONFIRM_DELETE")}');"

This will result in (example for the Customers group):

onclick="return confirm('#{nls['CUSTOMERS_CONFIRM_DELETE']}');"
                   
and a resource bundle entry

CUSTOMERS_CONFIRM_DELETE=Are you sure you want to delete this Customer?

When the user clicks the Delete button, (s)he will see this:

Delete Warning: Javascript popup dialog to let the user confirm the delete<br>

Comments:

Hello Sandra, I have been trying to use the NLS enabled template that are depicted in your blog. But compilation errors were raised from the following code : onclick="return confirm('${JHS.nls("Are you sure you want to delete this row?", "CONFIRM_DELETE")}');" errors: Error(72,77): Whitespace required. Error(72,105): '=' missing in attribute. Error(72,30): Attribute value should start with quote. Please Advise!!

Posted by Hala on December 04, 2006 at 04:27 PM PST #

Hello Hala,

You get these errors if you include the code
onclick="return confirm('${JHS.nls("Are you sure you want to delete this row?", "CONFIRM_DELETE")}');"
directly in your .jspx page.
You should include it in a JHeadstart Generator Template, a Velocity .vm file, and then generate the .jspx page using this template. For example, try it out in the file ViewController/templates/default/button/DeleteButton.vm.
To preserve customizations when upgrading to a higher JHeadstart release, you should create a custom copy of that template, and specify the path to that template in the Application Definition file. See the "JHeadstart Developer's Guide", chapter 3, section Customizing Page Layout, for more information.

Hope this helps,

Posted by Sandra Muller on December 04, 2006 at 05:13 PM PST #

Thank You Sandra !! It worked!!

Posted by Hala on December 04, 2006 at 09:07 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Java EE Consultants - JHeadstart, ADF, JSF

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today