Chris' SWI blog

http://blogs.sun.com/chrisf/date/20080502 Friday May 02, 2008

Visual Web Pack: Using radio buttons to select and deselect your tabs from the TAB Pane

Firstly the tools/products involved:

  • NetBeans IDE 6.0 (Build 200711261600)
  • Visual JSF, version: 1.0.3
  • GlassFish v2, update release 1
  • I thought I would share my experiences with the community on how I was able to toggle tab-panes on and off with a checkbox. Please let me know if you have an easier or better way. :-) Say you have two tab's, one that you want to toggle on or off, and another that remains enabled.

    Step 1: Make the check-box auto submit on change. Make sure the check-box starts of as selected="true", "selectedValue=true", and the immediate flag is selected.

    Step 2: Create a virtual form for the check-box, making sure it submits and participates in the virtual form created.

    Step 3: Add a hidden field to the form for use in the Java code (hiddenField1)

    Step 4: Add a SessionBean (SessionBean1) property to store the check-box state. Add get and set methods for the property.

    private boolean checkBoxSelected = true;

    public boolean isCheckBoxSelected() {
        return checkBoxSelected;
    }

    public void setCheckBoxSelected(boolean checkBoxSelected) {
        this.checkBoxSelected = checkBoxSelected;
    }

    Step 5: Double-click the check-box to add a valueChange method. Add the following code to the valueChange method:

    if (checkbox1.isChecked() == true) {
        tab2.setStyle("visibility: visible");
        hiddenField1.setText("true");
    } else {
        tabSet1.setSelected("tab1");
        tab2.setStyle("visibility: hidden");
        hiddenField1.setText("false");
    }

    The above code checks whether the check-box was select and enables Tab2 (in this case the second tab) if true (i.e. the check-box was ticked) and if false (un-ticked) the tab selected is set to "tab1" - the tab thats always enaled and we then disable the second tab chaning the visibility attribute, "visibility: hidden".

    Step 6: Add the following code to the prerender method:

    String selected = (String)hiddenField1.getText();

    if ((selected != null) && (selected.equals("true"))) {
        getSessionBean1().checkBoxSelected(true);
    } else if (selected == null) {
        checkbox1.setSelected(new Boolean(getSessionBean1().checkBoxSelected()));
    } else
        getSessionBean1().checkBoxSelected(false);
    }

    if (checkbox1.isChecked()) {
        tab2.setStyle("visibility: visible");
    } else {
        tab2.setStyle("visibility: hidden");
    }

     

    My second experience I would like to share with you is;

    Using multiple check-boxes (in this case 2 check-boxes) with the multiple tab-panes (in this case 2) to toggle either tabpane on or off. For example, selecting check-box 1 enables tab-pane 1, selecting check-box 2, enables panel 2. In this particular situation however, I want to make sure that at least one check-box is selected (thus one tab at a miminum is shown). The reason for using the Session Bean is to make sure that on the page reload, the check-boxes are set accordingly to what was previously selected and the respective tab enabled or disabled.

    Step 1: Make box check-boxes auto submit on change. Make sure both check-boxes starts of as selected="true", "selectedValue=true", and the immediate flag is selected.

    Step 2: Create a virtual form for both check-boxes, making sure they are submitting and participating in the virtual form created.

    Step 3: Add two hidden fields to the form for use in the Java code (hiddenField1 and hiddenField2)

    Step 4: Add two SessionBean (SessionBean1) properties to store the check-box statse. Add get and set methods for the property.

    private boolean checkBoxSelected1 = true;

    public boolean isCheckBoxSelected1() {
        return checkBoxSelected1;
    }

    public void setCheckBoxSelected1(boolean checkBoxSelected1) {
        this.checkBoxSelected1 = checkBoxSelected1;
    }

    private boolean checkBoxSelected2 = true;

    public boolean isCheckBoxSelected2() {
        return checkBoxSelected2
    }

    public void setCheckBoxSelected2(boolean checkBoxSelected2) {
        this.checkBoxSelected2 = checkBoxSelected2;
    }

    Step 5: Double-click the check-boxes to add a valueChange method for each check-box and add the following code to the valueChange methods:

    For Check Box 1:

    if (checkbox1.isChecked() == true) {
        tab1.setStyle("visibility: visible");
        hiddenField1.setText("true");
    } else if (checkbox2.isChecked() == true) {
        tabSet1.setSelected("tab2");
        tab1.setStyle("visibility: hidden");
        hiddenField1.setText("false");
    } else {
        tab1.setStyle("visibility: visible");
        checkbox1.setSelected(true);
        hiddenField1.setText("true");
    }

    As you will see frm the code above, it checks whether check-box 1 is selected, if so it enables tab 1. Otherwise it's not meant to be enabled, but based on my use case one tab (of 2) needs to be enabled so it checks check-box 2 to see whether it has been selected or not. if check-box 1 is not selected but check-box 2 is, it disables tab 1 and enables tab 2... if both check-box 1 and 2 aren't selected (not checked), it keeps tab 1 enabled, and checkbox 1.

    For Check Box 2:

    if (checkbox2.isChecked() == true) {
        tab2.setStyle("visibility: visible");
        hiddenField2.setText("true");
    } else if (checkbox1.isChecked() == true) {
        tabSet1.setSelected("tab1");
        tab2.setStyle("visibility: hidden");
        hiddenField2.setText("false");
    } else {
        tab2.setStyle("visibility: visible");
        checkbox2.setSelected(true);
        hiddenField2.setText("true");
    }

    The code for check-box 2 imilarly does what the code I wrote above for check-box 1 only in reverse - tab 2 not tab 1.

    Step 6: Add the following code to the prerender method:

    String selected = (String)hiddenField1.getText();

    if ((selected != null) && (selected.equals("true"))) {
        getSessionBean1().checkBoxSelected1(true);
    } else if (selected == null) {
        checkbox1.setSelected(new Boolean(getSessionBean1().checkBoxSelected1()));
    } else {
        getSessionBean1().checkBoxSelected1(false);
    }

    if (checkbox1.isChecked()) {
        tab1.setStyle("visibility: visible");
    } else {
        tab1.setStyle("visibility: hidden");
    }

    selected = (String)hiddenField2.getText();

    if ((selected != null) && (selected.equals("true"))) {
        getSessionBean1().checkBoxSelected2(true);
    } else if (selected == null) {
        checkbox2.setSelected(new Boolean(getSessionBean1().checkBoxSelected2()));
    } else {
        getSessionBean1().checkBoxSelected2(false);
    }


    if (checkbox2.isChecked()) {
        tab2.setStyle("visibility: visible");
    } else {
        tab2.setStyle("visibility: hidden");
    }

    Please let me know what you think! Comments are welcome!

    http://blogs.sun.com/chrisf/date/20080409 Wednesday April 09, 2008

    A GlassFish adopter in Australia

    Reino International, a division of Saltbush Parking Services, is the largest paid parking equipment and service provider in Australasia and the USA.

    Reino designs and manufactures parking meters, enforcement technologies and the management systems used to manage and enforce on-street and off-street

    Reino decided to use GlassFish for its web-based reporting application. GlassFish at the time was the only product that supported Java EE 5 technologies (JSF, JAX-WS and JPA). The System has now been place for over 18 months, see their story here Reino Develops a Web Based Reporting Application

    http://blogs.sun.com/chrisf/date/20080402 Wednesday April 02, 2008

    GlassFish v2: Changing JVM Options in a Cluster Config - make sure you start the instances properly

    I recently came across an issue where I had to set particular jvm options like; the system classpath, the javaagent, a log4j reference etc.

    When starting the node-agent with the default operation of starting the listening instances (instances syncing with that particular node-agent) asadmin start-node-agent NODE-AGENT-NAME I was seeing that the newly inputted configurations were not getting synchronized with the cluster-configuration changes.

    After discussing with engineering I found out it was a known problem with the start-up sequence and that the workaround was to start the node-agent without the instances starting as well. Then after a successful node agent start I would/can then start the cluster (the instances).

    The commands I used to do this was/were:
    1) asadmin start-node-agent --startinstances=false NODE-AGENT-NAME
    2) asadmin start-cluster CLUSTER-NAME

    After following these two steps above as oppose to the default node-agent start fixed the issue. I got my JVM settings down to the instances... I also wrote a wiki entry on this issue here http://wiki.glassfish.java.net/Wiki.jsp?page=JVMOptions

    http://blogs.sun.com/chrisf/date/20080326 Wednesday March 26, 2008

    My first entry/blog on blogs.sun.com: Comparing GlassFish v2 to Geronimo v2.0.0

    Recently I did a comparison of two open source products, Sun's GlassFish project VS IBM's Geronimo project. Here are 12 bullet points for your consideration. There are a few standout features in favour of GlassFish over Geronimo, these include:

    1/ To download Geronimo you need to log in and leave behind your reasons for the download; "still looking", evaluating etc. etc. GlassFish does not ask for such details when downloading...

    2/ Support for the up-most / latest standards in GlassFish compared to Geronimo, for example: The WebSphere Application Server CE 2.0 supports (ships with): XML-Web Services (JAX-WS)/JAX-Binding (JAXB) 2.0, compared to 2.1 in GlassFish.

    3/ In Geronimo to configure virtual hosts, clustering, deployment to clusters you need to use their CLI, GlassFish has a central administration console for this (CLI or GUI console), as mentioned here: virtual-host To deploy an app to a certain virtual host in Geronimo: Deploying an app to a virtual host (again via command line). Compared to: Clustering web applications with GlassFish

    4/ Everything you can do via the administration console, you can do via the CLI, see: Administration console and CLI for more information. [A far more powerful CLI tool than Geronimo has on offer]

    5/ Clustering support is limited in Geronimo, as listed here This feature does not replicate stateful session Enterprise JavaBeans (EJBs). You will need to avoid stateful session EJBs in your distributed applications. This feature does not replicate dynamic updates to the Java Naming and Directory Interface (JNDI). You will need to configure all the JNDI names used by your distributed applications in every node of the cluster. This feature does not replicate distributable web applications to other nodes in the cluster. You will need to deploy your distributable web applications to every node. GlassFish v2 has full clustering support, see wiki entry Clustering can be administered through the GUI Console as listed here (and VIA command line). Applications can also be deployed to a cluster using the GUI console/CLI.

    6/ The Documentation is weak in Geronimo compared to GlassFish, for example the administration guide, see Tuning Java under the Administration section here compared to GlassFish's JVM tuning

    7/ The JVM settings need to be changed from command line (for Geronimo) using "VI" (or your chosen file editor), in GlassFish, you can change these settings through the management console.

    8/ In Geronimo the common libraries area is interesting. The console lists each and every library from different directories (a.k.a. very basic classpath management IMO)

    9/ The admin console for Geronimo, ("http://.:8080/console" ) runs on the same port as the TomcatWebConnector, a.k.a "HTTP" for the Web Server component.

    10/ WebSphere CE 2.0 has limited support for 64bit JVM's (can only use IBM's) see for more information Geronimo's 64bit JVM Support

    11/ GlassFish v2 has call-flow monitoring built in to the admin console for example Call Flow Monitoring in GlassFish and Call Flow Monitoring in GlassFish

    12/ Glassfish has a unique position in the market right now whereby, the same binaries that are released to open-source form Sun's Commercially Supported Application 9.1, see: Productizing Open Source Projects for more information, the only differences being listed here: FAQ GlassFish VS SJSA91 With Geronimo you get to use Java EE 5, but when you need to move to clustering, failover etc. etc. and you move to WebSphere 6.1 you need to make sure your code is 1.4 compliant. The feature packs don't currently cover the full Java EE 5 spec.

    Please don't hesitate to leave comments below and I'll be sure to respond where I can.


    Valid HTML! Valid CSS!

    This is a personal weblog, I do not speak for my employer.