Avant UI | Bootstrap UI Kit

I liked the starter template for bootstrap using the Avant UI. I think this was a quick way for RAD, and instead of figuring out a layout that might fit your needs.

Avant UI is a free Bootstrap UI Kit for web development
— Read on www.avantui.com/

They collect minimal information and if you would like can make some a quick contribution for their effort. 

Spring Boot loading static content

We will try to quickly how to go about loading and serving static content using Spring Boot 2. There was a difference in how boot 2.0.0 was loading static resources to 2.1 version now. In this article, we will take a simple web application and load the static resources that are defined in the resource folder.

 

Here is how the project is setup for this article.

 

 

I decoupled the pom as a parent and one for the web project. Spring by default without any config changes loads static content from the path that is defined in ResourceWebHandler. But in the article we are going to overwrite the default path.

 

We first over-ride the classWebMVCConfigurer. The sample snippet of override is.,

 

public class BootSamplerWebAppWebConfigurer implements WebMvcConfigurer{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pages/", "/error/","/images"));
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/")
.setViewName("/main/index.html");
}
}

 

As we can see, there are the class couple of methods that we override to tell boot where our static resources are located. I don’t like the favicon that comes from spring framework. So here is the code to serve favicon static content. Here is the code to override that.

 

@Configuration
public class BootSamplerFavIconConfiguration {
@Bean
public SimpleUrlHandlerMapping customFavIconHandlerMapping() {
SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
simpleUrlHandlerMapping.setOrder(Integer.MIN_VALUE);
simpleUrlHandlerMapping.setUrlMap(Collections.singletonMap("/favicon.ico", faviconRequestHandler()));
return simpleUrlHandlerMapping;
}

@Bean
public ResourceHttpRequestHandler faviconRequestHandler() {
ResourceHttpRequestHandler resourceHttpRequestHandler = new ResourceHttpRequestHandler();
ClassPathResource classPathResource = new ClassPathResource("/static/images/favicon.ico");
List<Resource> locations = Arrays.asList(classPathResource);
resourceHttpRequestHandler.setLocations(locations);
return resourceHttpRequestHandler;
}
}

 

Error pages are from a static content directory, we will have to override the class ErrorrPageRegistar

 

public class BootSamplerWebAppErrorRegistrar implements ErrorPageRegistrar {

@Override
public void registerErrorPages(ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.html"));
registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400.html"));
}
}

 

The main method to run the application has some tweaks, here is the code block for that.

 


@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,
JdbcTemplateAutoConfiguration.class})
public class MainApp extends SpringBootServletInitializer {
public static void main(String[] args) {
final SpringApplication springApplication =
new SpringApplication(BootSamplerWebAppErrorRegistrar.class,
BootSamplerWebAppWebConfigurer.class, BootSamplerFavIconConfiguration.class,
MainApp.class);
springApplication.run(args);
}
}

 

When running the, we should get index.html served from the folder main . The template for this index is from the bootstrap template blackrock digital.

 

 

Finally all code for this is in github.

Design benchmarks

This is a long-form write-up. The comment that goes something like this.,

Which means that the people who speak louder online, with higher frequency and reach, are not necessarily the ones striving for Independence, Depth, Honesty, or Breadth through the content they create. They are not necessarily the ones equipped with the experience and knowledge required to share thoughts that will provoke change in our industry.

This is such a genuine opinion, beats the odds that, if you are an individual who is an industry trendsetter, then you do not have time to write about the content that you are working on. So anyone who has the power and time to write will have a perspective on how design should be.

 

Quickest way of getting an custom error message in Spring Boot 2.x

There are different ways to get a custom error message page in spring boot. The following solution worked for my web project. Here is the overview of the structure.

Pic Pic

To start with, if there is 404 error, then we want a custom error page showing up instead of the spring boot’s default page.
The first thing we are going handle is to suppress the boot framework’s error page. For this, we will go to the application properties and add the following line

server.error.whitelabel.enabled=false

As we are done with that, now let us implement the ErrorController interface. The thing to keep in mind is, we have the LOG entry that says what happened to the code base as we reached here. Here is the sample code.

 

@Controller
public class ITContractErrorController implements ErrorController     {
    public static final Logger LOG = LoggerFactory.getLogger(ITContractErrorController.class);
    @Autowired
    ErrorAttributes errorAttributes;
    @GetMapping({"${server.error.path:${error.path:/error}}"})
    public String handleError() {
        LOG.error("Sever error occured");
        return "/error/error.html";
    }
@Override
public String getErrorPath() {
    return "error";
    }
}

One other way that we can add the custom error message is using the Spring 2.x’s ConfigurableServletWebServerFactory implementation. We add this to the main method of the web module. Here is the sample code for this entry.

 

@SpringBootApplication
public class SkminfycontractorWebmoduleApplication {
    @Bean
    public ConfigurableServletWebServerFactory         containerCustomizer(){
        TomcatServletWebServerFactory factory = new     TomcatServletWebServerFactory();
        factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,     "/error/error.html"));
        return factory;
    }
    public static void main(String[] args) {
        SpringApplication.run(SkminfycontractorWebmoduleApplication.class, args);
    }
}

One thing to remember is, when we implement the override with ConfigurableServeletFactory then Override that is ErrorController is gone.

There is a lot of best practice information laid out in spring documentation and other places. But none worked for my setup. I will update this entry if I find a more interesting solution.

Free-code camp Inventory update solution

One other interesting problem with the inventory update challenge from freecodecamp. After this, it is going to be the modules for creating calculators and other challenges.


function updateInventoryWithArr(curInv, newInv) {
    var arr1 = curInv;
    var arr2 = newInv;
    var finalOutPutArr = [];
    var arr1Map = new Map();
    var arr2Map = new Map();
    var arr3Map = new Map();
    for (var j = 0; j < arr1.length; j++) {
        var data1 = arr1[j][1];
        var data2 = arr1[j][0];
        arr1Map.set(data1, data2);
        arr3Map.set(data1, data2);
    }

    for (var i = 0; i < arr2.length; i++) {
        var keyVal = arr2[i][0];
        var lookupKey = arr2[i][1];
        var keyData = arr1Map.get(lookupKey);
        var sumVal;
        if (typeof keyData != 'undefined') {

            sumVal = keyVal + keyData;
            arr3Map.set(arr2[i][1], sumVal);
            arr2Map.set(sumVal, arr2[i][1]);
        } else {
            arr3Map.set(arr2[i][1], keyVal);
            arr2Map.set(keyVal, arr2[i][1]);
        }

    }

    var dataInf = Array.from(arr3Map);
    for (var k = 0; k  b[1]
    });
    return finalOutPutArr;
}

Bootstrap 4 Tutorial

One of a kind tutorial, packed with all that is needed to start Bootstrap 4. When we are debugging an issue for some server side issue, we will need to know a lot of nit-picky details of Bootstrap. But this was a quite a walk thro’ of all the items that are needed to know and read the bootstrap code.