Archive for the ‘Netbeans’ Category

Netbeans Autosubmit Drop Down Boxes

Tuesday, March 27th, 2007

The immediate attribute against the dropdown box is a bit misleading. This is wholly different from the autopostback=”true” attribute on ASP.net.

With JSF, you need to write your own javascript, or use the IDE context menu to write one for you.

Netbeans JSF Autosubmit DropDown Box

Here’s a code sample showing how to change the contents of a second dropdown box based on the value of the first one.

    public void dropDown1_processValueChange(ValueChangeEvent event) {

        String newValue = (String) event.getNewValue();
        java.util.ArrayList options = new java.util.ArrayList();
        if (newValue.equals("Australia"))
        {
            options.add(new Option("Sydney"));
            options.add(new Option("Canberra"));
            options.add(new Option("Brisbane"));
            options.add(new Option("Perth"));
            options.add(new Option("Melbourne"));
        } else if (newValue.equals("US")) {
            options.add(new Option("Washington"));
            options.add(new Option("New York"));
            options.add(new Option("Los Angeles"));
        } else if (newValue.equals("Japan")) {
            options.add(new Option("Tokyo"));
            options.add(new Option("Saitama"));
            options.add(new Option("Niigata"));
        }

        int size = options.size();
        Option[] optarr = new Option[size];
        options.toArray(optarr);
        dropDown2DefaultOptions.setOptions(optarr);
    }

CachedRowSetDataProvider Bug when removeRow and appendRow called without commitChanges

Monday, March 26th, 2007

Here’s the test case and stack trace

    public String btnTest_action() {

        getMaintdayitemDataProvider().removeRow(getMaintdayitemDataProvider().getCursorRow());
        getMaintdayitemDataProvider().appendRow();
        getMaintdayitemDataProvider().cursorLast(); //
        return null;
    }

java.lang.IllegalArgumentException: CachedRowSetRowKey[2]
        at com.sun.data.provider.impl.CachedRowSetDataProvider.setCursorRow(CachedRowSetDataProvider.java:346)
        at com.sun.data.provider.impl.CachedRowSetDataProvider.cursorLast(CachedRowSetDataProvider.java:415)
        at precisweb.maintday.btnTest_action(maintday.java:678)

Netbeans Visual Web Selecting Rows

Saturday, March 24th, 2007

The UI presentation layer doesn’t hold state about which rows were selected.

Winston Prakash outlines how selecting a single row in Netbeans JSF table can be done, but it was a little roundabout.

Here’s a simpler take on it:

Bind a TableRowGroup’s selected attribute to a property on your page.


       <ui:tableRowGroup
             binding="#{Page1.tableRowGroup2}"
             id="tableRowGroup2"
            selected="#{Page1.selected}" 
            sourceData="#{Page1.myDataProvider}"
            sourceVar="currentRow">

Next just write the callback function, in our case, the selected row is the current cursor row, but it could be anything of course:

public boolean getSelected()
{
    RowKey rk = (RowKey) getValue("#{currentRow.tableRow}");
    return rk.equals(myDataProvider.getCursorRow());
}

Changing up the datasource name in a Netbeans project

Friday, March 23rd, 2007

In your personal directory, there is a Netbeans configuration file called context.xml, it has a list of datasources and their jdbc URLs

C:\Documents And Settings\Chui\.netbeans\5.5\context.xml


<context name="java:comp">
    <context name="env">
        <context name="jdbc">
            <object name="TravelPack" class="com.sun.rave.sql.DesignTimeDataSource">
                <arg class="java.lang.Boolean" value="false"/>
                <arg class="java.lang.String"/>
                <arg class="java.lang.Boolean" value="true"/>
                <arg class="java.lang.String" value="org.apache.derby.jdbc.ClientDriver"/>
                <arg class="java.lang.String" value="jdbc:derby://localhost:1527/travel"/>
                <arg class="java.lang.String"/>
                <arg class="java.lang.String" value="travel"/>
                <arg class="java.lang.String" value="D536B001AA3434DE"/>
            </object>

Start up Netbeans, in your session bean, each of the CachedRowSet has a named datasource in the property sheet, you may need to change it:

Netbeans change datasource name

And that’s it!