IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.

The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20131223

i started jboss in debug mode in eclipse so i could debug some changes i'd made, but when the debugger stopped at the first breakpoint, hitting F8 wouldn't resume and there were no step/start/stop/resume icons in the debug panel:

to get it to start working again, i right-clicked on the Debug view button and chose Reset:

then stepping worked after i restarted jboss in debug mode.

to get the step icons back (Debug Toolbar), i had to click on the down arrow, to the right in the Debug panel, and choose Show Debug Toolbar:

20131211

i tried starting the sahi dashboard to run a script: cd ~/workspaceEclipse/tcTrunk/testing/sahi/userdata/bin./start_dashboard.sh ~/workspaceEclipse/tcTrunk/testing

but got the following error message: java.net.BindException: Address already in use at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.AbstractPlainSocketImpl.bind(Unknown Source) at java.net.ServerSocket.bind(Unknown Source) at net.sf.sahi.Proxy.startProxy(Proxy.java:162) at net.sf.sahi.Proxy.access$000(Proxy.java:57) at net.sf.sahi.Proxy$1.run(Proxy.java:126) at java.lang.Thread.run(Unknown Source)

SOLUTION

i stopped my local jboss 7 server that was running in debug mode, and then i was able to open the sahi dashboard.

THE REASON

normally when you start sahi it tells you that it uses port 9999.

looking at the jboss console startup output, i could see that the reason sahi wasn't starting up was because port 9999 was already in use:

20131209

today i had some console output from an error i got while debugging some code ("..." means that i've shortened the actual text bc it was so long): 12:12:54,828 INFO [com.myapp.tiv.persistentservices.transportagreement.daoimpl....12:13:02,216 INFO [stdout] (http-/0.0.0.0:8080-1) setErrorMessage: Feil oppstod...12:13:02,217 ERROR [stderr] (http-/0.0.0.0:8080-1) org.hibernate.LazyInitializat...12:13:02,218 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.proxy.Abstr...

so the red text is what i wanted to remove so i could use the rest of the output in an explanation in our bugtracker. to do this, i created the following regex search/replace code that i ran in "geany" (sudo apt-get install geany):
search/match:^[^ ]+ ?(.*$)
replace:\1

so i ended up with the following result: INFO [com.myapp.tiv.persistentservices.transportagreement.daoimpl....INFO [stdout] (http-/0.0.0.0:8080-1) setErrorMessage: Feil oppstod...ERROR [stderr] (http-/0.0.0.0:8080-1) org.hibernate.LazyInitializat...ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.proxy.Abstr...

at first i thought it would be good enough with just this:
search/match:^[^ ]+ ?
replace:(nothing)

but in geany (or is the regex just wrong?), the matching didn't stop at the end of the line so the output was like this: [com.takecargo.tiv.persistentservices.transportagreement.daoimpl.... [stdout] (http-/0.0.0.0:8080-1) setErrorMessage: Feil oppstod...

EXPLANATION

^[^ ]+ ?(.*$)

first color (pink): start matching attempt at the beginning of the line
second color (purple): and match one or more characters that aren't a space (i.e. match until you meet a space)
third color (blue): and one additional single space
fourth color (aqua blue): then put everything else after that last additional space, to the end of the line, into a "capturing group" so we can reinsert it back into the line using the backreference, \1

While reading the java language specification (java se specs, main page) (JLS) for java 7 (direct link to pdf), I came across a section on escape sequences and unicode characters (Lexical Structure, p. 15), and how they're processed by the jvm, so I made a java "main" class to test outputting unicode and escape sequences to standard out (console).

i created a java class with a "main" method, some static variables and some normal (non-static) instance variables, then ran this file with debug breakpoints on all lines of code to find the processing order and here's what i found:

* access modifiers for variables and methods (private, public, protected, etc) don't seem to affect processing order, ALTHOUGH the "main" method must have the "public" modifier

* standard getter and setter methods for variables don't get processed, i.e. debugger never stops on their breakpoints

* "static final" variables don't get processed by the JVM during initialization or instantiation of the class, i.e. debugger never stops on their breakpoints

processing order:1. static variables and static initialization blocks, in textual order of appearance2. "main" method:2.1 begin executing any logic encountered2.1.1 if a call to instantiate the containing class is made (i.e. "new JVMClassInitializationProcessingOrderTest()"), temporarily pause execution of "main" method logic2.1.1.1 initialize (non-static) instance variables and (non-static) initialization blocks, in textual order of appearance2.1.1.2 process the class' constructor2.1.1.3 resume execution of the remaining logic in the "main" method

20131125

i've been recently reviewing some basic java principles lately and today i got to thinking about the word "class" and wondering exactly what that word is actually known as, e.g.:

public class MyClass { ...}

i found in the java tutorial an article called Java Language Keywords:
"Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.
"

---
NOTE: the red line in the class AccessControlTest:PackagePrivate pPriv = new PackagePrivate();

will not work (and is not expected to work) because class PackagePrivate is declared with a package-private access modifier, i.e. no "public" in front of the "class" keyword identifier, so the class AccessControlTest shouldn't have access to the class PackagePrivate because of java's access control rules.
---

however, when i first tried importing/referencing the class PackagePublic in the class AccessControlTest, i got the following error in eclipse:The resource is not on the build path of a java project

but the "close" button, nor anything else in the p:dialog, was getting rendered in the browser.
finally, i figured out (thanks to my colleague dan) that p:panelGrid simply needed a defined "columns" attribute, like this:

20131113

i have my primefaces jar included in my project build path, and when i do ctrl+space in an xhtml/jsf file, inside a primefaces tag, i get the list of available attributes, but there's no description for them:

i found a workaround by accident: when the autocomplete window is open, as shown in the screenshot above, do ctrl+space again, several times, until you rotate back to the attributes list, and THEN the description will show:

20131107

when trying to view a jsf page, i got the following error in the browser: http 500 error:com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.test.userUsersDataBean

and this was in the console: 11:23:07,407 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/].[facesServlet]] (http-localhost/127.0.0.1:8080-3) JBWEB000236: Servlet.service() for servlet facesServlet threw exception: java.lang.NullPointerException at com.test.userUsersDataBean.setUserAndMemberOnBackingBean(UsersDataBean.java:97) [:] at com.test.userUsersDataBean.<init>(UsersDataBean.java:109) [:]...

here's the code for UsersDataBean.java, line 97:user = userMenuBean.getUser();

userMenuBean was apparently null. eventually i found out that the problem was this, in UserMenuBean.java:@javax.enterprise.context.SessionScoped

when i changed it to this, it worked:@javax.faces.bean.SessionScoped;

UPDATE

i just got a similar Cant instantiate class error when i migrated some validator classes from faces-config.xml to using annotations. the solution was just to rebuild/recompile the project, then "Clean" the server (servers > right click on my jboss server instance > clean), then restart the server.

now just paste the code you want to run, to debug your webpage, and it will run when you hit "enter". in this example, that code in the textfield at the bottom of the debugger window will close the context menu you see in the background.

20131023

it's safer to run jboss as the jboss user, so a hacker can't do anything outside of the "jboss home" (where you installed jboss, e.g. /usr/jboss )

here's how i set it up (will gladly take constructive input):

i created a new service template file based on JBoss' file:bin/jboss_init_redhat.sh

and called it jboss.service.template.nick.sh and put it here:bin/jboss.service.template.nick.sh

here are the contents:
###########jboss.service.template.nick.sh###########

#!/bin/sh
#
# $Id: jboss_init_redhat.sh 60992 2007-02-28 11:33:27Z dimitris@jboss.org $
#
# JBoss Control Script
#
# To use this script run it as root - it will switch to the specified user
#
# Here is a little (and extremely primitive) startup/shutdown script
# for RedHat systems. It assumes that JBoss lives in /usr/local/jboss,
# it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin.
# All this can be changed in the script itself.
#
# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
## UPDATED 20131023 BY NICK, FOR RUNNING AS USER jboss## HOW TO CONFIGURE THIS AS A "SYSTEM SERVICE" (although i've configured it to stay open and dump output to the console, and can be stopped by just doing ctrl+c) AND RUN AS jboss USER:# * create jboss user (the password you give the jboss user is the password that will be asked for when you start jboss as the jboss user--see commands farther down, i.e. "HOW TO START/RUN.."):# sudo useradd -d /usr/jboss -s /bin/bash jboss# * make jboss user own the /usr/jboss folder:# sudo chown -R jboss:jboss /usr/jboss# * edit this file (as jboss user) so paths are correct, for every block of code titled "EDIT/CONFIGURE"# sudoedit -u jboss /usr/jboss/bin/jboss.service.template.nick.sh# * copy this file to /etc/init.d:# sudo cp /usr/jboss/bin/jboss.service.template.nick.sh /etc/init.d/jboss# HOW TO START/RUN JBOSS DOMAIN:# * to run myapp as jboss:# service jboss start myapp# * to run myapptest as jboss:# service jboss start myapptest# * to run myappprod as jboss:# service jboss start myappprod## NOTE: THIS FILE IS BASED ON JBOSS' OWN TEMPLATE FILE: <jboss-home>/bin/jboss_init_redhat.sh## HOW TO UPDATE /usr/jboss FROM SVN SINCE USER jboss OWNS IT:# cd /usr/jboss# sudo svn up .## IF YOU GET CONFLICTS ON UPDATE AND SEE SOMETHING LIKE THIS:# Conflict discovered in 'run.sh'.# Select: (p) postpone, (df) diff-full, (e) edit,# (h) help for more options:## ...AND YOU WANT TO LOAD ALL CHANGES FROM SVN ("UPDATE AND OVERRIDE LOCAL CHANGES"), CHOOSE "theirs full (tf)":# tf## FINALLY, REASSIGN USER jboss TO OWN /usr/jboss:# sudo chown -R jboss:jboss /usr/jboss#

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user#JBOSS_USER=${JBOSS_USER:-"RUNASIS"}##### EDIT/CONFIGURE #####JBOSS_USER=${JBOSS_USER:-"jboss"}##########################

after i changed the video driver in Software and Updates > Additional Drivers from "Using video driver for the AMD graphics accelerators from fglrx (opensource)" to "using X.org X server - AMD/ATI display driver wrapper from xserver-xorg-video-ati (open source, tested)", when i rebooted, ubuntu would freeze on startup at "loading initial ramdisk".

i read several places that in order to get into recovery mode, you need to hold down shift after the BIOS splashscreen, but that didn't help, i never got the grub list of kernels and modes to choose from.

to fix this, i had to turn off the laptop, take out the SSD disk and connect it to another computer so i could edit the following file:/boot/grub/grub.cfg

that file isn't writeable so in a terminal you need to make it writeable for root, like this (when you connect/mount the disk onto another ubuntu machine, the path looks something like the one below):sudo chmod 644 /media/disk/grub/grub.cfg

now edit the file:sudo gedit /media/disk/grub/grub.cfg

starting on line 81 i think there's a block of code for setting timeout; change timeout from 0 to 10, so it looks like this:

if [ "${recordfail}" = 1 ]; thenset timeout=10elseset timeout=10fi

save the file, unmount the disk from the other ubuntu machine, put it back into your laptop, boot, hold in the shift key after the bios splashscreen shows, THEN you'll get into grub :)

choose the option that looks something like Alternatives (can't remember the actual name, but i think it was the second choice from the top), then choose the most recent kernel that ends in "(recovery mode)" :)

which will output the locale-dependent text for the label general.costdeviation.status.accepted, e.g. for english:Accepted

but what if i want to dynamically ask for labels depending on the postfix, e.g. if i have multiple labels with an identical prefix, e.g.:general.costdeviation.status.accepted=Acceptedgeneral.costdeviation.status.negotiating=Negotiatinggeneral.costdeviation.status.open=Opengeneral.costdeviation.status.proposed=Proposed

if you have a button that opens a modal panel and you want to set the focus to the first text input field, then use the rich:modalPanel's onshow attribute:<rich:modalPanel onshow="document.getElementById('trq_det_form:hit_marking').focus()" ...

trq_det_form is the modaldPanel form id and hit_marking is the textfield input id.

20130924

the following code works both for single modal panels AND for multi-level modal panels (modal panels that open new modal panels, i.e. more than one modal panel open at the same time/on top of each other).

note: all rich:modalPanel tags must have a unique id attribute.

note: for some reason (1, 2), at least in our company's app, you have click the modal panel and then press escape in order for the "hide" functionality to work, so if anyone has a solution to this, i'd love to hear it. i tried generating a javascript click() event on the modalpanel to set focus to it, but it didn't help/work. but, despite that, it's still better and faster than having to mouse up to the "x" (close) icon or down to the cancel button at the bottom :)

every time a new modalpanel is opened, its id is placed at the beginning of the array and "older" panels (that are still open) get pushed further back in the array so that when you close the modalpanel on top, the code simply removes the id at the front of the array--index 0 (zero).

activeModalPanel is the modalpanel id that will get closed when you press the escape key

explanation of if(a && (a != "wait")):

during my testing of the code, i found out that the functions removeModal and addModal get run, no matter what, the first time ActiveModal gets initialized, and the "a" parameter is undefined (nothing). also, sometimes during processing, the parameter in to the functions has the value "wait". so, i don't want to do anything in the functions unless the parameter exists AND it isn't equal to "wait".

the parameter ('x') can be anything you want because the removeModal function simply removes the modal panel id at the beginning of the array (index 0), but we need some kind of text string sent in so we know that the function was called by the user and that it wasn't called during initialization of the ActiveModal object AND that it isn't a "wait" (see my explanation above).

the URL for the highest quality version of the video is the one that ends in "index_4_av.m3u8" (you can also see that in the comment above it, it says 1280x720).

now make sure you have avconv installed from ubuntu's repos:sudo apt-get install avconv

the portion of the news about Yassin begins at 04 minutes and 11 seconds and lasts for 5 minutes. I don't want the whole news report which is like 15 minutes long, so run the following command in a terminal window:cd

when the downloading and converting is done, the resulting video file will now be in your Downloads folder:/home/me/Downloads/yassin.mp4

if you want to download the whole video just cut out the time parameter parts, e.g.:avconv -i "http://nordond27a-f.akamaihd.net/i/wo/open/b5/b59297a8dd562f58eb7a5f77d101b0a7eb4500dc/b59297a8dd562f58eb7a5f77d101b0a7eb4500dc_,141,316,563,1266,2250,.mp4.csmil/index_4_av.m3u8" -codec copy yassin.mp4

then specified the video and audio codecs to use, like this:avconv -i http://nrkclip3b-f.akamaihd.net/i/wo/open/84/84af95d37d4b5c59574b6d45589612e022d52762/84af95d37d4b5c59574b6d45589612e022d52762_,141,316,563,1266,2250,.mp4.csmil/index_4_av.m3u8 -c:v libx264 -c:a libvo_aacenc knaus2.mp4
then it worked :)

here's one way to access the element using regexp: _cell(/invFormremoveTRQPanel:removeTrqPnlTbl:0:*/+"[1]")

invFormremoveTRQPanel:removeTrqPnlTbl:0 == the row identifier/.../ == regular expression code* == match any auto-generated id string, e.g. j_id162, this will match every column in the first row
so to specify which column (0-based) we want we write [1]

i needed a simple way to generate a date string so i could set a rich:calendar textbox input field using a sahi script, so here's sample code for one solution to generating tomorrow's date as a text string:var $formattedDate = java.util.Calendar.getInstance();$formattedDate.add(java.util.Calendar.DAY_OF_YEAR, 1);$formattedDate = new java.text.SimpleDateFormat("dd.MM.yyyy").format($formattedDate.getTime());_alert($formattedDate);

20130910

i have a datatable that expands with a new row every time i click an "add new row" button, and only the new row will have an editable textfield input, so to generalize the sahi script code you can use a regex, so it will match whichever single row has a visible textfield input:_setValue(_textbox(/detailForm:agrSCFactorsTable:\d{1}:SCF_nameIn/), $name);

20130904

i noticed on the sahi "for loops" documentation page that the for loop variable "i" wasn't being declared with a dollar sign ( $ ):

for (var i=0; i<links.length; i++){...

so when i wrote a for loop in one of my tests i decided to insert a dollar sign for consistency purposes (so all variables used the dollar sign):function setTimeFutureHours($hrs) { ... for(var $i=0; i<$hrs; $i++) { ... }}

but when i ran the code, the for loop never ran. i quickly realized that i hadn't put a dollar sign next to the "i" in the middle, so i changed it and it ran perfectly:

just out of curiosity, i tried the code without dollar signs next to the "i", like the documentation said and that also worked; you just have to be consistent and either use dollar signs on all of the variables in the for loop phrase or don't use dollar signs ;)

the following sahi code ...
* opens this date+time setting modal panel
* gets the current hour value (originally "12")
* clicks the "up arrow" icon for hour ("Time" in norwegian) to make the hour "13"
* verifies that the hour got set correctly
* then clicks the "set time" submit button ("Sett tid" in norwegian)
* then verifies that the modal panel is closed--the submit button is no longer visible

var $currentHour = _fetch(_textbox("dateAndTimeSetterForm:hourSpinner").value);// clicks the first hour spinner based on class--there are two and "up 1
hour" is on top, i.e. first, so "down 1 hour" would be
"rich-spinner-btn rich-spinner-button[1]" _click(_imageSubmitButton("rich-spinner-btn rich-spinner-button", _in(_table("dateAndTimeSetterForm:hourSpinnerButtons"))));

20130902

we have some code that gets a URL parameter value:String savedSearchName = context.getExternalContext().getRequestParameterMap().get("name");

the URL looks like this:http://localhost:9001/pages/listTRs.jsf?a=li&name=testsøk1

so even though the parameter looked like it had the right norwegian encoding (testsøk1), when we got the parameter value for "name", in java, the String savedSearchName had the following value:testsÃ¸k1

to fix this we had to change the following file:/path/to/jboss/server/mydomain/deploy/jboss-web.deployer/server.xml

yes it sounds odd, but using _wait appropriately can actually make your scripts run faster, without having to worry whether any script command got skipped because something happened too fast (e.g. maybe because of ajax?) :)

i've found that if i don't insert _wait calls in sahi scripts, then sometimes certain operations get skipped, so my code used to consist of some guesstimated wait periods for certain operations, like this: _setValue(_textbox("editTAParty:contact"), $email); _wait(500); _setSelected(_select("editTAParty:Party_languageIN"), $language); _wait(500);

but if you use the advanced _wait functionality, then nothing will get skipped and your scripts will run as fast as possible. here's an example: _setValue(_textbox("editTAParty:contact"), $email); _wait(10000, _textbox("editTAParty:contact").value == $email); _setSelected(_select("editTAParty:Party_languageIN"), $language); _wait(10000, _select("editTAParty:Party_languageIN").options.selectedIndex == $language);

basically, these wait calls mean to proceed with execution of the next step immediately as soon as the condition is fulfilled (or after 10 seconds--whichever comes first).

10000 means 10 seconds (10000 milliseconds). i set a high number since i don't anticipate any operation in the app that i'm testing to ever taking longer than 10 seconds.

UPDATE 20130902

just tested a full implementation of this on a script with 320 steps and reduced the run time from 7:30 to 1:47 :)

20130822

yesterday i was changing some xhtml files while running my app in debug mode in eclipse, but the changes weren't showing up in the browser and i wasn't seeing any reloading msgs in the console, although my jrebel.log file was showing that changes had been registered:2013-08-22 13:30:49.979 INFO [IntelliJFSNotify] Event 'CHANGE' on: '/home/me/workspaceEclipse/myapp/WebContent/webcomponents/fragments/listTransportRequests.xhtml'

i found this post today JRebel, JSF and automatic reload of xhtml files so i opened my web.xml file to see if these elements were there:<context-param> <param-name>facelets.REFRESH_PERIOD</param-name> <param-value>0</param-value></context-param><context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>true</param-value></context-param>

and they were, except the values were different:<context-param> <param-name>facelets.REFRESH_PERIOD</param-name> <param-value>2</param-value></context-param><context-param> <param-name>facelets.DEVELOPMENT</param-name> <param-value>false</param-value></context-param>

when i changed them to 0 and true, then saved the web.xml file, i suddenly saw some output on the console that one of my xhtml files had been changed. then i changed the values back to their original values and jrebel was still reloading them. i stopped the server, rebuilt my project, redeployed in debug and it was still working.... so i'm a little confused...

after 4 hours of endless attempts at trying dozens of people's tutorials, i finally was able to install the amd catalyst drivers on my sony vaio vpcse ( Radeon HD 6600M/6700M/7600M Series ) using a ppa and some additional necessary tasks. here's what i did:

my solution is way simpler:
open richfaces-ui-3.3.3.Final.jar in an archive manager

then open this file in a text editor (double click the file):/org/richfaces/ui.pack.js

beginning around line 15151, you'll see the following lines:}if(A.keyCode==13){if(this.spinner.required||""!=this.edit.value){this.edit.value=this.getValidValue(this.edit.value)}if(this.edit.form){this.edit.form.submit()
change the second line so it looks like this:}if(this.edit.form){/*COMMENTED OUT BY ME: this.edit.form.submit()*/

when you save the file ui.pack.js in the text editor, the archive manager should ask you if you want to update the jar file, choose Update

clear your browser cache, stop your app server, rebuild your project, then restart your server, then test it out in the browser and you should now be able to hit the enter key in a rich:inputNumberSpinner without submitting the form :)