Posts

Showing posts from February, 2023

Cutomize Bootstrap Look and Feel

Bootstrap is a popular front-end framework used to create responsive and mobile-first web pages. With its pre-built components and easy-to-use styling, it allows developers to create professional-looking websites quickly and efficiently. While Bootstrap comes with its own set of themes, sometimes you may need to create a custom theme to fit your project's unique design needs. In this article, we'll walk you through the steps of configuring a custom Bootstrap theme. Set Up Your Development Environment Before we can begin, we need to set up our development environment. This involves downloading Bootstrap and setting up a project folder. You can download Bootstrap from the official website , or you can use a package manager like npm or Yarn. Once you have Bootstrap installed, create a new project folder and add the necessary files. Next, install the Sass compiler . Bootstrap uses Sass files and in order to take advantage of it's variables, maps and mixins you'll need to se

Use JQuery DOM manipulation to glean data from HTML

Recently I had a request to help scrape data from a website. These tasks can be tricky and take quite a bit of time. But if the developer who wrote the code generating the HTML decided to go off script it can get downright ugly. In this article, I'm going to show you one method to clean up the HTML text nodes to make it easier to parse data. I'm going to use JQuery but you can certainly also do this with vanilla javascript.  Note : This is representative of the HTML I was working with but is not the actual data or fields.  Problem Statement I needed to pull out the business name, support phone numbers and contact email addresses. The data was jumbled together and as you can see, there are mulitple text nodes separated by break elements and the overall HTML was sporadic.  <div> <div> <img src= "image.png" data-userid= "123456789" > </div> <div id="business"> Business name<br> <div>

Use Java Enums with JPA

Java Persistence API (JPA) is a widely used standard for object-relational mapping (ORM) in Java applications. One of the common challenges when working with JPA is mapping database columns to Java enums. This can be especially challenging if the database column is not a string, such as when using an integer or a byte as the database column type. In this article, we will explore how to use Java enums with JPA. Mapping Java enums to database columns Before we dive into the details of how to use Java enums with JPA, let's first discuss how JPA maps Java enums to database columns. JPA provides two basic ways to map Java enums to database columns: Ordinal-based mapping : This maps the enum's ordinal value (the position of each enum value in the enum declaration) to the database column. For example, if we have an enum named Status with values ACTIVE, INACTIVE, and SUSPENDED, ACTIVE will have an ordinal value of 0, INACTIVE will have an ordinal value of 1, and so on. Name-based mappi

Project Organization using Eclipse modules

Project organization is a critical aspect of software development. A well-organized project can save developers time and effort in the long run, making it easier to maintain, modify, and scale a project. Eclipse is a popular Integrated Development Environment (IDE) that offers a variety of features and tools for software development. One of the most powerful features of Eclipse is the modular architecture, which allows developers to separate code into manageable modules.  In this article, we will discuss best practices for organizing Eclipse projects using modules. Modules are a collection of related files that are organized together in a separate package or directory. Modules can help keep the project well-organized and promote code reuse. Modules also help to maintain SOLID principles by compartmentalizing project responsibilities.  Here are some best practices for organizing Eclipse projects using modules: Separate modules for separate functionalities: It's best to create sepa

Logging in Spring

Logging is a crucial aspect of any application as it helps in monitoring and debugging the application. In a Spring application, there are several options available for logging, including the standard Java logging API, Log4j, and Logback. In this article, we will take a look at how to log messages in a Spring application using Logback. Logback is a fast and reliable logging framework that provides several advanced features and is highly customizable. It is an improvement over its predecessor, Log4j, and is widely used in Java applications. Setting up Logback in Spring First, we need to add the Logback dependency to our project. If you are using Maven, you can add the following to your pom.xml. As of this article, version 1.4.5 was the latest. Head over to Maven Repository to ensure you get the latest version for your project. <!-- https: //mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <a

Handling image uploads in Spring

Handling image uploads in a web application is a common task, and in Spring, it can be done using Java. In this article, we will discuss how to handle image uploads in Spring using Java. Create a Controller The first step in handling image uploads in Spring is to create a controller that will handle the image uploads. The controller should have a method that will accept the uploaded image file. This method should be annotated with @PostMapping , which indicates that it will handle HTTP POST requests. import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController @RequestMapping("/api/images") public class ImageController { @PostMapping public String uploadImage ( @RequestParam("image") MultipartFi

Spring @ControllerAdvice

Spring Framework provides a feature called @ControllerAdvice that allows developers to provide a centralized advice for all controllers within an application. The advice can be in the form of exception handling, or providing default values for model attributes, or even adding additional response headers. In this article, we will explore what @ControllerAdvice is, how to use it, and some best practices for working with it in Spring. What is @ControllerAdvice? @ControllerAdvice is a Spring annotation that is used to provide advice for all controllers within an application. The advice can be in the form of exception handling, model attribute population, or response header customization. When a @ControllerAdvice class is annotated, it becomes a global point of control for all controllers within an application. How to use @ControllerAdvice To use @ControllerAdvice , you need to create a class that is annotated with @ControllerAdvice . The class should have methods annotated with @Excepti

Spring Framework Profiles

Spring Framework provides a feature called "Profiles" that allows developers to configure different sets of beans and settings for different environments. This is a useful feature for managing the configuration of an application in development, testing, and production environments. In this article, we will explore what Spring Framework profiles are, how to create and use them, and some best practices for working with profiles in Spring. What are Spring Framework profiles? Spring Framework profiles are a way to define and configure different sets of beans and settings for different environments. For example, you may have a set of beans and settings for your development environment, and another set for your production environment. With profiles, you can easily switch between these configurations based on your needs. Creating and using profiles To create a profile in Spring Framework, you first need to define a profile-specific configuration file. This configuration file can be

Spring Security part 5 - Freemarker Security Tags

  In this series of Spring Security articles, I’ve walked you through the configuration, authentication and authorization cycles. In this final article, I’m going to show you how to set up security tags in Free Marker. The concepts I’m going to show you work equally well in JSP, Thymeleaf and Tiles. Other Articles Architecture -  Spring Security Architecture Part 1 -  Security configuration Part 2 -  How to handle UserDetails gracefully Part 3 -  UserDetails for OAuth authentication Part 4 -  Handling GrantedAuthorities with custom roles/permissions Part 5 -  Security tags for Freemarker If you’re new to Spring, you should take a look at  Getting started with Spring Framework for Web Apps 1 Security Tags Implementing security tags with server-side rendering technologies is fairly common, but Spring Security doesn’t ship with any out of the box. Thankfully, setting these up in Free Marker (and others) is fairly straight-forward. This article will leverage knowledge and code exposed in p