tags:

views:

1996

answers:

2

Hi,

I am currently trying to validate some front-end values with some server-side methods (as a group) and am running into issues dealing with the result.

Here is the XHTML for the button that starts it all:

<h:commandButton action="#{Bean.save()}" 
        value="Save" 
           id="save" 
      onclick="checkForConfirmation();" />

And the javascript, part of which the button calls, the other part of which the jsFunction calls

function checkForConfirmation()
{
         var name = document.getElementById("path:to:name").value;
         var address = document.getElementById("path:to:address").value;
         var city = document.getElementById("path:to:city").value;
         var state = document.getElementById("path:to:state").value;
         var zip = document.getElementById("path:to:zip").value;

         jsFunc1(name, address, city, state, zip);
}
function showConfirmPrompt()
{
            if(confirm('Confirmation before save')) 
            {
                return true;
            }

            return false; 
}

And finally, the jsFunction which is the problematic piece:

<a4j:form>
        <a4j:jsFunction name="jsFunc1" action="#{Bean.shouldBeConfirmed()}" data="#{Bean.booleanResult}" oncomplete="alert(data); if (data) {showConfirmPrompt();}">
            <a4j:actionparam name="param1" assignTo="#{Bean.nameToBeValidated}"/>
            <a4j:actionparam name="param2" assignTo="#{Bean.addressToBeValidated}"/>
            <a4j:actionparam name="param3" assignTo="#{Bean.cityToBeValidated}"/>
            <a4j:actionparam name="param4" assignTo="#{Bean.stateToBeValidated}"/>
            <a4j:actionparam name="param5" assignTo="#{Bean.zipToBeValidated}"/>
        </a4j:jsFunction>
    </a4j:form>

The problem is that, towards the end of this chain of events, the alert(data) in the 'oncomplete' attribute shows that the data is undefined. I need this to be defined in order to know whether or not to show a warning dialogue.

I can confirm that the Bean.shouldBeConfirmed() method is indeed running, and with the right parameters, and indeed returning the correct value, and even setting the value of the Bean.booleanResult variable (which is a normal java boolean). What am I doing wrong here?

+1  A: 

I have it exactly as your setup and it works for me. The only difference is, I have extra attributes on jsFunction:

    <a4j:form>
    <a4j:jsFunction name="jsFunc1" 
        action="#{Bean.shouldBeConfirmed()}" 
        data="#{Bean.booleanResult}" 
        oncomplete="alert(data);"
        ignoreDupResponses="true"
        eventQueue="foo">
        ...

And my data (your booleanResult) is an int. Works fine.

Yev
A: 

Hi, I have also face the same problem.. In case of Boolean results we need to write full method name instead removing getter... like in your case it should be #{Bean.isBooleanResult}.... Let me know if face problem...

vishal