Setting the default/welcome page for a JSF app

Since <welcome-file-list> only works with physical files, you cannot use a *.jsf filename here since this resolves to a different physical file (like *.xhtml).

To define a welcome file, use one of the following approaches:

    • add an index.html file, and include a refresh meta tag in the head:

      <head>
      <meta http-equiv="Refresh" content="0; URL=your_welcome_page.jsf">
      </head>

 

  • add an index.jsp file, and redirect to your welcome page:

    <% response.sendRedirect("dropdowns.jsf"); %>

Initializing a JSF ManagedBean

Sometimes things really are easy – the fact that I Googled how to do this now seems pretty silly. The more I use JSF the more I like it 🙂

To initialize the state of the ManagedBean that a JSF page is using (like to preload data, or initialize other displayed values), just call the code from the bean’s constructor. Simple as that.

For example

@ManagedBean
public class ExampleController
{
    private String exampleProperty1;
    private String exampleProperty2;

    public ExampleController()
    {
    //example init code here, e.g. to init property values
    }

    ...

}

Skipping locally updated files with Git

If you have a local file that you’ve updated locally (like a properties file) but you want to avoid committing the changes when you next commit, use this command:

git update-index --skip-worktree path/to/filename

If you need to add it back to the list of tracked files, then use this:

git update-index –no-skip-worktree path/to/filename

MongoDB usage notes

MongoDB Shell commands:

#list dbs on server:
show dbs
#show collections in current db
show collections
#switch to db
use databasename;

#find everything and print as json
db.collectionname.find().forEach(printjson);

#'like' query:
db.collectionname.find(fieldname:/pattern/).forEach(printjson);

#count results:
db.collectionname.find().count();

#return only requested properties (similar to 'select x, y, z from table a')
db.collectionname.find({}, {fieldname1:1, fieldname2:1}).forEach(printjson)

#select min x by sorting in asc order and picking first result
db.collectionname.find().sort({x: 1}).limit(1).forEach(printjson)

#select max x by sorting in desc order and picking first result
db.collectionname.find().sort({x: -1}).limit(1).forEach(printjson)

#add an index for property x
db.collectionname.ensureIndex({x: 1})

Stats webapp: http://localhost:28017/