Default action to execute when pressing enter in a form

This is not specific to JSF. This is specific to HTML. The HTML5 forms specification section 4.10.22.2 basically specifies that the first occuring <input type=”submit”> element in the “tree order” in same <form> as the current input element in the HTML DOM tree will be invoked on enter press. There are basically two workarounds: Use … Read more

Should switch statements always contain a default clause?

Switch cases should almost always have a default case. Reasons to use a default 1.To ‘catch’ an unexpected value switch(type) { case 1: //something case 2: //something else default: // unknown type! based on the language, // there should probably be some error-handling // here, maybe an exception } 2. To handle ‘default’ actions, where … Read more

How to set a Django model field’s default value to a function call / callable (e.g., a date relative to the time of model object creation)

The question is misguided. When creating a model field in Django, you are not defining a function, so function default values are irrelevant: from datetime import datetime, timedelta class MyModel(models.Model): # default to 1 day from now my_date = models.DateTimeField(default=datetime.now() + timedelta(days=1)) This last line is not defining a function; it is invoking a function … Read more

How to change MySQL data directory?

Stop MySQL using the following command: sudo /etc/init.d/mysql stop Copy the existing data directory (default located in /var/lib/mysql) using the following command: sudo cp -R -p /var/lib/mysql /newpath edit the MySQL configuration file with the following command: sudo gedit /etc/mysql/my.cnf # or perhaps /etc/mysql/mysql.conf.d/mysqld.cnf Look for the entry for datadir, and change the path (which … Read more

How can I make Sublime Text the default editor for Git?

Windows Sublime Text 2 (Build 2181) The latest Build 2181 just added support for the -w (wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such. git config –global core.editor “‘c:/program files/sublime text 2/sublime_text.exe’ … Read more