dev@jsftemplating.java.net

Re: Dynafaces example

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Fri, 02 Mar 2007 14:46:38 -0800

Hi Priti,

The following blog has a "download" link to the example in the blog:

    http://blogs.sun.com/paulsen/entry/jsftemplating_dynamicfaces_easy_ajax

Attached is the page I made right before the meeting that "counts".

Ken

Priti Tiwary wrote:
> Hi Ken,
> In your blog can you include the Ajax Dynafaces examples you demoed
> today?
> Priti


<sun:html>
    <sun:head title="Ajax Zone">
        <!-- <jsfExt:scripts /> -->
        <f:verbatim>
            <script type="text/javascript">
                function refreshTime() {
                    window.setTimeout(
                        'DynaFaces.fireAjaxTransaction(document.getElementById(\\'form:count\\'), '
                        + '{'
                        + ' execute: \\'form:count\\','
                        + ' immediate: false,'
                        + ' inputs: \\'form:count\\','
                        + ' render: \\'form:count\\''
                        + '});'
                        + 'refreshTime();',
                        1000);
                }
            </script>
        </f:verbatim>
    </sun:head>

    <sun:body onLoad="refreshTime('form:count')">
        <sun:form id="form">
            "<center><p>&nbsp;</p>
            <staticText id="count" value='<div id="form:count">#{pageSession.count}</div>'>
                <!beforeCreate
                    setPageSessionAttribute(key="count" value="1");
                />
                <!beforeEncode
                    inc("#{pageSession.count}" value=>$pageSession{count});
                    println("here");
                />
            </staticText>

            <sun:markup tag="div" id="result">
                <staticText value="#{pageSession.msg}">
                    <!beforeCreate
                        setPageSessionAttribute(key="msg" value="Guess my number [1-100]!");
                    />
                </staticText>
            </sun:markup>

            "<p>&nbsp;</p>


            // The data input / processing...
            <sun:textField id="guess" label="Your guess: " value="#{requestScope.guess}" />
            <sun:button text="Submit AJAX Request" onClick="
                    DynaFaces.fireAjaxTransaction(this, {execute: this.id + ',form:guess', immediate: false, inputs: this.id + ',form:guess_field', render: 'form:result' });
                    return false;
                    ">
                <!command
                    if ("#{requestScope.guess}>64") {
                        setPageSessionAttribute(key="msg" value="#{requestScope.guess} is too high!");
                    }
                    if ("#{requestScope.guess}=64") {
                        setPageSessionAttribute(key="msg" value="You WIN!!! It was #{requestScope.guess}.");
                    }
                    if ("#{requestScope.guess}<64") {
                        setPageSessionAttribute(key="msg" value="#{requestScope.guess} is too low!");
                    }
                />
            </sun:button>

            "<p>&nbsp;</p>

            // This fields below exist to show required fields are NOT effected
            <sun:textField label="This is required: " required="#{true}" />
            <sun:button text="Submit (non-AJAX)" />

            "</center>
        </sun:form>
    </sun:body>
</sun:html>