Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-14 Thread Stifan Kristi
a, i c, thank you so much for your detail explaination and reference,
anthony.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-14 Thread Sebastian E. Ovide
Thanks Anthony,

I confirm that Replacing request.cid with
request.env.http_web2py_component_element made the trick.


Is there any reason why when ajax is false it is not stored in  request.cid ?


On Tue, Jun 14, 2011 at 3:44 AM, Anthony abasta...@gmail.com wrote:

 On Monday, June 13, 2011 9:00:55 PM UTC-4, 黄祥 wrote:

 pardon, me, what's cid used for? is it mandatory to use trap?
 thank you so much.


 All components (with or without ajax=True) are wrapped in a DIV, which is
 given an id. You can specify the id via the 'target' argument to LOAD() --
 if you do not specify it, one is generated automatically. For ajax
 components, the id is stored in request.cid so it can be accessed if needed.
 If you want to trap a link via the 'cid' argument to the A() helper, you
 need to know the component id. See
 http://web2py.com/book/default/chapter/13#Client-Server-Component-Communications
  for
 more details.

 Anthony




-- 
Sebastian E. Ovide


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-14 Thread Anthony
On Tuesday, June 14, 2011 5:27:37 AM UTC-4, sebastian wrote: 

 Thanks Anthony, 

 I confirm that Replacing request.cid with 
 request.env.http_web2py_component_element made the trick.

 Is there any reason why when ajax is false it is not stored in  request.cid ?

  
Maybe Massimo can answer that. Perhaps when it was first designed it wasn't 
anticipated that request.cid would be needed for non-ajax components.
 


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
Not necessarily. Ajax=true loads the page and component in parallel. Ajax=false 
waits for the component to load before rendering the page.


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread apple
Well it certainly seems faster. With Ajax=True the first part of the
page appears then there is a disconcerting pause before the rest.

On Jun 13, 9:37 am, pbreit pbreitenb...@gmail.com wrote:
 Not necessarily. Ajax=true loads the page and component in parallel. 
 Ajax=false waits for the component to load before rendering the page.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread anil manikyam
i have a one field i.e) username

i want to accept only alphabets plz send this code
db.define_table('table1',
Field('username', 'string')


plz send code for this



-- 
@n!l m@n!ky@m


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread anil manikyam
i have a one field i.e) username

i want to accept only alphabets plz send this code
db.define_table('table1',
Field('username', 'string')


plz send code for this

-- 
@n!l m@n!ky@m


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
With ajax=True, first the parent page is returned to the browser, and then 
an Ajax call is made to fill in the component. So, the parent page should 
load a little faster in that case (because the component isn't called until 
after), but there's an additional network call to get the component, so 
total time might be a bit longer.
 
With ajax=False, the component is added to the parent page on the server 
side as part of the original request for the parent page. That means 
returning the parent page might take slightly longer (because web2py has to 
generate the component content as part of the original response), but there 
is no subsequent Ajax call once the parent page is returned. So, this may 
seem faster because there is no waiting for the component to render once the 
main page is loaded.
 
With ajax=True, however, there shouldn't necessarily be a disconcerting 
pause, unless the component takes a particularly long time for web2py to 
generate (or unless you've got slow network times).
 
Anthony

On Monday, June 13, 2011 6:24:56 AM UTC-4, apple wrote:

 Well it certainly seems faster. With Ajax=True the first part of the 
 page appears then there is a disconcerting pause before the rest. 

 On Jun 13, 9:37 am, pbreit pbreit...@gmail.com wrote: 
  Not necessarily. Ajax=true loads the page and component in parallel. 
 Ajax=false waits for the component to load before rendering the page.



[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
It can be a little jarring but some believe this approach is a big trend in web 
service design.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Sebastian E. Ovide
It depends on the page imagine the case of a page with a lot of
comments... each comment has a like component... if you load each like via
ajax you will need to do a lot of ajax calls   and the page would
take several seconds to load and you will be loading your webserver with
resources consuming calls


so it depends on the case...

anyway I would suggest to use ajax=true until
http://code.google.com/p/web2py/issues/detail?id=286 is fixed

On Mon, Jun 13, 2011 at 5:22 PM, pbreit pbreitenb...@gmail.com wrote:

 It can be a little jarring but some believe this approach is a big trend in
 web service design.




-- 
Sebastian E. Ovide


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
On Monday, June 13, 2011 6:21:01 PM UTC-4, sebastian wrote: 

 anyway I would suggest to use ajax=true until 
 http://code.google.com/p/web2py/issues/detail?id=286 is fixed

 
 I'm not sure issue 286 is really a problem. ajax_trap is for trapping forms 
within components, not for trapping links. If you want to trap a link within 
a component, you just have to know the div id of the component. When 
ajax=True, the div id is stored in request.cid, so you can specify 
cid=request.cid in the A() helper, as you did in your example. However, when 
ajax=False, the div id is not stored in request.cid. In that case, you can 
specify your own div id via the 'target' argument to LOAD(). So, you would 
do:
 {{=LOAD(f=testajax.load,target='testajax',ajax=False)}}

In testajax.load

{{=A('click me', _href=URL('testajax.load'),cid='testajax')}}
 Alternatively, you can get the automatically generated component id from 
request.env.http_web2py_component_element, so you could do:
 {{=A('click me', 
_href=URL('testajax.load'),cid=request.env.http_web2py_component_element)}}
 In any case, perhaps web2py should assign the component id to request.cid 
even when ajax=False.
 Anthony


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread pbreit
Right, you would not load each individual comment via individual LOADs 
(except I think the new Google Groups does something similar). But you might 
have individual components for Top 10 Comments, 10 Newest Comments, etc.

Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
Note, I have added a comment to issue 286 on Google Code with the 
explanation below.

On Monday, June 13, 2011 7:00:39 PM UTC-4, Anthony wrote:

 On Monday, June 13, 2011 6:21:01 PM UTC-4, sebastian wrote: 

 anyway I would suggest to use ajax=true until 
 http://code.google.com/p/web2py/issues/detail?id=286 is fixed

  
  I'm not sure issue 286 is really a problem. ajax_trap is for trapping 
 forms within components, not for trapping links. If you want to trap a link 
 within a component, you just have to know the div id of the component. When 
 ajax=True, the div id is stored in request.cid, so you can specify 
 cid=request.cid in the A() helper, as you did in your example. However, when 
 ajax=False, the div id is not stored in request.cid. In that case, you can 
 specify your own div id via the 'target' argument to LOAD(). So, you would 
 do:
  {{=LOAD(f=testajax.load,target='testajax',ajax=False)}}

 In testajax.load

 {{=A('click me', _href=URL('testajax.load'),cid='testajax')}}
  Alternatively, you can get the automatically generated component id from 
 request.env.http_web2py_component_element, so you could do:
  {{=A('click me', 
 _href=URL('testajax.load'),cid=request.env.http_web2py_component_element)}}
  In any case, perhaps web2py should assign the component id to request.cid 
 even when ajax=False.
  Anthony



Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Stifan Kristi
pardon, me, what's cid used for? is it mandatory to use trap?
thank you so much.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-13 Thread Anthony
On Monday, June 13, 2011 9:00:55 PM UTC-4, 黄祥 wrote: 

 pardon, me, what's cid used for? is it mandatory to use trap? 
 thank you so much.

 
All components (with or without ajax=True) are wrapped in a DIV, which is 
given an id. You can specify the id via the 'target' argument to LOAD() -- 
if you do not specify it, one is generated automatically. For ajax 
components, the id is stored in request.cid so it can be accessed if needed. 
If you want to trap a link via the 'cid' argument to the A() helper, you 
need to know the component id. See 
http://web2py.com/book/default/chapter/13#Client-Server-Component-Communications
 for 
more details.
 
Anthony


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread pbreit
I think ajax_trap only pertains to form processing. My LOADs don't have any 
forms and are all ajax=True. It's just a way to componentize pages. Example, 
the categories and items on http://pricetack.com

[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Massimo Di Pierro
I stronly suggest always using ajax=True and not using ajax_trap=True. 

Both trap forms. ajax_trap=True performs an extra optimization: it avoids 
the first ajax call by serving the original content within the outer page. 
people have reported some problems with this and I am working to fix it.

from a user point of view there is no difference.




[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread apple
Right now there is a bug that means the request.vars don't get passed
correctly. I assume that will be fixed fairly quickly so ignoring that
for the moment:

As I understand it ajax=False means that the page is compiled on the
first request; but the components all have their own request object.
So you have all the benefits of componentisation without the overhead
of the ajax calls. Setting ajax_trap determines whether forms are
submitted via ajax or by reloading the whole page.

So once it  is all working as intended don't you get all the benefits
without the overhead by setting ajax=False? Or is there some other
reason that you would want to set ajax=True?

On Jun 12, 6:04 pm, Massimo Di Pierro massimo.dipie...@gmail.com
wrote:
 I stronly suggest always using ajax=True and not using ajax_trap=True.

 Both trap forms. ajax_trap=True performs an extra optimization: it avoids
 the first ajax call by serving the original content within the outer page.
 people have reported some problems with this and I am working to fix it.

 from a user point of view there is no difference.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Stifan Kristi
pardon me, btw, what is the function of ajax_trap = True? what can do by
ajax_trap = True?
thank you so much.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread villas
Traps the result in a div,  there is some info in the book:

http://web2py.com/book/default/chapter/13


[web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Massimo Di Pierro
ajax = True does the same as ajax_trap = True. They both trap forms.

On Jun 12, 6:11 pm, Stifan Kristi steve.van.chris...@gmail.com
wrote:
 pardon me, btw, what is the function of ajax_trap = True? what can do by
 ajax_trap = True?
 thank you so much.


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Anthony
On Sunday, June 12, 2011 7:11:10 PM UTC-4, 黄祥 wrote: 

 pardon me, btw, what is the function of ajax_trap = True? what can do by 
 ajax_trap = True? 
 thank you so much.

 
ajax=True means the entire component is always loaded via Ajax (by calling 
the web2py_component() function in /static/js/web2py_ajax.js) -- this 
includes trapping any forms in the component, submitting them to the 
component action via Ajax, and rendering the result in the component div.
 
ajax_trap=True is only relevant when ajax=False. When ajax=False, the 
component is inserted in the page on the server side, before the parent page 
is returned to the browser. In that case, if there is a form in the 
component and you want the form submitted to the component action via Ajax, 
then you have to set ajax_trap=True. Otherwise, the form will be submitted 
normally and the entire page will be reloaded.
 
As Massimo suggested, if you've got a form in the component and would like 
it trapped via Ajax, you're probably better off just setting ajax=True so 
the whole component will always be loaded/reloaded via Ajax. Setting 
ajax=False probably makes more sense when you just need to load the 
component once and don't need any further interaction/reloading (i.e., no 
forms).
 
This is explained in the book here: 
http://web2py.com/book/default/chapter/13#Components
 
Anthony


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Stifan Kristi
a, i understand, right now, thank you so much for your explaination, massimo


Re: [web2py] Re: When would one load a component with ajax=True as opposed to ajax_trap=True

2011-06-12 Thread Stifan Kristi
a, it's clear for me know, thank you very much for your detail explaination
and reference, anthony, i think this is the answer about my ajax component
problems question, sorry, oot in the wrong room. again, thank you so much.

On Mon, Jun 13, 2011 at 7:53 AM, Anthony abasta...@gmail.com wrote:

 On Sunday, June 12, 2011 7:11:10 PM UTC-4, 黄祥 wrote:

 pardon me, btw, what is the function of ajax_trap = True? what can do by
 ajax_trap = True?
 thank you so much.


 ajax=True means the entire component is always loaded via Ajax (by calling
 the web2py_component() function in /static/js/web2py_ajax.js) -- this
 includes trapping any forms in the component, submitting them to the
 component action via Ajax, and rendering the result in the component div.

 ajax_trap=True is only relevant when ajax=False. When ajax=False, the
 component is inserted in the page on the server side, before the parent page
 is returned to the browser. In that case, if there is a form in the
 component and you want the form submitted to the component action via Ajax,
 then you have to set ajax_trap=True. Otherwise, the form will be submitted
 normally and the entire page will be reloaded.

 As Massimo suggested, if you've got a form in the component and would like
 it trapped via Ajax, you're probably better off just setting ajax=True so
 the whole component will always be loaded/reloaded via Ajax. Setting
 ajax=False probably makes more sense when you just need to load the
 component once and don't need any further interaction/reloading (i.e., no
 forms).

 This is explained in the book here:
 http://web2py.com/book/default/chapter/13#Components

 Anthony