Yes, I solve my issue using OnEvent using this post:

http://tapestry.1045711.n5.nabble.com/ck-OnEvent-with-Context-td2433888.html

looks like chenille kit doesnt handle context values very well.

but the problem with the solution offered in the above post is that the code
tries to get the context parameters after the event is triggered, during
which time the context variable might be null (as it happened in my case,
because i am using a loop and the context value i need is "row" parameter
which becomes null after the table is rendered. )

So, I did the following:

>From the js file - post the values of 'context' (parse from URI) and 'value'
instead of just 'value' as in the original code.

Added a function getContext() to parse the context value (this handles just
one context value, but should be easily changeable to handle many) and post
both 'context' and 'value'

getContext : function(url) {
        if(typeof(url) == 'undefined')
                return "";
        
        var pos = url.lastIndexOf("/");
        
        if(pos == -1)
                return "";
        
        return url.substr(pos+1);
    },
    reflectOnEvent: function(myEvent)
    {
        var fieldValue;
        var formElement = this.element.form;
        var url = this.requestUrl;

        if(this.stop) Event.stop(myEvent);

        if (typeof formElement != 'undefined')
            fieldValue = $F(this.element);

        console.info('context:' , this.getContext(url));
        
        new Ajax.Request(url, {
            method: 'post',
                        parameters: {"value": fieldValue, "context" : 
this.getContext(url)},
//here posting both

                        onFailure: function(t)
            {
                alert('Error communication with the server: ' +
t.responseText.stripTags());
            },
            onException: function(t, exception)
            {
                alert('Error communication with the server: ' +
exception.message);
            },
            onSuccess: function(t)
            {
                if (this.onCompleteCallback != null)
                                {
                                        var funcToEval = 
this.onCompleteCallback + "(" + t.responseText + ")";
                                        eval(funcToEval);
                                }
                        }.bind(this)
        });
    }


Changed AbstractEventMixin.java like this - 

Object onInternalEvent()
        {
                String value = request.getParameter(PARAM_VALUE);
                String context = request.getParameter(PARAM_CONTEXT);

                final Holder valueHolder = Holder.create();

                ComponentEventCallback callback = new ComponentEventCallback()
                {
                        public boolean handleResult(Object result)
                        {
                                valueHolder.put(result);
                                return true;
                        }
                };

        
                Object[] params = {value, context};

                // old code just passes the value
                //resources.triggerEvent(getEventName(), new Object[]{input}, 
callback);

        // new code passes both value and context to the event handler
        resources.triggerEvent(getEventName(), params, callback);

        return valueHolder.get(); 
        }




-- 
View this message in context: 
http://tapestry.1045711.n5.nabble.com/creating-an-InPlaceSelect-control-tp3358181p3359914.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to