gradle – dependencyManagement

I was following the code from the book HandsOn: Microservices with Spring Boot and Spring Cloud and it showed the following code

plugins {
   id "io.spring.dependency-management" version "1.0.5.RELEASE"
}

dependencyManagement {
  imports { mavenBom("org.springframework.boot:spring-boot-
  dependencies:${springBootVersion}") }
}

it works, but since I’m using a more recent version of spring CLI, my build.gradle file looked a little different. The above dependencyManagement section can be removed in newer versions and just add a platform dependency as follows, effectively importing a BOM dependency

implementation platform('org.springframework.boot:spring-boot-dependencies:${springBootVersion}')

smartgwt – 100% width for FormItem in a DynamicForm

I can’t belive I fell into this trap +10 years later, I was adding a filter -composed by a DynamicForm and a SelectItem- into and old legacy web application developed with SmartGwt. I just added a DynamicForm with a SelectItem with setTitleOrientation(TitleOrientation.TOP); into a VLayout and set the width of the SelectItem to setWidth("100%") which didn’t work, then read the docs and changed it to setWidth("*"), again didn’t work.

I found this post which referenced the proper documentation about FormLayout which reminded me that DynamicForms use a two column mode by default (one for the title ad one for the input control).

So, the solution is very simple, just setColSpan(2); 🤷

SmartGwt – Filter events client side

SmartGwt has this great Calendar component to display events, it has many features built in.

Usually you would bind your Calendar to a DataSource and it will fetch, add, update and delete accordingly, but we have a Calendar which data is fetched and updated manually through handlers (DayBodyClickHandler, BackgroundClickHandler, CurrentViewChangedHandler, DateChangedHandler, EventRemoveClickHandler, EventResizeStopHandler) which call event.cancel() to override normal behaviour. It also allows us to display a custom event editing component, although now there exists EventEditorCustomizer. Also you may use a client only DataSource in order to do the filtering locally on client side but we haven’t tried that (though it seems simpler 🤷).

Also I tried to override the shouldShowEvent method but it never was called since we were cancelling the default event handlers.

audienciasCalendar = new Calendar(){
			@Override
			public boolean shouldShowEvent(CalendarEvent calendarEvent) {
				Audiencia audiencia = calendarEvent.getAttributeAsObject("audiencia");
				String idJuez = itmJuez.getValueAsString();
				if(idJuez != null && !idJuez.equals(audiencia.getJuez().getId())){
					return false;
				}
				return super.shouldShowEvent(calendarEvent);
			}
		};

So, my solution was to create an array to hold the actual events unfiltered, then when the user changes some SelectItem, it will filter those vaues and call the setData method on the Calendar and hence filtering. To clear the filter we just call setData again with the original values. Also we have to update this variable whenever the user adds, removes or updates an item.

Here the relevant code.

private Calendar audienciasCalendar;
private final SelectItem itmJuez;
private CalendarEvent[] calendarEvents;
...
audienciasCalendar.addDayBodyClickHandler(new DayBodyClickHandler() {

			@Override
			public void onDayBodyClick(final DayBodyClickEvent event) {
				event.cancel();
				AudienciaDetailsModule winDetails = new AudienciaDetailsModule();
				winDetails.setWidth(Window.getClientWidth() / 2);
				winDetails.setHeight(Window.getClientHeight() / 2 + 40);
				winDetails.centerInPage();
				winDetails.show();
			}
		});

itmJuez = new SelectItem("juez", "Juez/Juzgado");
		itmJuez.setOptionDataSource(new RestDataSource(){
			{
				setDataURL(Consts.REST_JUECES_AGENDA);
				setDataFormat(DSDataFormat.JSON);
			}
		});
		itmJuez.setDisplayField("nombre");
		itmJuez.setValueField("id");
		itmJuez.setAutoFetchData(true);https://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/ClientOnlyDataSources.html
		itmJuez.addChangedHandler(new ChangedHandler() {
			@Override
			public void onChanged(ChangedEvent changedEvent) {
				filterAudiencias((String) changedEvent.getValue());
			}
		});
private void filterAudiencias(String idJuez) {
		if(idJuez != null) {
			List filteredEvents = new ArrayList();
			for (CalendarEvent calendarEvent : calendarEvents) {
				Audiencia audiencia = (Audiencia) calendarEvent.getAttributeAsObject("audiencia");
				if (audiencia.getJuez().getId() == idJuez){
					filteredEvents.add(calendarEvent);
				}

			}
			audienciasCalendar.setData(filteredEvents.toArray(new CalendarEvent[filteredEvents.size()]));
		} else {
			audienciasCalendar.setData(calendarEvents);
		}
	}

wildfly – how to stop service in standalone mode

Standalone is not meant for production. But still, we have some apps running in this mode, it’s easy to start and deploy apps right away, just copy the apps to deployments folder and maybe create a signaling .dodeploy file. To start the server you simply run standalone.sh and to stop it you simply press CTRL-C in the terminal. But we configured it to run at startup in the background, i.e.

standalone.sh -b 0.0.0.0 > /dev/null 2>&1 &

how do you stop it? well, of course you can just kill the process. First identify it with ps aux | grep wild and then kill {PID} or even kill -9 {PID}.

but to stop it with a command from the CLI console you may use

bash jboss-cli.sh --connect --commands=shutdown

the bash interpreter is important, otherwise you’ll have an error jboss-cli.sh: 89: jboss-cli.sh: Syntax error: "(" unexpected.

Finally, here is our complete /etc/init.d script to start, stop or check the status of the service which was created based on an old atlassian jira startup script. It starts wildlfy with a specific user.

#!/bin/bash

# WildFly Linux service controller script
cd "${WILDFLY_HOME}"

case "$1" in
    start)
        su -m wildfly ./start.sh
        ;;
    stop)
        bash ./bin/jboss-cli.sh --connect --commands=shutdown
        ;;
    status)
        bash ./bin/jboss-cli.sh --connect --commands=":read-attribute(name=server-state)"
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac

ubuntu 18.04 – how to disable CTRL-SHIFT-U for unicode input

I regularly use KeePass to manage my passwords. It has a feature called Auto Type, you may use it to automatically enter username and password in login forms. But most of the time I use it for shell logins which does not work the same.

Usually I store the command, username and server address in the URL field, i.e. ssh admin@example.com. You may copy this information to the clipboard by pressing CTRL-SHIFT-U and then paste it in the terminal with CTRL-SHIFT-V, but in Ubuntu it triggers unicode input and it shows an underscored u. KeePass does not have the option to map the shortcuts to different key combinations. So I found [https://superuser.com/a/1421979) in stackoverflow. Beware there are several ways to do it and some of them may not work for you. In my case I just changed in Language Support the Keyboard Input method System to none and then I had to delete the file rm ~/.xinputrc as suggested in the comments because I was getting a transparent background in the Text Editor (gedit).

smartgwt – EventResizedHandler

While I was upgrading SmartGWT from 4.0 to 12.1 some of the components have changed its interfaces. This is the case for the Calendar, which previously had the EventResizedHandler but now it uses EventResizeStopHandler. It is the same case for EventMovedHandler which now should be EventRepositionStopHandler.

Every one of these methods has its counter part *MoveHandler which allows you to cancel the event reposition or resizing.

bootstrap – making the navbar transparent

I was replicating a website template in order to use github pages. The template has a navbar with transparent background.

At first I thought this could be so simple, just by adding an opacity property in a css file. I tried but the opacity would affect all children of the navbar (dark themed at first).

.navbar-dark {
    opacity: 0.25;
}

the actual solution is to set the background color using rgb notation instead of hex notation, which allows to set the color opacity.

.navbar-dark {
    background-color: rgb(205, 92, 92, 0) !important;
    border: 0;
}

but…

as it happens, bootstrap has an already provided solution since v4.6.0, just use the bg-transparent class instead of bg-dark (background color).


...

smartgwt – intellij superdev mode with theme issue

I was trying to upgrade some legacy application developed with GWT from old Dev Mode to Super Dev Mode (now just Dev Mode) in order to feel the development process much more modern. This app uses SmartGwt components.

First I needed to upgrade the version of GWT from 2.4.0 to 2.7.0 to be able to use super dev mode and create a Launch configuration on my IDE (IntelliJ) which has superb support for this framework.

I just had to check the box next to Use Super Dev Mode. I thought I could call the day but it turns out the application was not loading, just a blank page.

The first problem I had was that I was inheriting SmartGwt modules which loaded script tags that are no longer supported in GWT. I fix these by using different modules where possible and adding a configuration tag to my GWT xml file telling it to ignore modules with script tags instead of failing.

-	<inherits name="com.smartgwt.SmartGwtNoTheme"/>
-	<inherits name="com.smartclient.theme.graphite.Graphite"/>
+	<inherits name="com.smartgwt.SmartGwtNoScript"/>
+	<inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/>
+	<set-configuration-property name="xsiframe.failIfScriptTag" value="FALSE"/>

Then you have to add the scripts manually to your bootstrap html file, including the script to load the Theme Skin files (replace Desktop with your application module name).

 http://Desktop/sc/modules/ISC_Core.js
  http://Desktop/sc/modules/ISC_Foundation.js
  http://Desktop/sc/modules/ISC_Containers.js
  http://Desktop/sc/modules/ISC_Grids.js
  http://Desktop/sc/modules/ISC_Forms.js
  http://Desktop/sc/modules/ISC_RichTextEditor.js
  http://Desktop/sc/modules/ISC_Calendar.js
  http://Desktop/sc/modules/ISC_DataBinding.js
  http://Desktop/sc/skins/Enterprise/load_skin.js
  http://Desktop/ckeditor/ckeditor.js
  http://Desktop/Desktop.nocache.js

Great! now it was loading up but looking horribly. Apparently it was not loading correctly the path for CSS files and images.

The solution was setting up the isomorphicDir variable in the bootstrap html file within a script tag just before loading the javascript files from SmartClient.

 window.isomorphicDir = 'Desktop/sc/'; 

and voilà!

There’s also a troubleshooting guide for super dev mode from SmartGWT if you’re still stuck.

ehcache 2.5 – disable update checker

I was updating an old GWT application which used ehcache 2.5, in this version, the update checker mechanism is on by default. In the documentation says you may disable it by placing the following config in an ehcache.xml file in the root of the classpath.

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="false" monitoring="autodetect"
         dynamicConfig="true"/>

I tried this and placed the file in my resources folder (so it will be copied to the classes folder and hence be on the root of the class path) but it simply didn’t work.

I had to specify the -Dnet.sf.ehcache.skipUpdateCheck=true option at the command line and that did the trick.

safari – custom search engines

I’m really used to using custom searches in Google Chrome. As I transition to Safari I find this as a road block, since they have disabled the capacity for extensions to modify the behavior of the search bar, this means Omnikey -for instance- does not work anymore.

There are alternatives of course but they are not as compelling for me as it was on Google Chrome, these are examples of the most used "shortcuts" I used within Chrome

  • y billie eilish (search "billie eilish" on youtube)
  • a jordan shoes (search "jordan shoes" on amazon)
  • m mario bros (search "mario bros" on mercadolibre)
  • and a lot more

as you can see I try to use single letter keys for every search (where possible), this simply can not be done with bangs ! in duckduckgo because every key (command) can not be personalized since its shared with everyone else. Take for example my first search, it would trigger a search on yahoo instead of youtube.

Safari has inbuilt Quick Website Search, you just have to figure out the term that triggers it. Find out more in Safari Preferences 
→ Search tab → Quick Website Search

Again with this solution I have to type you billie eilish then TAB and ENTER to make the first search, and first, you have to figure out the term that triggers it. I found you have to type at least 3 characters, the url must contain these and you have to TAB. You can see a list of the search engines Safari has captured in Manage Websites but you can not assign personalized keys.

I think -for now- I have to get back to Google Chrome. 🤷🏽‍♂️ 😥