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)


html javascript - set focus to first page input text textfield when page loads

here's how you set the focus in the first input text textfield of an html page when the page loads.

put this in your page template header (inside the <head> tag, or just inside an individual page's <head> tag):
<script type="text/javascript" src="/scripts/keyboard-controls.js"></script>

create a file here:


function setFocusOnFirstTextfield() {
    var nodeList = document.getElementsByTagName("input");
    for(item in nodeList) {
        if(nodeList[item].getAttribute("type") == "text" || nodeList[item].getAttribute("type") == "password") {

put this in your page template footer (or just at the bottom of an individual html page):

<script type="text/javascript">

(right before the closing body tag, </body>)

so, if you're using a template for your header and footer, then this code will work for all pages in your project :)

richfaces how to set focus on an h:inputText input text textfield (HtmlInputText) in a rich:modalPanel when clicking an open/show button

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.


richfaces how to close rich:modalPanel with escape key rich:hotKey, including modalpanels that open other modalpanels (multi-tier/multi-level)

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 :)


var ActiveModal = new function() {
    this.visiblePanelIDs = new Array();
    this.activeModalPanel = null;
    this.removeModal = function(a) {
        if(a && (a != "wait")) {
            this.activeModalPanel = this.visiblePanelIDs[0];
    this.addModal = function(a) {
        if(a && (a != "wait")) {

            a =,'');
            this.activeModalPanel = this.visiblePanelIDs[0];


explanation of a =,''); :
gets the actual modalPanel id by stripping away the richfaces-appended text "Container" on the rendered id

the JSON code above is based on Justin Skinner's Multiple RichFaces Modal with Same Shortcut Key to Close. my improvement is that the code now works with multi-level modalpanels--it works with an array of modalpanel ids.

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).

open modalpanel1
visiblePanelIDs: {"modalpanel1"}
activeModalPanel: modalpanel1

open modalpanel2
visiblePanelIDs: {"modalpanel2","modalpanel1"}
activeModalPanel: modalpanel2

close modalpanel2
visiblePanelIDs: {"modalpanel1"}
activeModalPanel: modalpanel1

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".

template code (or at the top of your xhtml/jsf page)

<script type="text/javascript" src="/scripts/keyboard-controls.js"></script>


<rich:hotKey key="esc" handler="if(ActiveModal.activeModalPanel){Richfaces.hideModalPanel(ActiveModal.activeModalPanel);}"/>

rich:modalPanel attributes onshow and onhide

<rich:modalPanel onshow="ActiveModal.addModal(this)" onhide="ActiveModal.removeModal('x')" id="transportAgreementDetails">

explanation of ActiveModal.removeModal('x'):

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).


how to generically find "this" richfaces rich:modalPanel's jsf non-html-rendered id, i.e. the id in the jsf/xhtml code (-"Container")

when this code is run in a browser:
<rich:modalPanel id="changePwdPanel" onshow="alert(">

it outputs the following:

and the resulting html code looks like this:
<div id="changePwdPanel" style="display: none;"><input autocomplete="off" id="changePwdPanelOpenedState" name="changePwdPanelOpenedState" type="hidden" /><div class="rich-modalpanel " id="changePwdPanelContainer" ...

if you want to get the actual modalPanel coded id, i.e. changePwdPanel, you can e.g. do this:

<rich:modalPanel id="changePwdPanel" onshow="alert((,''))">


how to download/save videos from NRK in ubuntu 13.04

title in norwegian: hvordan laste ned og lagre videoer fra NRK Nett TV

here's a video of my friend Yassin on NRK:

here's what i had to do to save a copy of that video:
go here:

choose "Link til avspilling med HLS", then click "Lagre"

go to the video link again:

click the Play icon

the page will redirect to this URL:,141,316,563,1266,2250,.mp4.csmil/master.m3u8

save that page/file (ctrl+s), then open the downloaded file  (master.m3u8) in a text editor (e.g. geany)

the file contents will look like this:

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=212000,RESOLUTION=320x180,CODECS="avc1.66.30, mp4a.40.2",141,316,563,1266,2250,.mp4.csmil/index_0_av.m3u8?null=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=387000,RESOLUTION=480x270,CODECS="avc1.66.30, mp4a.40.2",141,316,563,1266,2250,.mp4.csmil/index_1_av.m3u8?null=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=712000,RESOLUTION=640x360,CODECS="avc1.77.30, mp4a.40.2",141,316,563,1266,2250,.mp4.csmil/index_2_av.m3u8?null=
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1410000,RESOLUTION=960x540,CODECS="avc1.77.30, mp4a.40.2",141,316,563,1266,2250,.mp4.csmil/index_3_av.m3u8?null=

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 Downloads

avconv -i ",141,316,563,1266,2250,.mp4.csmil/index_4_av.m3u8" -ss 00:04:11 -t 00:05:00 -codec copy yassin.mp4

when the downloading and converting is done, the resulting video file will now be in your Downloads folder:

if you want to download the whole video just cut out the time parameter parts, e.g.:
avconv -i ",141,316,563,1266,2250,.mp4.csmil/index_4_av.m3u8" -codec copy yassin.mp4

special thanks to this thread:

note: avconv is the "new" replacement for the old program ffmpeg

UPDATE 20131031

i was getting some errors when trying to download a specific video encoded with h264:
[NULL @ 0x123d480] non-existing PPS referenced
[h264 @ 0x1241300] non-existing PPS 0 referenced
[h264 @ 0x1241300] decode_slice_header error
[h264 @ 0x1241300] no frame!

so i installed some extra packages:
sudo apt-get install libx264-dev libfaac-dev librtmp-dev libass-dev

then specified the video and audio codecs to use, like this:
avconv -i,141,316,563,1266,2250,.mp4.csmil/index_4_av.m3u8 -c:v libx264 -c:a libvo_aacenc knaus2.mp4

then it worked :)


sahi - how to access a specific table cell using regex when the cell doesn't have an id

here's some relevant, rendered HTML from a richfaces rich:dataTable for the image above:

<tbody id="invFormremoveTRQPanel:removeTrqPnlTbl:tb">
    <tr class="rich-table-row rich-table-firstrow row1">
        <td id="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id159" class="rich-table-cell wsS ">
            <input type="checkbox" name="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id161"></input>
        <td id="invFormremoveTRQPanel:removeTrqPnlTbl:0:j_id162" class="rich-table-cell wsS ">


the green code represents the first row's second column. the red code is a random id string generated by richfaces because in the xhtml/jsf file, there was no id set for the cell:

    <f:facet name="header">#{msg['label.rcvrRefId']}</f:facet>
    <h:outputText value="#{trq.getRcvrRefId()}" />


here's one way to access the element using regexp:

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]

sahi - how to get tomorrow's date in the format dd.MM.yyyy

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());

which will give output like:

it's cool how you can call java directly in the sahi code :)

thanks to the post how to add the specific number of days to a date which was obtained


sahi - regex how to specify an indeterminate row number for a textfield element in a table row column

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);

\d{1} means a digit (number) with 1 in length, i.e. 0-9.

so that regex will match elements like:
_setValue(_textbox(/detailForm:agrSCFactorsTable:0:SCF_nameIn/), $name);
_setValue(_textbox(/detailForm:agrSCFactorsTable:3:SCF_nameIn/), $name);
_setValue(_textbox(/detailForm:agrSCFactorsTable:7:SCF_nameIn/), $name);


[SOLVED] sahi "for loop" not working

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:

function setTimeFutureHours($hrs) {
    for(var $i=0; $i<$hrs; $i++) {

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 ;)

sahi - how to set a richfaces rich:inputNumberSpinner value and verify it got set correctly

i have the following form composed of a rich:calendar and 2 rich:inputNumberSpinner elements:

<a4j:form id="dateAndTimeSetterForm">
    <h:panelGrid id="dateAndTimeSetter" style="border:1px" columns="1">
        <h:panelGrid style="border:0px;width:100%;align:center" columns="1">
                locale="#{userMenuBean.userLocale}" direction="auto"
                id="dateSetterCal" popup="false" showInput="true"
                showApplyButton="false" datePattern="#{msg['calendar.datePattern']}" cellWidth="24px"
                cellHeight="22px" style="width:200px;align:center;">
                <a4j:support event="onchanged" ajaxSingle="true"
                    reRender="hourSpinner, minuteSpinner" />
        <h:panelGrid style="border:0px;width:100%;align:center;"
            <h:outputLabel style="align:right"
                value="#{msg['label.hour']}" />
                value="#{msg['label.minute']}" />
            <rich:inputNumberSpinner id="hourSpinner" minValue="0"
                style="align:right" maxValue="23" inputSize="2"
                value="#{listTRQsDataModel.requestHandler.hourForTimeInEditPosition}" />
            <rich:inputNumberSpinner id="minuteSpinner" minValue="0"
                maxValue="59" inputSize="2"
                value="#{listTRQsDataModel.requestHandler.minuteForTimeInEditPosition}" />

        <h:panelGrid style="border:0px;align:center;" columns="1">
            <a4j:commandButton id="setTimeBtn" style="align:center"
                oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('time_panel_trq')}.hide()"
                value="#{msg['label.setTime']}" />

which looks like this in a browser:

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

function set_trq_pickup_time_future_1_hr() {

    _wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")));

    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"))));

    var $newHour = ($currentHour+1);

    _wait(_textbox("dateAndTimeSetterForm:hourSpinner").value == $newHour);


    _wait(10000, _isVisible(_button("dateAndTimeSetterForm:setTimeBtn")) == false);


[SOLVED] jboss 4.2.2.GA - character encoding problem when getting URL/URI parameter value

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

the URL looks like this:

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:

to fix this we had to change the following file:

and add a URIEncoding attribute to the <Connector> tag for the HTTP/1.1 protocol:

<Service name="jboss.web">
    <Connector port="9001"
        disableUploadTimeout="true" />

you have to restart your jboss sever for the change to take effect. after restart, the norwegian characters were correct in java: