cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Werner Masik <wer...@gefi.at>
Subject switch/case fails when if/then works
Date Wed, 06 Jul 2005 08:33:36 GMT
Hello!

I have a strange flowscript problem with a switch/case.  The code is a 
function that should display a list of persons (using a repeater). Every 
row of the repeater contains a submit button for editing and deleting. 
When a button is pressed the form gets submitted and the next action is 
decided by a If/then or a Switch/case that compares the ID of the 
submit-widget.  The strange behaviour is that when I press the edit 
button (with submit-ID=editPerson) the switch/case compare does not seem 
to work. The If/then works. Is it possible that switch/case only works 
with integer? Or maybe it is just a stupid mistake I don't see now. But 
the code is based on http://www.planetcocoon.com/node/1715#comment
So I think it should work. If anybody has an idea, please let me know.

Thanks, werner

Here is my code:

function personenEditor() {
   
    var form = new Form("forms/personenlisteDef.xml");
    form.createBinding("forms/personenlisteBinding.xml");   
    var personDAO = new Packages.com.gefi.ees.persistence.PersonDAO();   
    form.load(personDAO);   
   
    var redisplayForm = true;
    while(redisplayForm) {
       
        form.showForm("formPage/personenlisteTemplate");
        var submitWidget = form.getWidget().getSubmitWidget();
        // Can be null on "normal" submit
        var submitId = submitWidget == null ? null : submitWidget.getId();
        java.lang.System.out.print("SubmitWidgetID=" + submitId);
        var person_id = 
submitWidget.getParent().getChild('person_id').getValue();
        java.lang.System.out.println("; person_id=" + person_id);
       
        if (submitId=="editPerson") {
            // this works
            java.lang.System.out.println("if editPerson");           
        }
        switch(submitId) {
            case "editPerson":
                // does not work
                java.lang.System.out.println("switch editPerson");    
       
                showEditForm();
                break;
            case "createPerson":
                   showCreateForm();
                break;
            case "deletePerson":
                showDeleteForm();
                break;           
        }
    }
}

Mime
View raw message