Chen Jian's Java Blog 

Change the font family globally in Material-UI 3.x

by Chen Jian


Posted on 2019-06-29 12:00 in Frontend


Some say you should use the jsx-global-plugin like "@global body{fontFamily:'someFont'}" , but it doesn't work in my project. The global CSS still has the lower CSS speciality than MUI components' CSS because this global CSS is using a type selector. ...


Code snippet: Swagger + Spring Boot

by Chen Jian


Posted on 2019-06-25 12:00 in Java


compile 'io.springfox:springfox-swagger2:2.9.2' compile 'io.springfox:springfox-swagger-ui:2.9.2' /** * See https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api */ @Configuration @EnableSwagger2 public class...


Generate PDF from server side using Java

by Chen Jian


Posted on 2019-06-21 12:00 in Java


You can use OpenPDF to draw a PDF (the open source fork of iText). However, the learning curve of creating PDF with layouts and stuff is very high. A more cost-effective solution is create an HTML version of it and convert it using Flying Saucer ...


Redux + Typescript: The type of the root state

by Chen Jian


Posted on 2019-06-14 12:00 in Frontend


You can get the type of the state from the root reducer // the reducer const appReducer = combineReducers({ global: globalStateReducer, example: exampleReducer }); type AppState = ReturnType<typeof appReducer> However the...


Redux + Typescript: Use class to define Actions

by Chen Jian


Posted on 2019-06-14 12:00 in Frontend


You want the actions to be typed. You should use interface or class. Class is better than interface because in interfaces you cannot define the action "type" as a constant, but in classes you can: class LoadingStartedAction implements...


Read process output in Java without hanging the main thread

by Chen Jian


Posted on 2019-06-14 12:00 in Java


See https://github.com/chenjianjx/wsdl2html/blob/541a33820e9f246a6a73aafaadbb1cf96c6123fc/src/main/java/org/jaxws/util/os/SystemProcessUtils.java


Gradle upload a custom-generated jar file to Nexus

by Chen Jian


Posted on 2019-06-14 12:00 in Java


Do this: apply plugin: 'maven-publish' publishing { publications { maven( MavenPublication ) { artifact theTaskThatGeneratesJar } } repositories { maven { ...


Don't run Jetty with the default "bin/jetty.sh start"

by Chen Jian


Posted on 2019-06-13 12:00 in Java


Instead, run it with: java -jar start.jar "bin/jetty.sh start" does a lot of doggy things for you. You will get suprising results if you use it, for example, the logs inside your war are not shown. Avoid it unless you do know about those...


Sending html emails with images inside

by Chen Jian


Posted on 2019-05-26 12:00 in Java


If the images are external image links that can be accessed by http url, then nothing speical needs to be done. If the images are external image files, then you have 2 choices. Embed the images as base64 strings. . This is simple....


React Component: A pair of componentDidMount() and componentWillUnmount() may cause infinite loop if error is thrown from render

by Chen Jian


Posted on 2019-04-18 12:00 in Frontend


The following will cause an infinite loop. The render() method will be called again and again. class ToDoItemEditComponentContainer extends React.Component { componentDidMount() { this.props.loadItem(); //load item remotely and...


JSON.stringify() won't work for ES6 Set

by Chen Jian


Posted on 2019-04-17 12:00 in Frontend


It will just return "{}", no matter if the Set is empty. This also means deep clone based on JSON won't work. If JSON.stringify() matters to you, use Array instead of Set


Material-UI: avoid RadioGroup if there are complex elements inside each radio

by Chen Jian


Posted on 2019-03-03 12:00 in Frontend


Just use seperate Radios The problem with RadioGroup with nested elements under Radios is that it messes up with your layout. RadioGroup is a child of FormGroup, which does a lot of styling itself. If you use it, you will lose a lot of freedom...


My practice of fetching data for List/Detail components in React/Redux

by Chen Jian


Posted on 2019-02-17 12:00 in Frontend


The user experience it should have When you go to a detail page from the list page or with a direct URL, the detail page should show the up-to-date data When you go to the list page with a direct URL, the list page should show the...


What happens to the redux store if I refresh the browser?

by Chen Jian


Posted on 2019-01-19 12:00 in Frontend


It will go away, and then be initialised. If you have this question, it means you have no exact idea of the lifespan of client-side state in a browser. First of all, a document is created under current tab of the browser when a url is first...


flexbox's "justify-content:center" doesn't do text-align

by Chen Jian


Posted on 2018-12-15 12:00 in Frontend


It only aligh the "items" to the center axis. Text inside each item is not aligned in center Here is an example provided by w3schools . You can see "1" is not in the center of the pink box.