DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Avatar

A. Programmer

Developer at freelancer

London, GB

Joined Mar 2011

Stats

Reputation: 0
Pageviews: 902.9K
Articles: 5
Comments: 5
  • Articles
  • Comments

Articles

article thumbnail
Allowing Duplicate Keys in Java Collections
Java Collections allows you to add one or more elements with the same key by using the MultiValueMap class, found in the Apache org.apache.commons.collections package (http://commons.apache.org/collections/): package multihashmap.example; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.collections.map.MultiValueMap; public class MultiHashMapExample { public static void main(String[] args) { List list; MultiValueMap map = new MultiValueMap(); map.put("A", 4); map.put("A", 6); map.put("B", 7); map.put("C", 1); map.put("B", 9); map.put("A", 5); Set entrySet = map.entrySet(); Iterator it = entrySet.iterator(); System.out.println(" Object key Object value"); while (it.hasNext()) { Map.Entry mapEntry = (Map.Entry) it.next(); list = (List) map.get(mapEntry.getKey()); for (int j = 0; j < list.size(); j++) { System.out.println("\t" + mapEntry.getKey() + "\t " + list.get(j)); } } } } Since Java Core does’t come with some solutions for supporting multiple keys, using the org.apache.commons.collections seems to be a proper way to deal with multiple keys. And the output is: From http://e-blog-java.blogspot.com/2012/02/how-to-allow-duplicate-key-in-java.html
March 3, 2012
· 99,325 Views · 5 Likes
article thumbnail
How to Customize the Growl PrimeFaces Component
I believe that every JSF fan has heard about PrimeFaces, the open source component suite for Java Server Faces (PrimeFaces). From my point of view, it is a real pleasure to explore PrimeFaces components and to get play with their capabilities. Recently, I had to use a customized growl component, meaning that I needed to make it appear in different locations and changing it’s aspect. Let me share this experience with you! The final result (after customization) is shown in the below image: - Replacing the default info icon with a custom image can be accomplished by using the infoIcon attribute of component: - In addition, you can customize the image’s CSS properties, like width and height, by modifying the CSS class ui-growl-image: .ui-growl-image { width: 100px; height: 95px; float: left; } - By default, the growl’s message will be displayed for 6000 ms and after that will be hidden. You can change this period by setting the sticky attribute to true (the message will never get hide) or changing the duration in the life attribute. - The growl background it is also customizable through CSS. This time operate over ui-growl-item-container class: .ui-growl-item-container { background-image: url('./imgs/background.jpg'); } - The growl closing icon is set by default in the top left corner. If you want it to appear in a different place, like top right corner, you need to modify the CSS ui-growl-icon-close class: .ui-growl-icon-close { cursor: pointer; position: absolute; left: 335px; top: 15px; } - You can also change the font and style of the summary and the detail message, like below: .ui-growl-title { font: 28px "Lucida Console", Monaco, monospace; text-align: center; } .ui-growl-message p { font: 20px "Lucida Console", Monaco, monospace; letter-spacing: -1px; } - Finally, you can place the growl anywhere you want, top left, bottom left, bottom right, center and so on by ui-growl class: .ui-growl { position:fixed; top: 40%; left: 37%; width: 360px; height: 110px; z-index:9999; } That’s it ! Hope you like it! From http://e-blog-java.blogspot.com/2011/07/how-to-customize-growl-primefaces.html
July 25, 2011
· 56,085 Views · 3 Likes
article thumbnail
The built-in qualifiers @Default and @Any
• @Default - Whenever a bean or injection point does not explicitly declare a qualifier, the container assumes the qualifier @Default. • @Any – When you need to declare an injection point without specifying a qualifier, is useful to know that all beans have the @Any qualifier. This qualifier “belongs” to all beans and injection points (not applicable when @New is present) and when is explicitly specified you suppress the @Default qualifier. This is useful if you want to iterate over all beans with a certain bean type. The example presented in this post will prove how @Any qualifier works in a useful example. You will try to iterate over all beans with a certain bean type. For start, you define a new Java type, like below – a simple interface representing a Wilson tennis racquet type: package com.racquets; public interface WilsonType { public String getWilsonRacquetType(); } Now, three Wilson racquets will implement this interface – notice that no qualifier was specified: package com.racquets; public class Wilson339Racquet implements WilsonType{ @Override public String getWilsonRacquetType() { return ("Wilson BLX Six.One Tour 90 (339 gr)"); } } package com.racquets; public class Wilson319Racquet implements WilsonType { @Override public String getWilsonRacquetType() { return ("Wilson BLX Six.One Tour 90 (319 gr)"); } } package com.racquets; public class Wilson96Racquet implements WilsonType { @Override public String getWilsonRacquetType() { return ("Wilson BLX Pro Tour 96"); } } Next, you can use the @Any qualifier at injection point to iterate over all beans of type WilsonRacquet. An instance of each implementation is injected and the result of getWilsonRacquetType method is stored in an ArrayList: package com.racquets; import java.util.ArrayList; import javax.enterprise.context.RequestScoped; import javax.enterprise.inject.Any; import javax.enterprise.inject.Instance; import javax.enterprise.inject.Produces; import javax.inject.Inject; import javax.inject.Named; @RequestScoped public class WilsonRacquetBean { private @Named @Produces ArrayList wilsons = new ArrayList(); @Inject void initWilsonRacquets(@Any Instance racquets) { for (WilsonType racquet : racquets) { wilsons.add(racquet.getWilsonRacquetType()); } } } From a JSF page, you can easily iterate over the ArrayList (notice here that the wilsons collection was annotated with @Named (allows JSF to have access to this field) and @Produces (as a simple explanation, a producer field suppress the getter method)): The built-in qualifiers @Default and @Any The output is in figure below: From http://e-blog-java.blogspot.com/2011/04/built-in-qualifiers-default-and-any.html
April 21, 2011
· 8,291 Views
article thumbnail
How to integrate JavaScript and JSF
JSF and JavaScript can combine forces to develop powerful applications. For example, let's see how we can use JavaScript code with h:commandLink and h:commandButton to obtain a confirmation before getting into action. Getting ready We have developed this recipe with NetBeans 6.8, JSF 2.0, and GlassFish v3. The JSF 2.0 classes were obtained from the NetBeans JSF 2.0 bundled library. How to do it... As you know the h:commandLink takes an action after a link is clicked (on the mouse click event), while h:commandButton does the same thing, but renders a button, instead of a text link. In this case, we place a JavaScript confirmation box before the action starts its effect. This is useful in user tasks that can't be reversed, such as deleting accounts, database records, and so on. Therefore, the onclick event was implemented as shown next: How it works... Notice that we embed the JavaScript code inside the onclick event (you also may put it separately in a JS function, per example). When the user clicks the link or the button, a JS confi rmation box appear with two buttons. If you confirm the choice, the JSF action takes place, while if you deny it then nothing happens. There's more... You can use this recipe to display another JS box, such as prompt box or alert box. You can find this recipe in JSF 2.0 Cookbook from Packt From http://e-blog-java.blogspot.com/2011/03/how-to-integrate-javascript-and-jsf.html
March 24, 2011
· 35,717 Views
article thumbnail
How to watch the file system for changes in Java 7 (JDK 7)
Java 7 uses the underlying file system functionalities to watch the file system for changes. Now, we can watch for events like creation, deletion, modification, and get involved with our own actions. For accomplish this task, we need: • An object implementing the Watchable interface - the Path class is perfect for this job. • A set of events that we are interested in - we will use StandardWatchEventKind which implements the WatchEvent.Kind. • An event modifier that qualifies how a Watchable is registered with a WatchService. • A watcher who watch some watchable – per example, a watcher that watches the File System for changes. The abstract class is java.nio.file.WatchService but we will be using the FileSystem object to create a watcher for the File System. The below example follows the above scenario: import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardWatchEventKind; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; import java.util.List; public class Main { public static void main(String[] args) { //define a folder root Path myDir = Paths.get("D:/data"); try { WatchService watcher = myDir.getFileSystem().newWatchService(); myDir.register(watcher, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY); WatchKey watckKey = watcher.take(); List> events = watckKey.pollEvents(); for (WatchEvent event : events) { if (event.kind() == StandardWatchEventKind.ENTRY_CREATE) { System.out.println("Created: " + event.context().toString()); } if (event.kind() == StandardWatchEventKind.ENTRY_DELETE) { System.out.println("Delete: " + event.context().toString()); } if (event.kind() == StandardWatchEventKind.ENTRY_MODIFY) { System.out.println("Modify: " + event.context().toString()); } } } catch (Exception e) { System.out.println("Error: " + e.toString()); } } } The FileSystem object and the WatchService can also be created like this: FileSystem fileSystem = FileSystems.getDefault(); WatchService watcher = fileSystem.newWatchService(); And the Path (watchable), what we watch, and register it with the WatchService object like this: Path myDir = fileSystem.getPath("D:/data"); myDir.register(watcher, StandardWatchEventKind.ENTRY_CREATE, StandardWatchEventKind.ENTRY_DELETE, StandardWatchEventKind.ENTRY_MODIFY);
March 17, 2011
· 120,697 Views

Comments

The Awkwardness of Functional Programming

Dec 20, 2011 · Tony Thomas

No, I have’nt tested it with JBoss. The major difference between the lazy loading mechanism and the eager loading mechanism is the fact that the lazy loading will retrieve related entites only as needed, while the eager loading attemps to retrieve all related entites as once.
The Awkwardness of Functional Programming

Dec 20, 2011 · Tony Thomas

No, I have’nt tested it with JBoss. The major difference between the lazy loading mechanism and the eager loading mechanism is the fact that the lazy loading will retrieve related entites only as needed, while the eager loading attemps to retrieve all related entites as once.
The Awkwardness of Functional Programming

Nov 24, 2011 · Tony Thomas

I am using Glassfish and the persistence provider is EclipseLink (JPA 2.0).
The Awkwardness of Functional Programming

Nov 24, 2011 · Tony Thomas

I am using Glassfish and the persistence provider is EclipseLink (JPA 2.0).
The Awkwardness of Functional Programming

Nov 24, 2011 · Tony Thomas

I am using Glassfish and the persistence provider is EclipseLink (JPA 2.0).

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: