<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>click-user@incubator.apache.org Archives</title>
<link rel="self" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/?format=atom"/>
<link href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/"/>
<id>http://mail-archives.apache.org/mod_mbox/incubator-click-user/</id>
<updated>2009-12-09T13:27:22Z</updated>
<entry>
<title>Re: [ANNOUNCE] Apache Click</title>
<author><name>gilbertoca &lt;gilbertoca@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260361772053-4139100.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260361772053-4139100-post@n2-nabble-com%3e</id>
<updated>2009-12-09T12:29:32Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Good news! Lastly but very happy!
Thanks for all your effort!

Gilberto

PS.: Can we get there?
http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/JDev11gExperience/JDev11gExperience.html
(Oracle ADF) It's seems very interesting, but not everyone can buy it!



Bob Schellink-2 wrote:
&gt; 
&gt; Apache Click has graduated!
&gt; 
&gt; Earlier this week the Apache board has established Click as a new
&gt; top-level project.
&gt; 
&gt; We will be migrating the website and mailing lists to their new locations
&gt; in the coming days. 
&gt; Subscribers to the incubator mail lists will automatically be migrated to
&gt; the new lists, there is no 
&gt; need to resubscribe.
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/ANNOUNCE-Apache-Click-tp4042033p4139100.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260319114713-4136572.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260319114713-4136572-post@n2-nabble-com%3e</id>
<updated>2009-12-09T00:38:34Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

That worked nicely! Thanks again for the help - I just only found this
community and I have to say that your prompt support is really great.. I
hope I'll be able to help at some point in the future.

Dipita

Bob Schellink-2 wrote:
&gt; 
&gt; Yep, see my previous mail on creating a custom Form and overriding the
&gt; #insert method to return 
&gt; silently (might be a better default than throwing an exception).
&gt; 
&gt; Alternatively you can check if the control exists before adding it:
&gt; 
&gt; public void onInit() {
&gt;    Field field = new TextField("name");
&gt; 
&gt;    if (! form.getControlMap().contains(field.getName())) {
&gt;      form.add(field);
&gt;    }
&gt; }
&gt; 
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt; dshah wrote:
&gt;&gt; Hi Bob,
&gt;&gt; What you are saying makes sense (regarding using javascript to add the
&gt;&gt; fields to the form once I figure out which ones were newly added etc) -
&gt;&gt; however, basically using stateful pages is not working for me - we cannot
&gt;&gt; create the controls on the main page in the constructor since those are
&gt;&gt; dynamically created based on the user selection. Because of this
&gt;&gt; limitation,
&gt;&gt; if I make the page stateful, the next time the onInit() method is called
&gt;&gt; (e.g. when a submit button for the form is clicked,) I am getting an
&gt;&gt; error
&gt;&gt; saying the field (the one that is created and initialized on the onInit
&gt;&gt; method) already exists in the form..
&gt;&gt; 
&gt;&gt; How would we get around this problem?
&gt;&gt; 
&gt;&gt; Once again, thanks for all your help - I appreciate the prompt and very
&gt;&gt; explanatory emails.
&gt;&gt; Dipita
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt; If I have a page (say A) that has a form with some controls (say A1),
&gt;&gt;&gt;&gt; and
&gt;&gt;&gt;&gt; I
&gt;&gt;&gt;&gt; have another page (say B) which has another control (say B1).  I use
&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt; render page B's control.  However, I don't see that control on the
&gt;&gt;&gt;&gt; server
&gt;&gt;&gt;&gt; side for Page A -- as Bob has explained below, it's because the server
&gt;&gt;&gt;&gt; is
&gt;&gt;&gt;&gt; not aware of this render that happened on the client.  Question is - is
&gt;&gt;&gt;&gt; getting a handle of the form on Page A and adding control B1 to that
&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt; the only way to make the server aware of this new control that was
&gt;&gt;&gt;&gt; added?  
&gt;&gt;&gt;
&gt;&gt;&gt; Basically yes. You either have to access the Form from a stateful Page,
&gt;&gt;&gt; or
&gt;&gt;&gt; place the Form directly 
&gt;&gt;&gt; in the HttpSession and access it from there.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Is there any other way to do this -- basically, if we are going to add
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; control B1 o Page A's form object, then the whole form is being sent
&gt;&gt;&gt;&gt; back
&gt;&gt;&gt;&gt; to/from the client (browser) and server right?  I am wondering is there
&gt;&gt;&gt;&gt; a
&gt;&gt;&gt;&gt; way to not have to send the whole form back/forth from the
&gt;&gt;&gt;&gt; client/browser
&gt;&gt;&gt;&gt; (technically it doesn't seem possible to me but I am not so clear about
&gt;&gt;&gt;&gt; all
&gt;&gt;&gt;&gt; this..)
&gt;&gt;&gt;
&gt;&gt;&gt; Sending back the whole Form is probably easiest because Form will
&gt;&gt;&gt; include
&gt;&gt;&gt; all the markup to render 
&gt;&gt;&gt; the controls. But you can send back only the Field/Fields/FieldSet you
&gt;&gt;&gt; added, no need to render the 
&gt;&gt;&gt; whole Form. You can use your JS library to append the returned
&gt;&gt;&gt; Field/Fields/FieldSet to the Form. 
&gt;&gt;&gt; Just remember that Form lay out its controls in a grid using the &lt;table&gt;
&gt;&gt;&gt; element. So very likely you 
&gt;&gt;&gt; will want to wrap your returned Fields inside &lt;tr&gt; elements as well.
&gt;&gt;&gt;
&gt;&gt;&gt; Hope that make sense :)
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thoughts?
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0
&gt;&gt;&gt;&gt;&gt; final.
&gt;&gt;&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are
&gt;&gt;&gt;&gt;&gt; busy
&gt;&gt;&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt;&gt;&gt; official
&gt;&gt;&gt;&gt;&gt; 2.1.0 final release.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2
&gt;&gt;&gt;&gt;&gt;&gt; version
&gt;&gt;&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example
&gt;&gt;&gt;&gt;&gt;&gt; is
&gt;&gt;&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call,
&gt;&gt;&gt;&gt;&gt;&gt; how
&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up
to
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt;&gt;&gt; well
&gt;&gt;&gt;&gt;&gt; if the form parts are 
&gt;&gt;&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt;&gt;&gt; stateful
&gt;&gt;&gt;&gt;&gt; pages because you can 
&gt;&gt;&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    ...
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt;&gt;&gt; something
&gt;&gt;&gt;&gt;&gt; like this:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; contentType here
&gt;&gt;&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;&gt;&gt;      try {
&gt;&gt;&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by
&gt;&gt;&gt;&gt;&gt; setting
&gt;&gt;&gt;&gt;&gt; path to null
&gt;&gt;&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;&gt;&gt;      }
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; The above method is probably better off in a utility class or the
&gt;&gt;&gt;&gt;&gt; border
&gt;&gt;&gt;&gt;&gt; page.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for
&gt;&gt;&gt;&gt;&gt;&gt; example
&gt;&gt;&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute
&gt;&gt;&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section
of
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select
&gt;&gt;&gt;&gt;&gt; control.
&gt;&gt;&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to
your
&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll
&gt;&gt;&gt;&gt;&gt;&gt;&gt; note
&gt;&gt;&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be
&gt;&gt;&gt;&gt;&gt;&gt;&gt; available
&gt;&gt;&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript
Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to
Ajax and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases.
For
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user
with
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page
which
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Prototype, 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless
by 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases,
but
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; in 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will
add
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; fields
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation
on
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation
on the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields
added with
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and
their
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; values 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful
Pages, 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; vs 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the
Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events
are
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; called 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; request.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new
stateful
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free
to post
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have
to change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both
Ajax and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is
called
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax
requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks
like in
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; order
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to
support the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses
Click 1.5 to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial
form)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using
Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; controls) 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very
minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript,
no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do
what we are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we
are not 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial
form is 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent
selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the
dependant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components
(except
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click.
Simply invoke
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the
method 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter.
Or you
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here
are some
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg:
HTML, JSON, XML.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser
you probably
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not
have the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to
null. Have a
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples
you can look
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components
but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and
need to incorporate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's
selection -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there
support for Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to
some examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am
struggling to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond -
really appreciate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4136572.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Stateful pages - examples?</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260317592910-4136472.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260317592910-4136472-post@n2-nabble-com%3e</id>
<updated>2009-12-09T00:13:12Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Ok. Thanks Bob! I'll try that.

Dipita

Bob Schellink-2 wrote:
&gt; 
&gt; I think the idea would be that control action events would add fields to
&gt; the Form, not the onInit
&gt; method. Otherwise, as you mentioned, Click throws the exception.
&gt; 
&gt; public AjaxPage extends Page {
&gt; 
&gt;    private ActionLink more = new ActionLink("more", this, "onMoreClick");
&gt;    private Form form = new Form("form");
&gt; 
&gt;    public boolean onMoreClick() {
&gt;      TextField field = new TextField("name");
&gt;      form.add(field);
&gt; 
&gt;      renderControl(field);
&gt;    }
&gt; 
&gt;    private void renderControl(Control c) {
&gt;       ...
&gt;       HttpServletResponse response = getContext().getResponse();
&gt; 
&gt;       //write the control to the response
&gt;       ...
&gt;       setPath(null);
&gt;    }
&gt; }
&gt; 
&gt; 
&gt; onMoreClick is only called when the link is clicked so you shouldn't
&gt; receive the exception if the 
&gt; Form is submitted.
&gt; 
&gt; That said this discussion is making me think that controls might be better
&gt; off not throwing the 
&gt; exception and instead return silently.
&gt; 
&gt; You can implement this in a custom Form implementation:
&gt; 
&gt; public AjaxForm extends Form {
&gt; 
&gt;    @Override
&gt;    public Control insert(Control control, int index) {
&gt;      // Return if form contains control
&gt;      if (getControlMap().contains(control.getName()) {
&gt;        return control;
&gt;      }
&gt; 
&gt;      // Else insert control
&gt;      super.insert(control, index);
&gt;    }
&gt; }
&gt; 
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt; dshah wrote:
&gt;&gt; Hi,
&gt;&gt; Are there any examples with stateful pages?  
&gt;&gt; 
&gt;&gt; I have a test case where I have one page (A) that is stateful and I call
&gt;&gt; another page(B) (via ajax) to load section of a form that is a member of
&gt;&gt; page A.  I have put all the construction of control objects on the
&gt;&gt; onInit()
&gt;&gt; method.. All works fine when to render this pages but when I click on a
&gt;&gt; button to submit the form, I get an error that the "form already contains
&gt;&gt; field".. How can we use stateful pages with form where you want to create
&gt;&gt; the field controls on the onInit() method (since they may change based on
&gt;&gt; user input..)
&gt;&gt; 
&gt;&gt; Here is what my code looks like:
&gt;&gt; Page A: (AjaxTestPage.java)
&gt;&gt; public class AjaxTestPage extends Page
&gt;&gt; {
&gt;&gt; 	
&gt;&gt; 	public Form form =  new Form("form");
&gt;&gt; 	Submit addToOrderSubmit = new Submit("addThisToOrder", this,
&gt;&gt; "onAddThisToOrder");
&gt;&gt; 	
&gt;&gt; 	public AjaxTestPage()
&gt;&gt; 	{
&gt;&gt; 		setStateful(true);
&gt;&gt; 		
&gt;&gt; 	}
&gt;&gt; 	public void onInit()
&gt;&gt; 	{
&gt;&gt; 		super.onInit();
&gt;&gt; 		addMinMaxDropDownsToForm();
&gt;&gt; 		form.add(addToOrderSubmit);
&gt;&gt; 	}
&gt;&gt; 	
&gt;&gt; 	private void addMinMaxDropDownsToForm()
&gt;&gt; 	{
&gt;&gt; 		SelectGroup sg = new SelectGroup("selectOption");
&gt;&gt; 		sg.setLabel("SelectGroupLabel");
&gt;&gt; 		sg.setName("SelectGroupName");
&gt;&gt; 		for (int i = 0; i &lt; 10; i++) {
&gt;&gt; 			String name = "Name" + i;
&gt;&gt; 			Integer intI = new Integer(i);
&gt;&gt; 			String intString = intI.toString();
&gt;&gt; 			Select select = new Select(intString, name);
&gt;&gt; 			select.setWidth("30");
&gt;&gt; 			//select.setAttribute("onChange", "selectMinMaxCondiment('" + i	+
&gt;&gt; "')");
&gt;&gt; 			for (int j = 0; j &lt;= 2; j++) {
&gt;&gt; 				select.add(new Option(String.valueOf(j), String.valueOf(j)));
&gt;&gt; 			}
&gt;&gt; 			sg.add(select);	
&gt;&gt; 		}
&gt;&gt; 		form.add(sg);
&gt;&gt; 	}
&gt;&gt; 	
&gt;&gt; 	public boolean onAddThisToOrder() 
&gt;&gt; 	{ 
&gt;&gt;            //do something here
&gt;&gt;         }
&gt;&gt;        public Form getForm() {
&gt;&gt; 		return this.form;
&gt;&gt; 	}
&gt;&gt; }
&gt;&gt; 
&gt;&gt; Page B (AjaxTestPopulate.java) which populate a new control on the form:
&gt;&gt; public class AjaxTestPopulate extends Page {
&gt;&gt; 
&gt;&gt; 	public CheckList childList = null;
&gt;&gt; 	public Form form = null;
&gt;&gt; 	
&gt;&gt; 	public AjaxTestPopulate() {
&gt;&gt; 		
&gt;&gt; 	}
&gt;&gt; 	
&gt;&gt; 	@Override
&gt;&gt; 	public void onInit() {
&gt;&gt; 		childList = getChildList(); 
&gt;&gt; 		form = getParentForm();
&gt;&gt; 		form.add(childList);
&gt;&gt; 	}
&gt;&gt; 	public Form getParentForm() {
&gt;&gt; 		AjaxTestPage page = (AjaxTestPage)
&gt;&gt; getContext().getSessionAttribute(AjaxTestPage.class.getName()); 
&gt;&gt; 	    return page.getForm(); 
&gt;&gt; 	}
&gt;&gt; 	public CheckList getChildList() {
&gt;&gt; 		childList = new CheckList();
&gt;&gt; 		childList.setLabel("checkListName");
&gt;&gt; 		childList.setName("checkListName");
&gt;&gt; 		childList.setHeight(null);
&gt;&gt; 		childList.setSortable(false);
&gt;&gt; 		for (int i= 0; i &lt; 2; i++) {
&gt;&gt; 			
&gt;&gt; 			Option select = new Option("selectionGroupChildId",  "name"+i);
&gt;&gt; 			childList.add(select);
&gt;&gt; 		}
&gt;&gt; 		return childList;
&gt;&gt; 	}
&gt;&gt; 
&gt;&gt;     public String getContentType() {
&gt;&gt;         return "text/html; charset=UTF-8";
&gt;&gt;     }
&gt;&gt; 
&gt;&gt; }
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Any idea how to do this using stateful pages?
&gt;&gt; 
&gt;&gt; Dipita
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Stateful-pages-examples-tp4134634p4136472.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EE96C.8090201@gmail.com%3e"/>
<id>urn:uuid:%3c4B1EE96C-8090201@gmail-com%3e</id>
<updated>2009-12-09T00:03:56Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Yep, see my previous mail on creating a custom Form and overriding the #insert method to return

silently (might be a better default than throwing an exception).

Alternatively you can check if the control exists before adding it:

public void onInit() {
   Field field = new TextField("name");

   if (! form.getControlMap().contains(field.getName())) {
     form.add(field);
   }
}


kind regards

bob


dshah wrote:
&gt; Hi Bob,
&gt; What you are saying makes sense (regarding using javascript to add the
&gt; fields to the form once I figure out which ones were newly added etc) -
&gt; however, basically using stateful pages is not working for me - we cannot
&gt; create the controls on the main page in the constructor since those are
&gt; dynamically created based on the user selection. Because of this limitation,
&gt; if I make the page stateful, the next time the onInit() method is called
&gt; (e.g. when a submit button for the form is clicked,) I am getting an error
&gt; saying the field (the one that is created and initialized on the onInit
&gt; method) already exists in the form..
&gt; 
&gt; How would we get around this problem?
&gt; 
&gt; Once again, thanks for all your help - I appreciate the prompt and very
&gt; explanatory emails.
&gt; Dipita
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; dshah wrote:
&gt;&gt;&gt; If I have a page (say A) that has a form with some controls (say A1), and
&gt;&gt;&gt; I
&gt;&gt;&gt; have another page (say B) which has another control (say B1).  I use ajax
&gt;&gt;&gt; to
&gt;&gt;&gt; render page B's control.  However, I don't see that control on the server
&gt;&gt;&gt; side for Page A -- as Bob has explained below, it's because the server is
&gt;&gt;&gt; not aware of this render that happened on the client.  Question is - is
&gt;&gt;&gt; getting a handle of the form on Page A and adding control B1 to that form
&gt;&gt;&gt; the only way to make the server aware of this new control that was added?  
&gt;&gt;
&gt;&gt; Basically yes. You either have to access the Form from a stateful Page, or
&gt;&gt; place the Form directly 
&gt;&gt; in the HttpSession and access it from there.
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; Is there any other way to do this -- basically, if we are going to add
&gt;&gt;&gt; the
&gt;&gt;&gt; control B1 o Page A's form object, then the whole form is being sent back
&gt;&gt;&gt; to/from the client (browser) and server right?  I am wondering is there a
&gt;&gt;&gt; way to not have to send the whole form back/forth from the client/browser
&gt;&gt;&gt; (technically it doesn't seem possible to me but I am not so clear about
&gt;&gt;&gt; all
&gt;&gt;&gt; this..)
&gt;&gt;
&gt;&gt; Sending back the whole Form is probably easiest because Form will include
&gt;&gt; all the markup to render 
&gt;&gt; the controls. But you can send back only the Field/Fields/FieldSet you
&gt;&gt; added, no need to render the 
&gt;&gt; whole Form. You can use your JS library to append the returned
&gt;&gt; Field/Fields/FieldSet to the Form. 
&gt;&gt; Just remember that Form lay out its controls in a grid using the &lt;table&gt;
&gt;&gt; element. So very likely you 
&gt;&gt; will want to wrap your returned Fields inside &lt;tr&gt; elements as well.
&gt;&gt;
&gt;&gt; Hope that make sense :)
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; Thoughts?
&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt;&gt; official
&gt;&gt;&gt;&gt; 2.1.0 final release.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt;&gt; well
&gt;&gt;&gt;&gt; if the form parts are 
&gt;&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt;&gt; stateful
&gt;&gt;&gt;&gt; pages because you can 
&gt;&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    ...
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt;&gt; something
&gt;&gt;&gt;&gt; like this:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; contentType here
&gt;&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;&gt;      try {
&gt;&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by
&gt;&gt;&gt;&gt; setting
&gt;&gt;&gt;&gt; path to null
&gt;&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;&gt;      }
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt;&gt;&gt; page.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll
&gt;&gt;&gt;&gt;&gt;&gt; note
&gt;&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the
Ajax
&gt;&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases.
For
&gt;&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and

&gt;&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless
by 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases,
but in 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add
fields
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation
on the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on
the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added
with
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their
values 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages,

&gt;&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
vs 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page

&gt;&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are
called 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every
request.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to
post
&gt;&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to
change
&gt;&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called
for 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like
in order
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click
1.5 to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial
form) -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click
controls) 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript,
no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what
we are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are
not 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form
is 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant
would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components
(except for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply
invoke a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter.
Or you can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here
are some
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML,
JSON, XML.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you
probably want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have
the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null.
Have a
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you
can look at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components
but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need
to incorporate a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's
selection -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support
for Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some
examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really
appreciate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Where can we download ClickClick?</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EE44D.9090603@gmail.com%3e"/>
<id>urn:uuid:%3c4B1EE44D-9090603@gmail-com%3e</id>
<updated>2009-12-08T23:42:05Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Sven Pfeiffer wrote:
&gt; Hi Bob,
&gt; 
&gt; will this build also be available as maven-artifact?
&gt; Because currently we have to build and install the artifacts manually.


I'm not sure how maven works but maybe we can leverage sourceforge, which is currently setup
to push 
"net.sf.click" artifacts to maven? Or we'll need to add a separate artifact for "net.sf.clickclick".

kind regards

bob


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Stateful pages - examples?</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EE336.5040205@gmail.com%3e"/>
<id>urn:uuid:%3c4B1EE336-5040205@gmail-com%3e</id>
<updated>2009-12-08T23:37:26Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I think the idea would be that control action events would add fields to the Form, not the
onInit
method. Otherwise, as you mentioned, Click throws the exception.

public AjaxPage extends Page {

   private ActionLink more = new ActionLink("more", this, "onMoreClick");
   private Form form = new Form("form");

   public boolean onMoreClick() {
     TextField field = new TextField("name");
     form.add(field);

     renderControl(field);
   }

   private void renderControl(Control c) {
      ...
      HttpServletResponse response = getContext().getResponse();

      //write the control to the response
      ...
      setPath(null);
   }
}


onMoreClick is only called when the link is clicked so you shouldn't receive the exception
if the 
Form is submitted.

That said this discussion is making me think that controls might be better off not throwing
the 
exception and instead return silently.

You can implement this in a custom Form implementation:

public AjaxForm extends Form {

   @Override
   public Control insert(Control control, int index) {
     // Return if form contains control
     if (getControlMap().contains(control.getName()) {
       return control;
     }

     // Else insert control
     super.insert(control, index);
   }
}


kind regards

bob


dshah wrote:
&gt; Hi,
&gt; Are there any examples with stateful pages?  
&gt; 
&gt; I have a test case where I have one page (A) that is stateful and I call
&gt; another page(B) (via ajax) to load section of a form that is a member of
&gt; page A.  I have put all the construction of control objects on the onInit()
&gt; method.. All works fine when to render this pages but when I click on a
&gt; button to submit the form, I get an error that the "form already contains
&gt; field".. How can we use stateful pages with form where you want to create
&gt; the field controls on the onInit() method (since they may change based on
&gt; user input..)
&gt; 
&gt; Here is what my code looks like:
&gt; Page A: (AjaxTestPage.java)
&gt; public class AjaxTestPage extends Page
&gt; {
&gt; 	
&gt; 	public Form form =  new Form("form");
&gt; 	Submit addToOrderSubmit = new Submit("addThisToOrder", this,
&gt; "onAddThisToOrder");
&gt; 	
&gt; 	public AjaxTestPage()
&gt; 	{
&gt; 		setStateful(true);
&gt; 		
&gt; 	}
&gt; 	public void onInit()
&gt; 	{
&gt; 		super.onInit();
&gt; 		addMinMaxDropDownsToForm();
&gt; 		form.add(addToOrderSubmit);
&gt; 	}
&gt; 	
&gt; 	private void addMinMaxDropDownsToForm()
&gt; 	{
&gt; 		SelectGroup sg = new SelectGroup("selectOption");
&gt; 		sg.setLabel("SelectGroupLabel");
&gt; 		sg.setName("SelectGroupName");
&gt; 		for (int i = 0; i &lt; 10; i++) {
&gt; 			String name = "Name" + i;
&gt; 			Integer intI = new Integer(i);
&gt; 			String intString = intI.toString();
&gt; 			Select select = new Select(intString, name);
&gt; 			select.setWidth("30");
&gt; 			//select.setAttribute("onChange", "selectMinMaxCondiment('" + i	+ "')");
&gt; 			for (int j = 0; j &lt;= 2; j++) {
&gt; 				select.add(new Option(String.valueOf(j), String.valueOf(j)));
&gt; 			}
&gt; 			sg.add(select);	
&gt; 		}
&gt; 		form.add(sg);
&gt; 	}
&gt; 	
&gt; 	public boolean onAddThisToOrder() 
&gt; 	{ 
&gt;            //do something here
&gt;         }
&gt;        public Form getForm() {
&gt; 		return this.form;
&gt; 	}
&gt; }
&gt; 
&gt; Page B (AjaxTestPopulate.java) which populate a new control on the form:
&gt; public class AjaxTestPopulate extends Page {
&gt; 
&gt; 	public CheckList childList = null;
&gt; 	public Form form = null;
&gt; 	
&gt; 	public AjaxTestPopulate() {
&gt; 		
&gt; 	}
&gt; 	
&gt; 	@Override
&gt; 	public void onInit() {
&gt; 		childList = getChildList(); 
&gt; 		form = getParentForm();
&gt; 		form.add(childList);
&gt; 	}
&gt; 	public Form getParentForm() {
&gt; 		AjaxTestPage page = (AjaxTestPage)
&gt; getContext().getSessionAttribute(AjaxTestPage.class.getName()); 
&gt; 	    return page.getForm(); 
&gt; 	}
&gt; 	public CheckList getChildList() {
&gt; 		childList = new CheckList();
&gt; 		childList.setLabel("checkListName");
&gt; 		childList.setName("checkListName");
&gt; 		childList.setHeight(null);
&gt; 		childList.setSortable(false);
&gt; 		for (int i= 0; i &lt; 2; i++) {
&gt; 			
&gt; 			Option select = new Option("selectionGroupChildId",  "name"+i);
&gt; 			childList.add(select);
&gt; 		}
&gt; 		return childList;
&gt; 	}
&gt; 
&gt;     public String getContentType() {
&gt;         return "text/html; charset=UTF-8";
&gt;     }
&gt; 
&gt; }
&gt; 
&gt; 
&gt; Any idea how to do this using stateful pages?
&gt; 
&gt; Dipita



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260314775918-4136233.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260314775918-4136233-post@n2-nabble-com%3e</id>
<updated>2009-12-08T23:26:15Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi Bob,
What you are saying makes sense (regarding using javascript to add the
fields to the form once I figure out which ones were newly added etc) -
however, basically using stateful pages is not working for me - we cannot
create the controls on the main page in the constructor since those are
dynamically created based on the user selection. Because of this limitation,
if I make the page stateful, the next time the onInit() method is called
(e.g. when a submit button for the form is clicked,) I am getting an error
saying the field (the one that is created and initialized on the onInit
method) already exists in the form..

How would we get around this problem?

Once again, thanks for all your help - I appreciate the prompt and very
explanatory emails.
Dipita


Bob Schellink-2 wrote:
&gt; 
&gt; dshah wrote:
&gt;&gt; 
&gt;&gt; If I have a page (say A) that has a form with some controls (say A1), and
&gt;&gt; I
&gt;&gt; have another page (say B) which has another control (say B1).  I use ajax
&gt;&gt; to
&gt;&gt; render page B's control.  However, I don't see that control on the server
&gt;&gt; side for Page A -- as Bob has explained below, it's because the server is
&gt;&gt; not aware of this render that happened on the client.  Question is - is
&gt;&gt; getting a handle of the form on Page A and adding control B1 to that form
&gt;&gt; the only way to make the server aware of this new control that was added?  
&gt; 
&gt; 
&gt; Basically yes. You either have to access the Form from a stateful Page, or
&gt; place the Form directly 
&gt; in the HttpSession and access it from there.
&gt; 
&gt; 
&gt;&gt; Is there any other way to do this -- basically, if we are going to add
&gt;&gt; the
&gt;&gt; control B1 o Page A's form object, then the whole form is being sent back
&gt;&gt; to/from the client (browser) and server right?  I am wondering is there a
&gt;&gt; way to not have to send the whole form back/forth from the client/browser
&gt;&gt; (technically it doesn't seem possible to me but I am not so clear about
&gt;&gt; all
&gt;&gt; this..)
&gt; 
&gt; 
&gt; Sending back the whole Form is probably easiest because Form will include
&gt; all the markup to render 
&gt; the controls. But you can send back only the Field/Fields/FieldSet you
&gt; added, no need to render the 
&gt; whole Form. You can use your JS library to append the returned
&gt; Field/Fields/FieldSet to the Form. 
&gt; Just remember that Form lay out its controls in a grid using the &lt;table&gt;
&gt; element. So very likely you 
&gt; will want to wrap your returned Fields inside &lt;tr&gt; elements as well.
&gt; 
&gt; Hope that make sense :)
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt;&gt; 
&gt;&gt; Thoughts?
&gt;&gt; Dipita
&gt;&gt; 
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;
&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;
&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;
&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt; official
&gt;&gt;&gt; 2.1.0 final release.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;
&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt; well
&gt;&gt;&gt; if the form parts are 
&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt; stateful
&gt;&gt;&gt; pages because you can 
&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;
&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;
&gt;&gt;&gt;    ...
&gt;&gt;&gt;
&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build
&gt;&gt;&gt; the
&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;
&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt; something
&gt;&gt;&gt; like this:
&gt;&gt;&gt;
&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;
&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust
&gt;&gt;&gt; the
&gt;&gt;&gt; contentType here
&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;
&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;
&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;      try {
&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;
&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;
&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;
&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by
&gt;&gt;&gt; setting
&gt;&gt;&gt; path to null
&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;
&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;
&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;      }
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt;&gt; page.
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;
&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;
&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;
&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;
&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll
&gt;&gt;&gt;&gt;&gt; note
&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and

&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by

&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but
in 
&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields
&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on
the 
&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the

&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values

&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages,

&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
vs 
&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called

&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful
&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and

&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called
for 
&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in
order
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5
to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form)
-
&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we
are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not

&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is

&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant
would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except
for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply
invoke a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or
you can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are
some
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON,
XML.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably
want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the
default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null.
Have a
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can
look at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but
it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to
incorporate a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
-
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support
for Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples
or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really
appreciate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4136233.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Where can we download ClickClick?</title>
<author><name>Sven Pfeiffer &lt;sven.pfeiffer@madsep.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EE092.5010406@madsep.de%3e"/>
<id>urn:uuid:%3c4B1EE092-5010406@madsep-de%3e</id>
<updated>2009-12-08T23:26:10Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Bob,

will this build also be available as maven-artifact?
Because currently we have to build and install the artifacts manually.


Bob Schellink wrote:
&gt; dshah wrote:
&gt;&gt; Ok Thanks SVen -- we'll try that out.
&gt;
&gt;
&gt; Once 2.1.0 is out, I'll put up a build for ClickClick.
&gt;



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Where can we download ClickClick?</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EDD62.40208@gmail.com%3e"/>
<id>urn:uuid:%3c4B1EDD62-40208@gmail-com%3e</id>
<updated>2009-12-08T23:12:34Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
dshah wrote:
&gt; Ok Thanks SVen -- we'll try that out.


Once 2.1.0 is out, I'll put up a build for ClickClick.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1EDD12.2020403@gmail.com%3e"/>
<id>urn:uuid:%3c4B1EDD12-2020403@gmail-com%3e</id>
<updated>2009-12-08T23:11:14Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
dshah wrote:
&gt; 
&gt; If I have a page (say A) that has a form with some controls (say A1), and I
&gt; have another page (say B) which has another control (say B1).  I use ajax to
&gt; render page B's control.  However, I don't see that control on the server
&gt; side for Page A -- as Bob has explained below, it's because the server is
&gt; not aware of this render that happened on the client.  Question is - is
&gt; getting a handle of the form on Page A and adding control B1 to that form
&gt; the only way to make the server aware of this new control that was added?  


Basically yes. You either have to access the Form from a stateful Page, or place the Form
directly 
in the HttpSession and access it from there.


&gt; Is there any other way to do this -- basically, if we are going to add the
&gt; control B1 o Page A's form object, then the whole form is being sent back
&gt; to/from the client (browser) and server right?  I am wondering is there a
&gt; way to not have to send the whole form back/forth from the client/browser
&gt; (technically it doesn't seem possible to me but I am not so clear about all
&gt; this..)


Sending back the whole Form is probably easiest because Form will include all the markup to
render 
the controls. But you can send back only the Field/Fields/FieldSet you added, no need to render
the 
whole Form. You can use your JS library to append the returned Field/Fields/FieldSet to the
Form. 
Just remember that Form lay out its controls in a grid using the &lt;table&gt; element. So
very likely you 
will want to wrap your returned Fields inside &lt;tr&gt; elements as well.

Hope that make sense :)

kind regards

bob


&gt; 
&gt; Thoughts?
&gt; Dipita
&gt; 
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; Hi Dipita,
&gt;&gt;
&gt;&gt; dshah wrote:
&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;
&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt; So if you want to use 2.1.0 
&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;
&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;
&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt; moving our infrastructure 
&gt;&gt; from the incubator to TLP. Once this is done we will push out the official
&gt;&gt; 2.1.0 final release.
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version of
&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt; doing
&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt; does
&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt; suggested
&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt; another
&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt;&gt; same form element?
&gt;&gt;
&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt; information such as a Table 
&gt;&gt; etc. For your case (building up a form on the server) this won't work well
&gt;&gt; if the form parts are 
&gt;&gt; built in a separate Page. Technically this is possible when using stateful
&gt;&gt; pages because you can 
&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;
&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;
&gt;&gt;    ...
&gt;&gt;
&gt;&gt;    public FormPage getForm() {
&gt;&gt;      FormPage page = (FormPage)
&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;      return page.getForm();
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; However its probably easier to call back to FormPage itself and build the
&gt;&gt; Form with every call.
&gt;&gt;
&gt;&gt; You can create a helper method to render your partial responses, something
&gt;&gt; like this:
&gt;&gt;
&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;
&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt;&gt; contentType here
&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;
&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;
&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;      try {
&gt;&gt;          Context context = getContext();
&gt;&gt;          String partial = context.renderTemplate(template, templateModel);
&gt;&gt;
&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;
&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;
&gt;&gt;          // NB: Specify no further rendering required by Click by setting
&gt;&gt; path to null
&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;          setPath(null);
&gt;&gt;
&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;
&gt;&gt;      } finally {
&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;      }
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt; page.
&gt;&gt;
&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt; select.value);
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt; the
&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt; form
&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;
&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt; In Ajax terms this is 
&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;
&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt; AjaxSelect class:
&gt;&gt;
&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;
&gt;&gt;    public void onInit() {
&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks!
&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in

&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields
to 
&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the

&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values

&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs

&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called

&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page

&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for

&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order
to 
&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to

&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form)
-
&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are

&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
and 
&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would

&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except
for
&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you
can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some
things
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON,
XML. So
&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably
want to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have
a look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look
at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for
Ajax with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples
or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate
it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Where can we download ClickClick?</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260311477281-4135898.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260311477281-4135898-post@n2-nabble-com%3e</id>
<updated>2009-12-08T22:31:17Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Ok Thanks SVen -- we'll try that out.

Dipita

sven.pfeiffer wrote:
&gt; 
&gt; Hi Dipita,
&gt; 
&gt; as far as I know there are currently no binary artifacts to download.
&gt; 
&gt; You can checkout the sources as described here: 
&gt; http://code.google.com/p/clickclick/source/checkout
&gt; 
&gt; To build them you simply need to run ant as described in the README.html
&gt; 
&gt; Hope this helps
&gt; SVen
&gt; 
&gt; 
&gt; dshah wrote:
&gt;&gt; Does anyone know if we can download code/version of ClickClick to
&gt;&gt; test/understand how to use it?
&gt;&gt;
&gt;&gt; Thanks!
&gt;&gt; Dipita
&gt;&gt;   
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Where-can-we-download-ClickClick-tp4135820p4135898.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Where can we download ClickClick?</title>
<author><name>Sven Pfeiffer &lt;sven.pfeiffer@madsep.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1ED21C.6010608@madsep.de%3e"/>
<id>urn:uuid:%3c4B1ED21C-6010608@madsep-de%3e</id>
<updated>2009-12-08T22:24:28Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Dipita,

as far as I know there are currently no binary artifacts to download.

You can checkout the sources as described here: 
http://code.google.com/p/clickclick/source/checkout

To build them you simply need to run ant as described in the README.html

Hope this helps
SVen


dshah wrote:
&gt; Does anyone know if we can download code/version of ClickClick to
&gt; test/understand how to use it?
&gt;
&gt; Thanks!
&gt; Dipita
&gt;   



</pre>
</div>
</content>
</entry>
<entry>
<title>Where can we download ClickClick?</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260310629124-4135820.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260310629124-4135820-post@n2-nabble-com%3e</id>
<updated>2009-12-08T22:17:09Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Does anyone know if we can download code/version of ClickClick to
test/understand how to use it?

Thanks!
Dipita
-- 
View this message in context: http://n2.nabble.com/Where-can-we-download-ClickClick-tp4135820p4135820.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Stateful pages - examples?</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260300037888-4134634.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260300037888-4134634-post@n2-nabble-com%3e</id>
<updated>2009-12-08T19:20:37Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi,
Are there any examples with stateful pages?  

I have a test case where I have one page (A) that is stateful and I call
another page(B) (via ajax) to load section of a form that is a member of
page A.  I have put all the construction of control objects on the onInit()
method.. All works fine when to render this pages but when I click on a
button to submit the form, I get an error that the "form already contains
field".. How can we use stateful pages with form where you want to create
the field controls on the onInit() method (since they may change based on
user input..)

Here is what my code looks like:
Page A: (AjaxTestPage.java)
public class AjaxTestPage extends Page
{
	
	public Form form =  new Form("form");
	Submit addToOrderSubmit = new Submit("addThisToOrder", this,
"onAddThisToOrder");
	
	public AjaxTestPage()
	{
		setStateful(true);
		
	}
	public void onInit()
	{
		super.onInit();
		addMinMaxDropDownsToForm();
		form.add(addToOrderSubmit);
	}
	
	private void addMinMaxDropDownsToForm()
	{
		SelectGroup sg = new SelectGroup("selectOption");
		sg.setLabel("SelectGroupLabel");
		sg.setName("SelectGroupName");
		for (int i = 0; i &lt; 10; i++) {
			String name = "Name" + i;
			Integer intI = new Integer(i);
			String intString = intI.toString();
			Select select = new Select(intString, name);
			select.setWidth("30");
			//select.setAttribute("onChange", "selectMinMaxCondiment('" + i	+ "')");
			for (int j = 0; j &lt;= 2; j++) {
				select.add(new Option(String.valueOf(j), String.valueOf(j)));
			}
			sg.add(select);	
		}
		form.add(sg);
	}
	
	public boolean onAddThisToOrder() 
	{ 
           //do something here
        }
       public Form getForm() {
		return this.form;
	}
}

Page B (AjaxTestPopulate.java) which populate a new control on the form:
public class AjaxTestPopulate extends Page {

	public CheckList childList = null;
	public Form form = null;
	
	public AjaxTestPopulate() {
		
	}
	
	@Override
	public void onInit() {
		childList = getChildList(); 
		form = getParentForm();
		form.add(childList);
	}
	public Form getParentForm() {
		AjaxTestPage page = (AjaxTestPage)
getContext().getSessionAttribute(AjaxTestPage.class.getName()); 
	    return page.getForm(); 
	}
	public CheckList getChildList() {
		childList = new CheckList();
		childList.setLabel("checkListName");
		childList.setName("checkListName");
		childList.setHeight(null);
		childList.setSortable(false);
		for (int i= 0; i &lt; 2; i++) {
			
			Option select = new Option("selectionGroupChildId",  "name"+i);
			childList.add(select);
		}
		return childList;
	}

    public String getContentType() {
        return "text/html; charset=UTF-8";
    }

}


Any idea how to do this using stateful pages?

Dipita
-- 
View this message in context: http://n2.nabble.com/Stateful-pages-examples-tp4134634p4134634.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260296582333-4134265.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260296582333-4134265-post@n2-nabble-com%3e</id>
<updated>2009-12-08T18:23:02Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi Bob et Al,
I am asking this question again to confirm that this is my only option..

If I have a page (say A) that has a form with some controls (say A1), and I
have another page (say B) which has another control (say B1).  I use ajax to
render page B's control.  However, I don't see that control on the server
side for Page A -- as Bob has explained below, it's because the server is
not aware of this render that happened on the client.  Question is - is
getting a handle of the form on Page A and adding control B1 to that form
the only way to make the server aware of this new control that was added?  

Is there any other way to do this -- basically, if we are going to add the
control B1 o Page A's form object, then the whole form is being sent back
to/from the client (browser) and server right?  I am wondering is there a
way to not have to send the whole form back/forth from the client/browser
(technically it doesn't seem possible to me but I am not so clear about all
this..)

Thoughts?
Dipita



Bob Schellink-2 wrote:
&gt; 
&gt; Hi Dipita,
&gt; 
&gt; dshah wrote:
&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt; 
&gt; 
&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt; So if you want to use 2.1.0 
&gt; I suggest you just build it from trunk:
&gt; 
&gt; c:\dev\click&gt;svn co
&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt; c:\dev\click&gt;cd build
&gt; c:\dev\click\build&gt;ant get-deps
&gt; c:\dev\click\build&gt;ant build-distribution
&gt; 
&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt; moving our infrastructure 
&gt; from the incubator to TLP. Once this is done we will push out the official
&gt; 2.1.0 final release.
&gt; 
&gt; 
&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version of
&gt;&gt; Click and  have a couple of questions:
&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt; doing
&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt; does
&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt; suggested
&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt; another
&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt; same form element?
&gt; 
&gt; 
&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt; information such as a Table 
&gt; etc. For your case (building up a form on the server) this won't work well
&gt; if the form parts are 
&gt; built in a separate Page. Technically this is possible when using stateful
&gt; pages because you can 
&gt; retrieve the stateful page from the session:
&gt; 
&gt; public AjaxPage extends BorderPage {
&gt; 
&gt;    ...
&gt; 
&gt;    public FormPage getForm() {
&gt;      FormPage page = (FormPage)
&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;      return page.getForm();
&gt;    }
&gt; }
&gt; 
&gt; However its probably easier to call back to FormPage itself and build the
&gt; Form with every call.
&gt; 
&gt; You can create a helper method to render your partial responses, something
&gt; like this:
&gt; 
&gt; public FormPage extends BorderPage {
&gt; 
&gt;    public void renderPartial(String template, Map templateModel) {
&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt; contentType here
&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt; 
&gt;      response.setHeader("Pragma", "no-cache");
&gt; 
&gt;      OutputStream outputStream = null;
&gt;      try {
&gt;          Context context = getContext();
&gt;          String partial = context.renderTemplate(template, templateModel);
&gt; 
&gt;          outputStream = context.getResponse().getOutputStream();
&gt; 
&gt;          IOUtils.write(partial, outputStream);
&gt; 
&gt;          // NB: Specify no further rendering required by Click by setting
&gt; path to null
&gt;          // Thus Click won't render the Page default template form.htm
&gt;          setPath(null);
&gt; 
&gt;      } catch (IOException ioe) {
&gt;          throw new RuntimeException(ioe);
&gt; 
&gt;      } finally {
&gt;          IOUtils.closeQuietly(outputStream);
&gt;      }
&gt;    }
&gt; }
&gt; 
&gt; The above method is probably better off in a utility class or the border
&gt; page.
&gt; 
&gt;&gt; 
&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt; 
&gt;&gt; &lt;script type='text/javascript'
&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt; &lt;script type='text/javascript'
&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt; function registerAjax() {
&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt; }
&gt;&gt; 
&gt;&gt; function onCustomerChange(select) {
&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt; select.value);
&gt;&gt; }
&gt;&gt; 
&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt; &lt;/script&gt;
&gt;&gt; 
&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt; the
&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt; form
&gt;&gt; e.g. using JQuery's load event or something like that?
&gt; 
&gt; 
&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt; In Ajax terms this is 
&gt; called "inline event handling" while the register approach is called
&gt; "unobtrusive JavaScript", 
&gt; meaning the the markup doesn't have any behavior specified.
&gt; 
&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt; AjaxSelect class:
&gt; 
&gt; public CustomerAjaxSelect extends Select {
&gt; 
&gt;    public void onInit() {
&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;    }
&gt; }
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt;&gt; 
&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt; 
&gt;&gt; Thanks!
&gt;&gt; Dipita
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt; needs.
&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt; when
&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt; submitted.
&gt;&gt;&gt;
&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;
&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt; logic
&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;
&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype, 
&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in 
&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields to 
&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the 
&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values 
&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs 
&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called 
&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page 
&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for 
&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order to

&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to 
&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form) -
&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are 
&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection) and

&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would

&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke
a 
&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you can

&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some things
&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML.
So
&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably want
to 
&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default
&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have a look

&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it
&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax
with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to
get any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate
it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4134265.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: moving from Apache incubator to Apache Top Level project</title>
<author><name>&quot;Adrian A.&quot; &lt;a.adrian.tech@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3chfm2st$ida$1@ger.gmane.org%3e"/>
<id>urn:uuid:%3chfm2st$ida$1@ger-gmane-org%3e</id>
<updated>2009-12-08T17:37:32Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
&gt; I was wondering the move from Click to be an Apache Incubator to Apache Top
&gt; Level Project -- will that change the package structure of the code?  We are
&gt; trying to investigate using 2.1.0 and we noticed using that in 2.1.0, the
&gt; package structure is now org.apache... and  before it used to be
&gt; net.sf.click..
The package change from net.sf.* was due to the migration from 
Sourceforge to Apache.org.

Moving to Apache TLP *won't change* the java package, only the JAR file 
names: they won't contain the "incubating" word anymore:
click-2.1.0-incubating.jar -&gt; click-2.1.0.jar

Adrian.



</pre>
</div>
</content>
</entry>
<entry>
<title>moving from Apache incubator to Apache Top Level project</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260283397046-4132846.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260283397046-4132846-post@n2-nabble-com%3e</id>
<updated>2009-12-08T14:43:17Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi,
I was wondering the move from Click to be an Apache Incubator to Apache Top
Level Project -- will that change the package structure of the code?  We are
trying to investigate using 2.1.0 and we noticed using that in 2.1.0, the
package structure is now org.apache... and  before it used to be
net.sf.click..

Thoughts?
Dipita
-- 
View this message in context: http://n2.nabble.com/moving-from-Apache-incubator-to-Apache-Top-Level-project-tp4132846p4132846.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1DF920.2060208@gmail.com%3e"/>
<id>urn:uuid:%3c4B1DF920-2060208@gmail-com%3e</id>
<updated>2009-12-08T06:58:40Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Dipita,

The AjaxTestPage constructor isn't public. Change it to:

public class AjaxTestPopulate extends Page {

   public CheckList childList;
	
   // Constructor must be public
   public AjaxTestPopulate() {
     childList = getChildList();
     childList.setName("checkListName");
   }
}

kind regards

bob

dshah wrote:
&gt; Hi Bob,
&gt; Yes, the select on AjaxTestPage is using ajax to load
&gt; "ajax-test-populate.htm"..
&gt; 
&gt; I did as you suggested (first option of getting the childList in the
&gt; construction of AjaxTestPopulate.java,) howver now I am getting an error
&gt; when the page is rendering -- the log says
&gt; (java.lang.IllegalAccessException: Class net.sf.click.ClickServlet can not
&gt; access a member of class strive.solutions.page.AjaxTestPopulate with
&gt; modifiers "") - any ideas what this means -- I am uploading the modifified
&gt; AjaxTestPopulate.java reference.
&gt; 
&gt; Thanks!
&gt; Dipita http://n2.nabble.com/file/n4130831/AjaxTestPopulate.java
&gt; AjaxTestPopulate.java 
&gt; 
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; dshah wrote:
&gt;&gt;&gt; I have a test example that I am testing by just sending a request to load
&gt;&gt;&gt; part of the data based on a selection.. This is based on the example of
&gt;&gt;&gt; ajax-select demo in the 1.5.  However, whenever I select something on the
&gt;&gt;&gt; parent, the data is not rendering on the child (it's showing as though
&gt;&gt;&gt; the
&gt;&gt;&gt; values are null) - anyone figure out what I am doing wrong? 
&gt;&gt;
&gt;&gt; I assume the Select on AjaxTestPage uses Ajax to pull the CheckList from
&gt;&gt; AjaxTestPopulate right?
&gt;&gt;
&gt;&gt; Looking at AjaxTestPopulate the problem seems to be with the use of
&gt;&gt; autobinding. I recommend *not*
&gt;&gt; using the autobinding feature if you are new to Click. Quite a bit of
&gt;&gt; magic is involved which can be
&gt;&gt; confusing.
&gt;&gt;
&gt;&gt; Just to explain what I think goes wrong with autobinding in this example:
&gt;&gt;
&gt;&gt; 1. Click creates the AjaxTestPopulate Page by invoking its default no-arg
&gt;&gt; constructor.
&gt;&gt; 2. Immediately after creating the Page, Click binds all public declared
&gt;&gt; fields to the Page as follows:
&gt;&gt; 2.1 Click checks if the field is null or not
&gt;&gt; 2.2 If the field is not null and its name is not set, Click sets the
&gt;&gt; control name to that of the field
&gt;&gt; 2.3 Lastly Click adds the Control to the Page control list
&gt;&gt;
&gt;&gt; The problem in AjaxTestPopulate is that after the Page constructor is
&gt;&gt; called, childList is still
&gt;&gt; null, since it is only created in the onGet page event.
&gt;&gt;
&gt;&gt; You can change the Page as follows:
&gt;&gt;
&gt;&gt; public class AjaxTestPopulate extends Page {
&gt;&gt;
&gt;&gt;    public CheckList childList;
&gt;&gt;
&gt;&gt;    public AjaxTestPopulate() {
&gt;&gt;      // Create the childList in the Page constructor. When autobinding
&gt;&gt; kicks off (after Page
&gt;&gt;      // construction) the childList control will be created and satisfy
&gt;&gt; #2.1 above
&gt;&gt;      childList = getChildList();
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt;
&gt;&gt; Alternatively you can use explicit binding:
&gt;&gt;
&gt;&gt; public class AjaxTestPopulate extends Page {
&gt;&gt;
&gt;&gt;    public CheckList childList;
&gt;&gt;
&gt;&gt;    public onGet() {
&gt;&gt;      childList = getChildList();
&gt;&gt;      childList.setName("childList");
&gt;&gt;      addControl(childList);
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; Attaching my files:
&gt;&gt;&gt; 1. ajax-test.htm is the main page
&gt;&gt;&gt; 2. ajax-test-populate.htm is the page I want to load partially after
&gt;&gt;&gt; something on the above is selected.
&gt;&gt;&gt; 3. AjaxTestPage.java - corresponding page for ajax-test.htm
&gt;&gt;&gt; 4. AjaxTestPopulate.java - corresponding page for ajax-test-populate.htm
&gt;&gt;&gt; 5. result html -  this is the html I am seeing when I select something on
&gt;&gt;&gt; ajax-test.htm..
&gt;&gt;&gt;
&gt;&gt;&gt; Any idea what i am doing wrong?
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks!
&gt;&gt;&gt; Dipita http://n2.nabble.com/file/n4127448/ajax-test.htm ajax-test.htm 
&gt;&gt;&gt; http://n2.nabble.com/file/n4127448/ajax-test-populate.htm
&gt;&gt;&gt; ajax-test-populate.htm 
&gt;&gt;&gt; http://n2.nabble.com/file/n4127448/AjaxTestPage.java
&gt;&gt;&gt; AjaxTestPage.java 
&gt;&gt;&gt; http://n2.nabble.com/file/n4127448/AjaxTestPopulate.java
&gt;&gt;&gt; AjaxTestPopulate.java 
&gt;&gt;&gt; http://n2.nabble.com/file/n4127448/resultant_html.jpg
&gt;&gt;&gt; resultant_html.jpg 
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt; Ok. Thanks. If we use the same formpage, then does the whole form get
&gt;&gt;&gt;&gt; sent
&gt;&gt;&gt;&gt; back from the Click Servlet to the browser or just the partial part that
&gt;&gt;&gt;&gt; was just gotten?  
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; One of our concerns is that we want to reduce the bandwidth used when
&gt;&gt;&gt;&gt; sending the form from the servlet to the browser and so ideally, we were
&gt;&gt;&gt;&gt; hoping to only load part of the form (i.e. have the servlet engine send
&gt;&gt;&gt;&gt; only that section of the form to the browser but somehow know that the
&gt;&gt;&gt;&gt; newly retrieved section belongs to the form that is already on the
&gt;&gt;&gt;&gt; browser..)  
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thoughts?
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0
&gt;&gt;&gt;&gt;&gt; final.
&gt;&gt;&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are
&gt;&gt;&gt;&gt;&gt; busy
&gt;&gt;&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt;&gt;&gt; official 2.1.0 final release.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example
is
&gt;&gt;&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call,
how
&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using
the
&gt;&gt;&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up
to
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt;&gt;&gt; well if the form parts are 
&gt;&gt;&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt;&gt;&gt; stateful pages because you can 
&gt;&gt;&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    ...
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt;&gt;&gt; something like this:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; contentType here
&gt;&gt;&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;&gt;&gt;      try {
&gt;&gt;&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by
&gt;&gt;&gt;&gt;&gt; setting
&gt;&gt;&gt;&gt;&gt; path to null
&gt;&gt;&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;&gt;&gt;      }
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; The above method is probably better off in a utility class or the
&gt;&gt;&gt;&gt;&gt; border
&gt;&gt;&gt;&gt;&gt; page.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for
&gt;&gt;&gt;&gt;&gt;&gt; example
&gt;&gt;&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute
of
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section
of
&gt;&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select
&gt;&gt;&gt;&gt;&gt; control.
&gt;&gt;&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to
your
&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll
&gt;&gt;&gt;&gt;&gt;&gt;&gt; note
&gt;&gt;&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript
Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to
Ajax and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases.
For
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user
with
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page
which
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as
Prototype, 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless
by 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases,
but in 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will
add fields
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation
on the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation
on the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields
added with
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and
their
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; values 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful
Pages, 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
vs 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the
Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events
are
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; called 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; request.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new
stateful
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free
to post
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have
to change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both
Ajax and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is
called
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax
requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks
like in order
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to
support the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses
Click 1.5 to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial
form) -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using
Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; controls) 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very
minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript,
no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do
what we are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we
are not 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial
form is 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent
selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the
dependant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components
(except
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click.
Simply invoke
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the
method 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter.
Or you can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here
are some
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg:
HTML, JSON, XML.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser
you probably want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not
have the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to
null. Have a
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples
you can look at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components
but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and
need to incorporate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's
selection -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there
support for Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to
some examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am
struggling to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond -
really appreciate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260255127053-4130831.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260255127053-4130831-post@n2-nabble-com%3e</id>
<updated>2009-12-08T06:52:07Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi Bob,
Yes, the select on AjaxTestPage is using ajax to load
"ajax-test-populate.htm"..

I did as you suggested (first option of getting the childList in the
construction of AjaxTestPopulate.java,) howver now I am getting an error
when the page is rendering -- the log says
(java.lang.IllegalAccessException: Class net.sf.click.ClickServlet can not
access a member of class strive.solutions.page.AjaxTestPopulate with
modifiers "") - any ideas what this means -- I am uploading the modifified
AjaxTestPopulate.java reference.

Thanks!
Dipita http://n2.nabble.com/file/n4130831/AjaxTestPopulate.java
AjaxTestPopulate.java 



Bob Schellink-2 wrote:
&gt; 
&gt; dshah wrote:
&gt;&gt; I have a test example that I am testing by just sending a request to load
&gt;&gt; part of the data based on a selection.. This is based on the example of
&gt;&gt; ajax-select demo in the 1.5.  However, whenever I select something on the
&gt;&gt; parent, the data is not rendering on the child (it's showing as though
&gt;&gt; the
&gt;&gt; values are null) - anyone figure out what I am doing wrong? 
&gt; 
&gt; 
&gt; I assume the Select on AjaxTestPage uses Ajax to pull the CheckList from
&gt; AjaxTestPopulate right?
&gt; 
&gt; Looking at AjaxTestPopulate the problem seems to be with the use of
&gt; autobinding. I recommend *not*
&gt; using the autobinding feature if you are new to Click. Quite a bit of
&gt; magic is involved which can be
&gt; confusing.
&gt; 
&gt; Just to explain what I think goes wrong with autobinding in this example:
&gt; 
&gt; 1. Click creates the AjaxTestPopulate Page by invoking its default no-arg
&gt; constructor.
&gt; 2. Immediately after creating the Page, Click binds all public declared
&gt; fields to the Page as follows:
&gt; 2.1 Click checks if the field is null or not
&gt; 2.2 If the field is not null and its name is not set, Click sets the
&gt; control name to that of the field
&gt; 2.3 Lastly Click adds the Control to the Page control list
&gt; 
&gt; The problem in AjaxTestPopulate is that after the Page constructor is
&gt; called, childList is still
&gt; null, since it is only created in the onGet page event.
&gt; 
&gt; You can change the Page as follows:
&gt; 
&gt; public class AjaxTestPopulate extends Page {
&gt; 
&gt;    public CheckList childList;
&gt; 
&gt;    public AjaxTestPopulate() {
&gt;      // Create the childList in the Page constructor. When autobinding
&gt; kicks off (after Page
&gt;      // construction) the childList control will be created and satisfy
&gt; #2.1 above
&gt;      childList = getChildList();
&gt;    }
&gt; }
&gt; 
&gt; 
&gt; Alternatively you can use explicit binding:
&gt; 
&gt; public class AjaxTestPopulate extends Page {
&gt; 
&gt;    public CheckList childList;
&gt; 
&gt;    public onGet() {
&gt;      childList = getChildList();
&gt;      childList.setName("childList");
&gt;      addControl(childList);
&gt;    }
&gt; }
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt;&gt; 
&gt;&gt; Attaching my files:
&gt;&gt; 1. ajax-test.htm is the main page
&gt;&gt; 2. ajax-test-populate.htm is the page I want to load partially after
&gt;&gt; something on the above is selected.
&gt;&gt; 3. AjaxTestPage.java - corresponding page for ajax-test.htm
&gt;&gt; 4. AjaxTestPopulate.java - corresponding page for ajax-test-populate.htm
&gt;&gt; 5. result html -  this is the html I am seeing when I select something on
&gt;&gt; ajax-test.htm..
&gt;&gt; 
&gt;&gt; Any idea what i am doing wrong?
&gt;&gt; 
&gt;&gt; Thanks!
&gt;&gt; Dipita http://n2.nabble.com/file/n4127448/ajax-test.htm ajax-test.htm 
&gt;&gt; http://n2.nabble.com/file/n4127448/ajax-test-populate.htm
&gt;&gt; ajax-test-populate.htm 
&gt;&gt; http://n2.nabble.com/file/n4127448/AjaxTestPage.java
&gt;&gt; AjaxTestPage.java 
&gt;&gt; http://n2.nabble.com/file/n4127448/AjaxTestPopulate.java
&gt;&gt; AjaxTestPopulate.java 
&gt;&gt; http://n2.nabble.com/file/n4127448/resultant_html.jpg
&gt;&gt; resultant_html.jpg 
&gt;&gt; 
&gt;&gt; 
&gt;&gt; 
&gt;&gt; dshah wrote:
&gt;&gt;&gt; Ok. Thanks. If we use the same formpage, then does the whole form get
&gt;&gt;&gt; sent
&gt;&gt;&gt; back from the Click Servlet to the browser or just the partial part that
&gt;&gt;&gt; was just gotten?  
&gt;&gt;&gt;
&gt;&gt;&gt; One of our concerns is that we want to reduce the bandwidth used when
&gt;&gt;&gt; sending the form from the servlet to the browser and so ideally, we were
&gt;&gt;&gt; hoping to only load part of the form (i.e. have the servlet engine send
&gt;&gt;&gt; only that section of the form to the browser but somehow know that the
&gt;&gt;&gt; newly retrieved section belongs to the form that is already on the
&gt;&gt;&gt; browser..)  
&gt;&gt;&gt;
&gt;&gt;&gt; Thoughts?
&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0
&gt;&gt;&gt;&gt; final.
&gt;&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are
&gt;&gt;&gt;&gt; busy
&gt;&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt;&gt; official 2.1.0 final release.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt;&gt; well if the form parts are 
&gt;&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt;&gt; stateful pages because you can 
&gt;&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    ...
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt;&gt; something like this:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; contentType here
&gt;&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;&gt;      try {
&gt;&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by
&gt;&gt;&gt;&gt; setting
&gt;&gt;&gt;&gt; path to null
&gt;&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;&gt;      }
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; The above method is probably better off in a utility class or the
&gt;&gt;&gt;&gt; border
&gt;&gt;&gt;&gt; page.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for
&gt;&gt;&gt;&gt;&gt; example
&gt;&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section of
&gt;&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select
&gt;&gt;&gt;&gt; control.
&gt;&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll
&gt;&gt;&gt;&gt;&gt;&gt; note
&gt;&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the
&gt;&gt;&gt;&gt;&gt;&gt; Ajax
&gt;&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases.
For
&gt;&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and

&gt;&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless
by 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases,
but in 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add
fields
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation
on the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on
the 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added
with
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their
&gt;&gt;&gt;&gt;&gt;&gt;&gt; values 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages,

&gt;&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
vs 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page

&gt;&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are
&gt;&gt;&gt;&gt;&gt;&gt;&gt; called 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every
&gt;&gt;&gt;&gt;&gt;&gt;&gt; request.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to
post
&gt;&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to
change
&gt;&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax
and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called
&gt;&gt;&gt;&gt;&gt;&gt;&gt; for 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like
in order
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click
1.5 to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial
form) -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; controls) 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript,
no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what
we are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are
not 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form
is 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components
(except
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply
invoke
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter.
Or you can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here
are some
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML,
JSON, XML.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you
probably want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have
the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null.
Have a
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you
can look at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components
but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need
to incorporate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's
selection -
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support
for Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some
examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really
appreciate
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4130831.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1DA403.6070408@gmail.com%3e"/>
<id>urn:uuid:%3c4B1DA403-6070408@gmail-com%3e</id>
<updated>2009-12-08T00:55:31Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
dshah wrote:
&gt; Ok. Thanks. If we use the same formpage, then does the whole form get sent
&gt; back from the Click Servlet to the browser or just the partial part that was
&gt; just gotten?  


You can control what you send back from the Page. By default the Page will render the template

associated with the Page. But if you want you can render something else since you have access
to the 
Servlet HttpServletResponse object:

public MyPage extends Page {
   public boolean onSomeButtonClick() {
     HttpServletResponse response = getContext.getResponse();
     OutputStream os = response.getOutputStream();

     // Controls know how to draw themselves through their #toString() method
     IOUtils.write(textField.toString(), os);
     ...

     // Important to set path to null so Click won't render the default Page template
     setPath(null);
     return true;
   }
}

Have a look at the renderPartial method in my previous mail. That gives you the general idea
of how 
to create a generic method for rendering partial content. Note, its not necessary to use Velocity

templates to render controls. As shown above, controls know how to draw themselves by invoking
their 
#toStrnig methods (which is what a Velocity reference does as well e.g. $form becomes form.toString()).

kind regards

bob


&gt; 
&gt; One of our concerns is that we want to reduce the bandwidth used when
&gt; sending the form from the servlet to the browser and so ideally, we were
&gt; hoping to only load part of the form (i.e. have the servlet engine send only
&gt; that section of the form to the browser but somehow know that the newly
&gt; retrieved section belongs to the form that is already on the browser..)  
&gt; 
&gt; Thoughts?
&gt; Dipita
&gt; 
&gt; 
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; Hi Dipita,
&gt;&gt;
&gt;&gt; dshah wrote:
&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;
&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt; So if you want to use 2.1.0 
&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;
&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;
&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt; moving our infrastructure 
&gt;&gt; from the incubator to TLP. Once this is done we will push out the official
&gt;&gt; 2.1.0 final release.
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version of
&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt; doing
&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt; does
&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt; suggested
&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt; another
&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt;&gt; same form element?
&gt;&gt;
&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt; information such as a Table 
&gt;&gt; etc. For your case (building up a form on the server) this won't work well
&gt;&gt; if the form parts are 
&gt;&gt; built in a separate Page. Technically this is possible when using stateful
&gt;&gt; pages because you can 
&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;
&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;
&gt;&gt;    ...
&gt;&gt;
&gt;&gt;    public FormPage getForm() {
&gt;&gt;      FormPage page = (FormPage)
&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;      return page.getForm();
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; However its probably easier to call back to FormPage itself and build the
&gt;&gt; Form with every call.
&gt;&gt;
&gt;&gt; You can create a helper method to render your partial responses, something
&gt;&gt; like this:
&gt;&gt;
&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;
&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt;&gt; contentType here
&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;
&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;
&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;      try {
&gt;&gt;          Context context = getContext();
&gt;&gt;          String partial = context.renderTemplate(template, templateModel);
&gt;&gt;
&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;
&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;
&gt;&gt;          // NB: Specify no further rendering required by Click by setting
&gt;&gt; path to null
&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;          setPath(null);
&gt;&gt;
&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;
&gt;&gt;      } finally {
&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;      }
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt; page.
&gt;&gt;
&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt; select.value);
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt; the
&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt; form
&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;
&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt; In Ajax terms this is 
&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;
&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt; AjaxSelect class:
&gt;&gt;
&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;
&gt;&gt;    public void onInit() {
&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;    }
&gt;&gt; }
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt;
&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks!
&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in

&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields
to 
&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the

&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values

&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs

&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called

&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page

&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for

&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order
to 
&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to

&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form)
-
&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are

&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
and 
&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would

&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except
for
&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you
can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some
things
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON,
XML. So
&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably
want to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have
a look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look
at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for
Ajax with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples
or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate
it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1DA1B8.9070100@gmail.com%3e"/>
<id>urn:uuid:%3c4B1DA1B8-9070100@gmail-com%3e</id>
<updated>2009-12-08T00:45:44Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
dshah wrote:
&gt; I have a test example that I am testing by just sending a request to load
&gt; part of the data based on a selection.. This is based on the example of
&gt; ajax-select demo in the 1.5.  However, whenever I select something on the
&gt; parent, the data is not rendering on the child (it's showing as though the
&gt; values are null) - anyone figure out what I am doing wrong? 


I assume the Select on AjaxTestPage uses Ajax to pull the CheckList from AjaxTestPopulate
right?

Looking at AjaxTestPopulate the problem seems to be with the use of autobinding. I recommend
*not*
using the autobinding feature if you are new to Click. Quite a bit of magic is involved which
can be
confusing.

Just to explain what I think goes wrong with autobinding in this example:

1. Click creates the AjaxTestPopulate Page by invoking its default no-arg constructor.
2. Immediately after creating the Page, Click binds all public declared fields to the Page
as follows:
2.1 Click checks if the field is null or not
2.2 If the field is not null and its name is not set, Click sets the control name to that
of the field
2.3 Lastly Click adds the Control to the Page control list

The problem in AjaxTestPopulate is that after the Page constructor is called, childList is
still
null, since it is only created in the onGet page event.

You can change the Page as follows:

public class AjaxTestPopulate extends Page {

   public CheckList childList;

   public AjaxTestPopulate() {
     // Create the childList in the Page constructor. When autobinding kicks off (after Page
     // construction) the childList control will be created and satisfy #2.1 above
     childList = getChildList();
   }
}


Alternatively you can use explicit binding:

public class AjaxTestPopulate extends Page {

   public CheckList childList;

   public onGet() {
     childList = getChildList();
     childList.setName("childList");
     addControl(childList);
   }
}

kind regards

bob


&gt; 
&gt; Attaching my files:
&gt; 1. ajax-test.htm is the main page
&gt; 2. ajax-test-populate.htm is the page I want to load partially after
&gt; something on the above is selected.
&gt; 3. AjaxTestPage.java - corresponding page for ajax-test.htm
&gt; 4. AjaxTestPopulate.java - corresponding page for ajax-test-populate.htm
&gt; 5. result html -  this is the html I am seeing when I select something on
&gt; ajax-test.htm..
&gt; 
&gt; Any idea what i am doing wrong?
&gt; 
&gt; Thanks!
&gt; Dipita http://n2.nabble.com/file/n4127448/ajax-test.htm ajax-test.htm 
&gt; http://n2.nabble.com/file/n4127448/ajax-test-populate.htm
&gt; ajax-test-populate.htm  http://n2.nabble.com/file/n4127448/AjaxTestPage.java
&gt; AjaxTestPage.java  http://n2.nabble.com/file/n4127448/AjaxTestPopulate.java
&gt; AjaxTestPopulate.java  http://n2.nabble.com/file/n4127448/resultant_html.jpg
&gt; resultant_html.jpg 
&gt; 
&gt; 
&gt; 
&gt; dshah wrote:
&gt;&gt; Ok. Thanks. If we use the same formpage, then does the whole form get sent
&gt;&gt; back from the Click Servlet to the browser or just the partial part that
&gt;&gt; was just gotten?  
&gt;&gt;
&gt;&gt; One of our concerns is that we want to reduce the bandwidth used when
&gt;&gt; sending the form from the servlet to the browser and so ideally, we were
&gt;&gt; hoping to only load part of the form (i.e. have the servlet engine send
&gt;&gt; only that section of the form to the browser but somehow know that the
&gt;&gt; newly retrieved section belongs to the form that is already on the
&gt;&gt; browser..)  
&gt;&gt;
&gt;&gt; Thoughts?
&gt;&gt; Dipita
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt;&gt;
&gt;&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt;&gt; So if you want to use 2.1.0 
&gt;&gt;&gt; I suggest you just build it from trunk:
&gt;&gt;&gt;
&gt;&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt;&gt;
&gt;&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt;&gt; moving our infrastructure 
&gt;&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt;&gt; official 2.1.0 final release.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt;&gt; of
&gt;&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt;&gt; doing
&gt;&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt;&gt; does
&gt;&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt;&gt; suggested
&gt;&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt;&gt; another
&gt;&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt;&gt;&gt; same form element?
&gt;&gt;&gt;
&gt;&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt;&gt; information such as a Table 
&gt;&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt;&gt; well if the form parts are 
&gt;&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt;&gt; stateful pages because you can 
&gt;&gt;&gt; retrieve the stateful page from the session:
&gt;&gt;&gt;
&gt;&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt;&gt;
&gt;&gt;&gt;    ...
&gt;&gt;&gt;
&gt;&gt;&gt;    public FormPage getForm() {
&gt;&gt;&gt;      FormPage page = (FormPage)
&gt;&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;&gt;      return page.getForm();
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; However its probably easier to call back to FormPage itself and build the
&gt;&gt;&gt; Form with every call.
&gt;&gt;&gt;
&gt;&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt;&gt; something like this:
&gt;&gt;&gt;
&gt;&gt;&gt; public FormPage extends BorderPage {
&gt;&gt;&gt;
&gt;&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt;&gt;&gt; contentType here
&gt;&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt;&gt;
&gt;&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt;&gt;
&gt;&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;&gt;      try {
&gt;&gt;&gt;          Context context = getContext();
&gt;&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt;&gt; templateModel);
&gt;&gt;&gt;
&gt;&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt;&gt;
&gt;&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt;&gt;
&gt;&gt;&gt;          // NB: Specify no further rendering required by Click by setting
&gt;&gt;&gt; path to null
&gt;&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;&gt;          setPath(null);
&gt;&gt;&gt;
&gt;&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt;&gt;
&gt;&gt;&gt;      } finally {
&gt;&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;&gt;      }
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt;&gt; page.
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt;&gt; select.value);
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt;&gt; the
&gt;&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt;&gt; form
&gt;&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt;&gt;
&gt;&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt;&gt; In Ajax terms this is 
&gt;&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt;&gt;
&gt;&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt;&gt; AjaxSelect class:
&gt;&gt;&gt;
&gt;&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt;&gt;
&gt;&gt;&gt;    public void onInit() {
&gt;&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;&gt;    }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thanks!
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and

&gt;&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by

&gt;&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but
in 
&gt;&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields
&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on
the 
&gt;&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the

&gt;&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values

&gt;&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages,

&gt;&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless
vs 
&gt;&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called

&gt;&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful
&gt;&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and

&gt;&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called
for 
&gt;&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in
order
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support
the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5
to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form)
-
&gt;&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we
are 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not

&gt;&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is

&gt;&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
&gt;&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant
would 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except
for
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply
invoke a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or
you can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are
some things
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON,
XML. So
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably
want
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the
default
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null.
Have a look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can
look at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but
it
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to
incorporate a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support
for Ajax with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples
or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really
appreciate it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt; 




</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260208759880-4127448.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260208759880-4127448-post@n2-nabble-com%3e</id>
<updated>2009-12-07T17:59:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I have a test example that I am testing by just sending a request to load
part of the data based on a selection.. This is based on the example of
ajax-select demo in the 1.5.  However, whenever I select something on the
parent, the data is not rendering on the child (it's showing as though the
values are null) - anyone figure out what I am doing wrong? 

Attaching my files:
1. ajax-test.htm is the main page
2. ajax-test-populate.htm is the page I want to load partially after
something on the above is selected.
3. AjaxTestPage.java - corresponding page for ajax-test.htm
4. AjaxTestPopulate.java - corresponding page for ajax-test-populate.htm
5. result html -  this is the html I am seeing when I select something on
ajax-test.htm..

Any idea what i am doing wrong?

Thanks!
Dipita http://n2.nabble.com/file/n4127448/ajax-test.htm ajax-test.htm 
http://n2.nabble.com/file/n4127448/ajax-test-populate.htm
ajax-test-populate.htm  http://n2.nabble.com/file/n4127448/AjaxTestPage.java
AjaxTestPage.java  http://n2.nabble.com/file/n4127448/AjaxTestPopulate.java
AjaxTestPopulate.java  http://n2.nabble.com/file/n4127448/resultant_html.jpg
resultant_html.jpg 



dshah wrote:
&gt; 
&gt; Ok. Thanks. If we use the same formpage, then does the whole form get sent
&gt; back from the Click Servlet to the browser or just the partial part that
&gt; was just gotten?  
&gt; 
&gt; One of our concerns is that we want to reduce the bandwidth used when
&gt; sending the form from the servlet to the browser and so ideally, we were
&gt; hoping to only load part of the form (i.e. have the servlet engine send
&gt; only that section of the form to the browser but somehow know that the
&gt; newly retrieved section belongs to the form that is already on the
&gt; browser..)  
&gt; 
&gt; Thoughts?
&gt; Dipita
&gt; 
&gt; 
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; 
&gt;&gt; Hi Dipita,
&gt;&gt; 
&gt;&gt; dshah wrote:
&gt;&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt;&gt; 
&gt;&gt; 
&gt;&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt;&gt; So if you want to use 2.1.0 
&gt;&gt; I suggest you just build it from trunk:
&gt;&gt; 
&gt;&gt; c:\dev\click&gt;svn co
&gt;&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt;&gt; c:\dev\click&gt;cd build
&gt;&gt; c:\dev\click\build&gt;ant get-deps
&gt;&gt; c:\dev\click\build&gt;ant build-distribution
&gt;&gt; 
&gt;&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt;&gt; moving our infrastructure 
&gt;&gt; from the incubator to TLP. Once this is done we will push out the
&gt;&gt; official 2.1.0 final release.
&gt;&gt; 
&gt;&gt; 
&gt;&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version
&gt;&gt;&gt; of
&gt;&gt;&gt; Click and  have a couple of questions:
&gt;&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt;&gt; doing
&gt;&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt;&gt; does
&gt;&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt;&gt; suggested
&gt;&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt;&gt; another
&gt;&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt;&gt; same form element?
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt;&gt; information such as a Table 
&gt;&gt; etc. For your case (building up a form on the server) this won't work
&gt;&gt; well if the form parts are 
&gt;&gt; built in a separate Page. Technically this is possible when using
&gt;&gt; stateful pages because you can 
&gt;&gt; retrieve the stateful page from the session:
&gt;&gt; 
&gt;&gt; public AjaxPage extends BorderPage {
&gt;&gt; 
&gt;&gt;    ...
&gt;&gt; 
&gt;&gt;    public FormPage getForm() {
&gt;&gt;      FormPage page = (FormPage)
&gt;&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;&gt;      return page.getForm();
&gt;&gt;    }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; However its probably easier to call back to FormPage itself and build the
&gt;&gt; Form with every call.
&gt;&gt; 
&gt;&gt; You can create a helper method to render your partial responses,
&gt;&gt; something like this:
&gt;&gt; 
&gt;&gt; public FormPage extends BorderPage {
&gt;&gt; 
&gt;&gt;    public void renderPartial(String template, Map templateModel) {
&gt;&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt;&gt; contentType here
&gt;&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt;&gt; 
&gt;&gt;      response.setHeader("Pragma", "no-cache");
&gt;&gt; 
&gt;&gt;      OutputStream outputStream = null;
&gt;&gt;      try {
&gt;&gt;          Context context = getContext();
&gt;&gt;          String partial = context.renderTemplate(template,
&gt;&gt; templateModel);
&gt;&gt; 
&gt;&gt;          outputStream = context.getResponse().getOutputStream();
&gt;&gt; 
&gt;&gt;          IOUtils.write(partial, outputStream);
&gt;&gt; 
&gt;&gt;          // NB: Specify no further rendering required by Click by setting
&gt;&gt; path to null
&gt;&gt;          // Thus Click won't render the Page default template form.htm
&gt;&gt;          setPath(null);
&gt;&gt; 
&gt;&gt;      } catch (IOException ioe) {
&gt;&gt;          throw new RuntimeException(ioe);
&gt;&gt; 
&gt;&gt;      } finally {
&gt;&gt;          IOUtils.closeQuietly(outputStream);
&gt;&gt;      }
&gt;&gt;    }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; The above method is probably better off in a utility class or the border
&gt;&gt; page.
&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt;&gt; 
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'
&gt;&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt;&gt; function registerAjax() {
&gt;&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt;&gt; }
&gt;&gt;&gt; 
&gt;&gt;&gt; function onCustomerChange(select) {
&gt;&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt;&gt; select.value);
&gt;&gt;&gt; }
&gt;&gt;&gt; 
&gt;&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt;&gt; &lt;/script&gt;
&gt;&gt;&gt; 
&gt;&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt;&gt; the
&gt;&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt;&gt; form
&gt;&gt;&gt; e.g. using JQuery's load event or something like that?
&gt;&gt; 
&gt;&gt; 
&gt;&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt;&gt; In Ajax terms this is 
&gt;&gt; called "inline event handling" while the register approach is called
&gt;&gt; "unobtrusive JavaScript", 
&gt;&gt; meaning the the markup doesn't have any behavior specified.
&gt;&gt; 
&gt;&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt;&gt; AjaxSelect class:
&gt;&gt; 
&gt;&gt; public CustomerAjaxSelect extends Select {
&gt;&gt; 
&gt;&gt;    public void onInit() {
&gt;&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;&gt;    }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; kind regards
&gt;&gt; 
&gt;&gt; bob
&gt;&gt; 
&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt;&gt; 
&gt;&gt;&gt; Thanks!
&gt;&gt;&gt; Dipita
&gt;&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt;&gt; needs.
&gt;&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt;&gt; when
&gt;&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt;&gt; submitted.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt;&gt; logic
&gt;&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype,

&gt;&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in

&gt;&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields
&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the

&gt;&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values

&gt;&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs

&gt;&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called

&gt;&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful
&gt;&gt;&gt;&gt;&gt; Page 
&gt;&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for

&gt;&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order
&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to

&gt;&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form)
-
&gt;&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are

&gt;&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection)
&gt;&gt;&gt;&gt;&gt;&gt; and 
&gt;&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would

&gt;&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except
for
&gt;&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you
can 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some
things
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON,
XML. So
&gt;&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably
want
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have
a look 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look
at,
&gt;&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it
&gt;&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for
Ajax with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples
or
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling
to get
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate
it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt; 
&gt;&gt; 
&gt;&gt; 
&gt;&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4127448.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260174420641-4124853.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260174420641-4124853-post@n2-nabble-com%3e</id>
<updated>2009-12-07T08:27:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Ok. Thanks. If we use the same formpage, then does the whole form get sent
back from the Click Servlet to the browser or just the partial part that was
just gotten?  

One of our concerns is that we want to reduce the bandwidth used when
sending the form from the servlet to the browser and so ideally, we were
hoping to only load part of the form (i.e. have the servlet engine send only
that section of the form to the browser but somehow know that the newly
retrieved section belongs to the form that is already on the browser..)  

Thoughts?
Dipita




Bob Schellink-2 wrote:
&gt; 
&gt; Hi Dipita,
&gt; 
&gt; dshah wrote:
&gt;&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick
&gt; 
&gt; 
&gt; The current trunk is pretty much what we want to release as 2.1.0 final.
&gt; So if you want to use 2.1.0 
&gt; I suggest you just build it from trunk:
&gt; 
&gt; c:\dev\click&gt;svn co
&gt; http://svn.apache.org/repos/asf/incubator/click/trunk/click/
&gt; c:\dev\click&gt;cd build
&gt; c:\dev\click\build&gt;ant get-deps
&gt; c:\dev\click\build&gt;ant build-distribution
&gt; 
&gt; Click recently graduation as an Apache Top Level Project and we are busy
&gt; moving our infrastructure 
&gt; from the incubator to TLP. Once this is done we will push out the official
&gt; 2.1.0 final release.
&gt; 
&gt; 
&gt;&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version of
&gt;&gt; Click and  have a couple of questions:
&gt;&gt; 1. If you had a form and did something similar to what this example is
&gt;&gt; doing
&gt;&gt; (render part of the form using a different page) via an ajax call, how
&gt;&gt; does
&gt;&gt; the form on your main page get the fields that were rendered using the
&gt;&gt; different page or does it?  I mean if I make the page stateful as
&gt;&gt; suggested
&gt;&gt; and I render part of the page via an ajax call (which will configure
&gt;&gt; another
&gt;&gt; section of the form), I am unclear how both the rendering bind up to the
&gt;&gt; same form element?
&gt; 
&gt; 
&gt; Using a separate Page for Ajax rendering works OK for displaying extra
&gt; information such as a Table 
&gt; etc. For your case (building up a form on the server) this won't work well
&gt; if the form parts are 
&gt; built in a separate Page. Technically this is possible when using stateful
&gt; pages because you can 
&gt; retrieve the stateful page from the session:
&gt; 
&gt; public AjaxPage extends BorderPage {
&gt; 
&gt;    ...
&gt; 
&gt;    public FormPage getForm() {
&gt;      FormPage page = (FormPage)
&gt; getContext().getSessionAttribute(FormPage.class.getName());
&gt;      return page.getForm();
&gt;    }
&gt; }
&gt; 
&gt; However its probably easier to call back to FormPage itself and build the
&gt; Form with every call.
&gt; 
&gt; You can create a helper method to render your partial responses, something
&gt; like this:
&gt; 
&gt; public FormPage extends BorderPage {
&gt; 
&gt;    public void renderPartial(String template, Map templateModel) {
&gt;      // Depending if you send back HTML, JSON, XML you need to adjust the
&gt; contentType here
&gt;      response.setContentType("text/html; charset=UTF-8");
&gt;      //response.setContentType("text/xml; charset=UTF-8");
&gt; 
&gt;      response.setHeader("Pragma", "no-cache");
&gt; 
&gt;      OutputStream outputStream = null;
&gt;      try {
&gt;          Context context = getContext();
&gt;          String partial = context.renderTemplate(template, templateModel);
&gt; 
&gt;          outputStream = context.getResponse().getOutputStream();
&gt; 
&gt;          IOUtils.write(partial, outputStream);
&gt; 
&gt;          // NB: Specify no further rendering required by Click by setting
&gt; path to null
&gt;          // Thus Click won't render the Page default template form.htm
&gt;          setPath(null);
&gt; 
&gt;      } catch (IOException ioe) {
&gt;          throw new RuntimeException(ioe);
&gt; 
&gt;      } finally {
&gt;          IOUtils.closeQuietly(outputStream);
&gt;      }
&gt;    }
&gt; }
&gt; 
&gt; The above method is probably better off in a utility class or the border
&gt; page.
&gt; 
&gt;&gt; 
&gt;&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt;&gt; 
&gt;&gt; &lt;script type='text/javascript'
&gt;&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt;&gt; &lt;script type='text/javascript'
&gt;&gt; src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt;&gt; &lt;script type='text/javascript'&gt;
&gt;&gt; function registerAjax() {
&gt;&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt;&gt; '${context}/ajax/ajax-customer.htm');
&gt;&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt;&gt; }
&gt;&gt; 
&gt;&gt; function onCustomerChange(select) {
&gt;&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' +
&gt;&gt; select.value);
&gt;&gt; }
&gt;&gt; 
&gt;&gt; addLoadEvent(registerAjax);
&gt;&gt; &lt;/script&gt;
&gt;&gt; 
&gt;&gt; Question is do we need to register an ajax event or could I for example
&gt;&gt; onCustomerChange event (which is already registered as an attribute of
&gt;&gt; the
&gt;&gt; Select control) directly call the page that renders that section of the
&gt;&gt; form
&gt;&gt; e.g. using JQuery's load event or something like that?
&gt; 
&gt; 
&gt; You can just use onCustomerChange as an attribute of the Select control.
&gt; In Ajax terms this is 
&gt; called "inline event handling" while the register approach is called
&gt; "unobtrusive JavaScript", 
&gt; meaning the the markup doesn't have any behavior specified.
&gt; 
&gt; You can also look at encapsulating the Ajax behavior in a custom
&gt; AjaxSelect class:
&gt; 
&gt; public CustomerAjaxSelect extends Select {
&gt; 
&gt;    public void onInit() {
&gt;      select.setAttribute("onchange", "onCustomerChange(this)");
&gt;    }
&gt; }
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; 
&gt;&gt; 
&gt;&gt; Apologies for stupid questions but I am new to Ajax.
&gt;&gt; 
&gt;&gt; Thanks!
&gt;&gt; Dipita
&gt;&gt; 
&gt;&gt; 
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your
&gt;&gt;&gt; needs.
&gt;&gt;&gt; Its a form with two 
&gt;&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt;&gt; that the Page is stateful so 
&gt;&gt;&gt; any changes made to the Form (new fields added etc) will be available
&gt;&gt;&gt; when
&gt;&gt;&gt; the Form is finally 
&gt;&gt;&gt; submitted.
&gt;&gt;&gt;
&gt;&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;&gt;
&gt;&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax
&gt;&gt;&gt; logic
&gt;&gt;&gt; is encapsulated within the 
&gt;&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt;&gt; logic is encapsulated within 
&gt;&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;&gt;
&gt;&gt;&gt; Hope this helps.
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For
&gt;&gt;&gt;&gt; example 
&gt;&gt;&gt;&gt; you could use a wizard style approach to present the user with
&gt;&gt;&gt;&gt; different 
&gt;&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which
&gt;&gt;&gt;&gt; reacts 
&gt;&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype, 
&gt;&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in 
&gt;&gt;&gt;&gt; your case might not work very well. In your case you will add fields to 
&gt;&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the 
&gt;&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with
&gt;&gt;&gt;&gt; Ajax 
&gt;&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values 
&gt;&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs 
&gt;&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt;&gt; constructor is only called once, but the life cycle events are called 
&gt;&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page 
&gt;&gt;&gt;&gt; and test against that Page to get things working. Feel free to post
&gt;&gt;&gt;&gt; your 
&gt;&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change
&gt;&gt;&gt;&gt; much 
&gt;&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;&gt;      return true;
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for 
&gt;&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;&gt;         return true;
&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;       // This method is optional and only called for Ajax requests
&gt;&gt;&gt;&gt; which 
&gt;&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;&gt;          ...
&gt;&gt;&gt;&gt;       }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;     });
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt; }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order to

&gt;&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to 
&gt;&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form) -
&gt;&gt;&gt;&gt;&gt; our
&gt;&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls)

&gt;&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal
&gt;&gt;&gt;&gt;&gt; javascript
&gt;&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are 
&gt;&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection) and

&gt;&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would

&gt;&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke
a 
&gt;&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you can

&gt;&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some things
&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML.
So
&gt;&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably want
to 
&gt;&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default
&gt;&gt;&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have a look

&gt;&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it
&gt;&gt;&gt;&gt;&gt;&gt; targets
&gt;&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection
- does
&gt;&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax
with 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to
get any 
&gt;&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate
it.
&gt;&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4124853.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B1C3B7A.6080907@gmail.com%3e"/>
<id>urn:uuid:%3c4B1C3B7A-6080907@gmail-com%3e</id>
<updated>2009-12-06T23:17:14Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Dipita,

dshah wrote:
&gt; Thanks - in case we cannot upgrade to 2.1.0 and ClickClick


The current trunk is pretty much what we want to release as 2.1.0 final. So if you want to
use 2.1.0 
I suggest you just build it from trunk:

c:\dev\click&gt;svn co http://svn.apache.org/repos/asf/incubator/click/trunk/click/
c:\dev\click&gt;cd build
c:\dev\click\build&gt;ant get-deps
c:\dev\click\build&gt;ant build-distribution

Click recently graduation as an Apache Top Level Project and we are busy moving our infrastructure

from the incubator to TLP. Once this is done we will push out the official 2.1.0 final release.


&gt; I am looking at the ajax-select demo that comes with the 1.5.2 version of
&gt; Click and  have a couple of questions:
&gt; 1. If you had a form and did something similar to what this example is doing
&gt; (render part of the form using a different page) via an ajax call, how does
&gt; the form on your main page get the fields that were rendered using the
&gt; different page or does it?  I mean if I make the page stateful as suggested
&gt; and I render part of the page via an ajax call (which will configure another
&gt; section of the form), I am unclear how both the rendering bind up to the
&gt; same form element?


Using a separate Page for Ajax rendering works OK for displaying extra information such as
a Table 
etc. For your case (building up a form on the server) this won't work well if the form parts
are 
built in a separate Page. Technically this is possible when using stateful pages because you
can 
retrieve the stateful page from the session:

public AjaxPage extends BorderPage {

   ...

   public FormPage getForm() {
     FormPage page = (FormPage) getContext().getSessionAttribute(FormPage.class.getName());
     return page.getForm();
   }
}

However its probably easier to call back to FormPage itself and build the Form with every
call.

You can create a helper method to render your partial responses, something like this:

public FormPage extends BorderPage {

   public void renderPartial(String template, Map templateModel) {
     // Depending if you send back HTML, JSON, XML you need to adjust the contentType here
     response.setContentType("text/html; charset=UTF-8");
     //response.setContentType("text/xml; charset=UTF-8");

     response.setHeader("Pragma", "no-cache");

     OutputStream outputStream = null;
     try {
         Context context = getContext();
         String partial = context.renderTemplate(template, templateModel);

         outputStream = context.getResponse().getOutputStream();

         IOUtils.write(partial, outputStream);

         // NB: Specify no further rendering required by Click by setting path to null
         // Thus Click won't render the Page default template form.htm
         setPath(null);

     } catch (IOException ioe) {
         throw new RuntimeException(ioe);

     } finally {
         IOUtils.closeQuietly(outputStream);
     }
   }
}

The above method is probably better off in a utility class or the border page.

&gt; 
&gt; 2.  The ajax-select-include.htm has the following code snippet:
&gt; 
&gt; &lt;script type='text/javascript'
&gt; src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&gt; &lt;script type='text/javascript' src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&gt; &lt;script type='text/javascript'&gt;
&gt; function registerAjax() {
&gt;     ajaxEngine.registerRequest('getCustomerInfo',
&gt; '${context}/ajax/ajax-customer.htm');
&gt;     ajaxEngine.registerAjaxElement('customerDetails');
&gt; }
&gt; 
&gt; function onCustomerChange(select) {
&gt;     ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' + select.value);
&gt; }
&gt; 
&gt; addLoadEvent(registerAjax);
&gt; &lt;/script&gt;
&gt; 
&gt; Question is do we need to register an ajax event or could I for example
&gt; onCustomerChange event (which is already registered as an attribute of the
&gt; Select control) directly call the page that renders that section of the form
&gt; e.g. using JQuery's load event or something like that?


You can just use onCustomerChange as an attribute of the Select control. In Ajax terms this
is 
called "inline event handling" while the register approach is called "unobtrusive JavaScript",

meaning the the markup doesn't have any behavior specified.

You can also look at encapsulating the Ajax behavior in a custom AjaxSelect class:

public CustomerAjaxSelect extends Select {

   public void onInit() {
     select.setAttribute("onchange", "onCustomerChange(this)");
   }
}

kind regards

bob


&gt; 
&gt; Apologies for stupid questions but I am new to Ajax.
&gt; 
&gt; Thanks!
&gt; Dipita
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; There is a ClickClick jQuery demo which seems very similar to your needs.
&gt;&gt; Its a form with two 
&gt;&gt; selects where the first Select populates the second Select. You'll note
&gt;&gt; that the Page is stateful so 
&gt;&gt; any changes made to the Form (new fields added etc) will be available when
&gt;&gt; the Form is finally 
&gt;&gt; submitted.
&gt;&gt;
&gt;&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt;&gt;
&gt;&gt; This example uses jQuery but you'll notice that the JavaScript Ajax logic
&gt;&gt; is encapsulated within the 
&gt;&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt;&gt; logic is encapsulated within 
&gt;&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt;&gt;
&gt;&gt; Hope this helps.
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For example 
&gt;&gt;&gt; you could use a wizard style approach to present the user with different 
&gt;&gt;&gt; options. Each step in the wizard navigates to the next Page which reacts 
&gt;&gt;&gt; to values from the previous Page.
&gt;&gt;&gt;
&gt;&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype, 
&gt;&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt;&gt;
&gt;&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt;&gt; default. Statelessness has great benefits for some use cases, but in 
&gt;&gt;&gt; your case might not work very well. In your case you will add fields to 
&gt;&gt;&gt; the form over multiple ajax requests. The Form representation on the 
&gt;&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt;&gt; server. Thus when you finally submit the Form the fields added with Ajax 
&gt;&gt;&gt; won't have a corresponding field on the server Form, and their values 
&gt;&gt;&gt; won't be bound.
&gt;&gt;&gt;
&gt;&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs 
&gt;&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt;&gt; constructor is only called once, but the life cycle events are called 
&gt;&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt;&gt;
&gt;&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page 
&gt;&gt;&gt; and test against that Page to get things working. Feel free to post your 
&gt;&gt;&gt; code to this list and I'll help where I can.
&gt;&gt;&gt;
&gt;&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change much 
&gt;&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt;&gt; non-ajax calls.
&gt;&gt;&gt;
&gt;&gt;&gt; So if your code looks like this:
&gt;&gt;&gt;
&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;
&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;&gt;   }
&gt;&gt;&gt;
&gt;&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;&gt;      dostuff();
&gt;&gt;&gt;      return true;
&gt;&gt;&gt;   }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt; it will change to:
&gt;&gt;&gt;
&gt;&gt;&gt; public class MyPage extends Page {
&gt;&gt;&gt;
&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt;&gt;
&gt;&gt;&gt;       // This method replaces onSubmitClick() above and is called for 
&gt;&gt;&gt; non-Ajax requests
&gt;&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;&gt;         dostuff();
&gt;&gt;&gt;         return true;
&gt;&gt;&gt;       }
&gt;&gt;&gt;
&gt;&gt;&gt;       // This method is optional and only called for Ajax requests which 
&gt;&gt;&gt; target the submit button
&gt;&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;&gt;          ...
&gt;&gt;&gt;       }
&gt;&gt;&gt;
&gt;&gt;&gt;     });
&gt;&gt;&gt;   }
&gt;&gt;&gt; }
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order to 
&gt;&gt;&gt;&gt; use
&gt;&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to 
&gt;&gt;&gt;&gt; simply do
&gt;&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form) - our
&gt;&gt;&gt;&gt; current code base configures the form objects (using Click controls) 
&gt;&gt;&gt;&gt; on the
&gt;&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal javascript
&gt;&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are 
&gt;&gt;&gt;&gt; doing but
&gt;&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt;&gt; particular
&gt;&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt;&gt; dependendant
&gt;&gt;&gt;&gt; (child selection) based on the user's selection (parent selection) and 
&gt;&gt;&gt;&gt; needs
&gt;&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would 
&gt;&gt;&gt;&gt; change
&gt;&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke a 
&gt;&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you can 
&gt;&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some things
to
&gt;&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML. So
&gt;&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably want to

&gt;&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default Page
&gt;&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have a look

&gt;&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it targets
&gt;&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate
a 
&gt;&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection - does
&gt;&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax with

&gt;&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to get
any 
&gt;&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate it.
&gt;&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Can provide fileupload example code</title>
<author><name>&quot;Adrian A.&quot; &lt;a.adrian.tech@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3chffr6f$kh2$1@ger.gmane.org%3e"/>
<id>urn:uuid:%3chffr6f$kh2$1@ger-gmane-org%3e</id>
<updated>2009-12-06T08:49:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
&gt; I study click framework.
&gt; But I don't know how to implement fileupload by click framework.
&gt; Any body can provide example code?
The Click Control you are looking for is called "FileField":
http://incubator.apache.org/click/docs/click-api/org/apache/click/control/FileField.html

Take a look at FileUpload example from click-examples (it's using 
FileField).
You can see it live here too:
http://www.avoka.com/click-examples/control/file-upload.htm

Adrian.



</pre>
</div>
</content>
</entry>
<entry>
<title>Can provide fileupload example code</title>
<author><name>clarence0714 &lt;clarence0714@yahoo.com.tw&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260080705266-4120521.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260080705266-4120521-post@n2-nabble-com%3e</id>
<updated>2009-12-06T06:25:05Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hello everybody:
I study click framework.
But I don't know how to implement fileupload by click framework.
Any body can provide example code?
-- 
View this message in context: http://n2.nabble.com/Can-provide-fileupload-example-code-tp4120521p4120521.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1260062237802-4119863.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1260062237802-4119863-post@n2-nabble-com%3e</id>
<updated>2009-12-06T01:17:17Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Thanks - in case we cannot upgrade to 2.1.0 and ClickClick, I wanted to
understand how to use AJAX without ClickClick..
I am looking at the ajax-select demo that comes with the 1.5.2 version of
Click and  have a couple of questions:
1. If you had a form and did something similar to what this example is doing
(render part of the form using a different page) via an ajax call, how does
the form on your main page get the fields that were rendered using the
different page or does it?  I mean if I make the page stateful as suggested
and I render part of the page via an ajax call (which will configure another
section of the form), I am unclear how both the rendering bind up to the
same form element?

2.  The ajax-select-include.htm has the following code snippet:

&lt;script type='text/javascript'
src='${context}/assets/js/prototype.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='${context}/assets/js/rico.js'&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
function registerAjax() {
    ajaxEngine.registerRequest('getCustomerInfo',
'${context}/ajax/ajax-customer.htm');
    ajaxEngine.registerAjaxElement('customerDetails');
}

function onCustomerChange(select) {
    ajaxEngine.sendRequest('getCustomerInfo', 'customerId=' + select.value);
}

addLoadEvent(registerAjax);
&lt;/script&gt;

Question is do we need to register an ajax event or could I for example
onCustomerChange event (which is already registered as an attribute of the
Select control) directly call the page that renders that section of the form
e.g. using JQuery's load event or something like that?

Apologies for stupid questions but I am new to Ajax.

Thanks!
Dipita


Bob Schellink-2 wrote:
&gt; 
&gt; There is a ClickClick jQuery demo which seems very similar to your needs.
&gt; Its a form with two 
&gt; selects where the first Select populates the second Select. You'll note
&gt; that the Page is stateful so 
&gt; any changes made to the Form (new fields added etc) will be available when
&gt; the Form is finally 
&gt; submitted.
&gt; 
&gt; http://clickclick-jquery.appspot.com/ajax/select-demo.htm
&gt; 
&gt; This example uses jQuery but you'll notice that the JavaScript Ajax logic
&gt; is encapsulated within the 
&gt; JQSelect control, an Ajax aware Select subclass. (Technically the Ajax
&gt; logic is encapsulated within 
&gt; a JQHelper class and JQSelect merely delegates to JQHelper.)
&gt; 
&gt; Hope this helps.
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; Bob Schellink wrote:
&gt;&gt; Depending on your time constraints, and since your new to Ajax and 
&gt;&gt; Click, you want to reconsider using Ajax for your use cases. For example 
&gt;&gt; you could use a wizard style approach to present the user with different 
&gt;&gt; options. Each step in the wizard navigates to the next Page which reacts 
&gt;&gt; to values from the previous Page.
&gt;&gt; 
&gt;&gt; Otherwise I highly recommend you use a JS library such as Prototype, 
&gt;&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt;&gt; (generally) shield you from the different browser quirks.
&gt;&gt; 
&gt;&gt; One issue you will most likely face is that Click is stateless by 
&gt;&gt; default. Statelessness has great benefits for some use cases, but in 
&gt;&gt; your case might not work very well. In your case you will add fields to 
&gt;&gt; the form over multiple ajax requests. The Form representation on the 
&gt;&gt; browser will be very different from the Form representation on the 
&gt;&gt; server. Thus when you finally submit the Form the fields added with Ajax 
&gt;&gt; won't have a corresponding field on the server Form, and their values 
&gt;&gt; won't be bound.
&gt;&gt; 
&gt;&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt;&gt; however this is not a simple "flip the switch" setting. Stateless vs 
&gt;&gt; stateful take different approaches. In stateful mode the Page 
&gt;&gt; constructor is only called once, but the life cycle events are called 
&gt;&gt; for every request, while stateless pages are recreated every request.
&gt;&gt; 
&gt;&gt; So to start I suggest you pick a JS library, create a new stateful Page 
&gt;&gt; and test against that Page to get things working. Feel free to post your 
&gt;&gt; code to this list and I'll help where I can.
&gt;&gt; 
&gt;&gt; One note about ClickClick's AjaxAdapter is you won't have to change much 
&gt;&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt;&gt; non-ajax calls.
&gt;&gt; 
&gt;&gt; So if your code looks like this:
&gt;&gt; 
&gt;&gt; public class MyPage extends Page {
&gt;&gt; 
&gt;&gt;   public void onInit() {
&gt;&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;&gt;   }
&gt;&gt; 
&gt;&gt;   public boolean onSubmitClick() {
&gt;&gt;      dostuff();
&gt;&gt;      return true;
&gt;&gt;   }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; it will change to:
&gt;&gt; 
&gt;&gt; public class MyPage extends Page {
&gt;&gt; 
&gt;&gt;   public void onInit() {
&gt;&gt;     Submit submit = new Submit("submit");
&gt;&gt;     submit.setActionListener(new AjaxAdapter(){
&gt;&gt; 
&gt;&gt;       // This method replaces onSubmitClick() above and is called for 
&gt;&gt; non-Ajax requests
&gt;&gt;       public boolean onAction(Control control) {
&gt;&gt;         dostuff();
&gt;&gt;         return true;
&gt;&gt;       }
&gt;&gt; 
&gt;&gt;       // This method is optional and only called for Ajax requests which 
&gt;&gt; target the submit button
&gt;&gt;       public Partial onAjaxAction(Control control) {
&gt;&gt;          ...
&gt;&gt;       }
&gt;&gt; 
&gt;&gt;     });
&gt;&gt;   }
&gt;&gt; }
&gt;&gt; 
&gt;&gt; 
&gt;&gt; kind regards
&gt;&gt; 
&gt;&gt; bob
&gt;&gt; 
&gt;&gt; dshah wrote:
&gt;&gt; 
&gt;&gt;&gt;
&gt;&gt;&gt; I was looking at the ClickClick examples but it looks like in order to 
&gt;&gt;&gt; use
&gt;&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt;&gt; AjaxAdapter etc.
&gt;&gt; 
&gt;&gt; 
&gt;&gt;&gt;
&gt;&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to 
&gt;&gt;&gt; simply do
&gt;&gt;&gt; what we want (which is calling the servlet to get a partial form) - our
&gt;&gt;&gt; current code base configures the form objects (using Click controls) 
&gt;&gt;&gt; on the
&gt;&gt;&gt; server side and then renders it on the browser.. Very minimal javascript
&gt;&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt;&gt; libraries.  So
&gt;&gt;&gt; my idea was to continue using the raw libraries to do what we are 
&gt;&gt;&gt; doing but
&gt;&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt;&gt; particular
&gt;&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt;&gt; dependendant
&gt;&gt;&gt; (child selection) based on the user's selection (parent selection) and 
&gt;&gt;&gt; needs
&gt;&gt;&gt; to be connect (hooked to the user's selection as the dependant would 
&gt;&gt;&gt; change
&gt;&gt;&gt; based on the parent's selection.)
&gt;&gt;&gt;
&gt;&gt;&gt; Any tips are appreciated.
&gt;&gt;&gt; Thanks again!
&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke a 
&gt;&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt;&gt; different templates depending on the request parameter. Or you can 
&gt;&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt;&gt; requests.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Since I'm not sure what problems you are having here are some things to
&gt;&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML. So
&gt;&gt;&gt;&gt; depending on what you stream back to the browser you probably want to 
&gt;&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;&gt;    }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; - If you want to render partial results (and not have the default Page
&gt;&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have a look 
&gt;&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; There is also a project underway to add Ajax components but it targets
&gt;&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; [1]: 
&gt;&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate a 
&gt;&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection - does
&gt;&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax with 
&gt;&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to get any

&gt;&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate it.
&gt;&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; 
&gt;&gt; 
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4119863.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B19E9C9.4060800@gmail.com%3e"/>
<id>urn:uuid:%3c4B19E9C9-4060800@gmail-com%3e</id>
<updated>2009-12-05T05:04:09Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
There is a ClickClick jQuery demo which seems very similar to your needs. Its a form with two

selects where the first Select populates the second Select. You'll note that the Page is stateful
so 
any changes made to the Form (new fields added etc) will be available when the Form is finally

submitted.

http://clickclick-jquery.appspot.com/ajax/select-demo.htm

This example uses jQuery but you'll notice that the JavaScript Ajax logic is encapsulated
within the 
JQSelect control, an Ajax aware Select subclass. (Technically the Ajax logic is encapsulated
within 
a JQHelper class and JQSelect merely delegates to JQHelper.)

Hope this helps.

kind regards

bob

Bob Schellink wrote:
&gt; Depending on your time constraints, and since your new to Ajax and 
&gt; Click, you want to reconsider using Ajax for your use cases. For example 
&gt; you could use a wizard style approach to present the user with different 
&gt; options. Each step in the wizard navigates to the next Page which reacts 
&gt; to values from the previous Page.
&gt; 
&gt; Otherwise I highly recommend you use a JS library such as Prototype, 
&gt; JQuery, Mootools etc. They provide good ajax functionality and 
&gt; (generally) shield you from the different browser quirks.
&gt; 
&gt; One issue you will most likely face is that Click is stateless by 
&gt; default. Statelessness has great benefits for some use cases, but in 
&gt; your case might not work very well. In your case you will add fields to 
&gt; the form over multiple ajax requests. The Form representation on the 
&gt; browser will be very different from the Form representation on the 
&gt; server. Thus when you finally submit the Form the fields added with Ajax 
&gt; won't have a corresponding field on the server Form, and their values 
&gt; won't be bound.
&gt; 
&gt; To remedy this you will probably want to switch to stateful Pages, 
&gt; however this is not a simple "flip the switch" setting. Stateless vs 
&gt; stateful take different approaches. In stateful mode the Page 
&gt; constructor is only called once, but the life cycle events are called 
&gt; for every request, while stateless pages are recreated every request.
&gt; 
&gt; So to start I suggest you pick a JS library, create a new stateful Page 
&gt; and test against that Page to get things working. Feel free to post your 
&gt; code to this list and I'll help where I can.
&gt; 
&gt; One note about ClickClick's AjaxAdapter is you won't have to change much 
&gt; in your code to use the AjaxAdapter since it supports both Ajax and 
&gt; non-ajax calls.
&gt; 
&gt; So if your code looks like this:
&gt; 
&gt; public class MyPage extends Page {
&gt; 
&gt;   public void onInit() {
&gt;     Submit submit = new Submit("submit", this, "onSubmitClick");
&gt;   }
&gt; 
&gt;   public boolean onSubmitClick() {
&gt;      dostuff();
&gt;      return true;
&gt;   }
&gt; }
&gt; 
&gt; it will change to:
&gt; 
&gt; public class MyPage extends Page {
&gt; 
&gt;   public void onInit() {
&gt;     Submit submit = new Submit("submit");
&gt;     submit.setActionListener(new AjaxAdapter(){
&gt; 
&gt;       // This method replaces onSubmitClick() above and is called for 
&gt; non-Ajax requests
&gt;       public boolean onAction(Control control) {
&gt;         dostuff();
&gt;         return true;
&gt;       }
&gt; 
&gt;       // This method is optional and only called for Ajax requests which 
&gt; target the submit button
&gt;       public Partial onAjaxAction(Control control) {
&gt;          ...
&gt;       }
&gt; 
&gt;     });
&gt;   }
&gt; }
&gt; 
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; dshah wrote:
&gt; 
&gt;&gt;
&gt;&gt; I was looking at the ClickClick examples but it looks like in order to 
&gt;&gt; use
&gt;&gt; that we'd have to rewrite all our current code base to support the
&gt;&gt; AjaxAdapter etc.
&gt; 
&gt; 
&gt;&gt;
&gt;&gt; I was hoping to use our current code base which uses Click 1.5 to 
&gt;&gt; simply do
&gt;&gt; what we want (which is calling the servlet to get a partial form) - our
&gt;&gt; current code base configures the form objects (using Click controls) 
&gt;&gt; on the
&gt;&gt; server side and then renders it on the browser.. Very minimal javascript
&gt;&gt; validation and selection is done through raw javascript, no 
&gt;&gt; libraries.  So
&gt;&gt; my idea was to continue using the raw libraries to do what we are 
&gt;&gt; doing but
&gt;&gt; also use some ajax library like JQuery or Prototype (we are not 
&gt;&gt; particular
&gt;&gt; what we use) to render part of the form.. The partial form is 
&gt;&gt; dependendant
&gt;&gt; (child selection) based on the user's selection (parent selection) and 
&gt;&gt; needs
&gt;&gt; to be connect (hooked to the user's selection as the dependant would 
&gt;&gt; change
&gt;&gt; based on the parent's selection.)
&gt;&gt;
&gt;&gt; Any tips are appreciated.
&gt;&gt; Thanks again!
&gt;&gt; Dipita
&gt;&gt;
&gt;&gt;
&gt;&gt; Bob Schellink-2 wrote:
&gt;&gt;&gt; Hi Dipita,
&gt;&gt;&gt;
&gt;&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt;&gt; AutoCompleteField) but you can use Ajax with Click. Simply invoke a 
&gt;&gt;&gt; target Page and stream back the
&gt;&gt;&gt; result you need. You probably want to look at the method 
&gt;&gt;&gt; Context#renderTemplate() so you can render
&gt;&gt;&gt; different templates depending on the request parameter. Or you can 
&gt;&gt;&gt; create specific Pages to handle Ajax
&gt;&gt;&gt; requests.
&gt;&gt;&gt;
&gt;&gt;&gt; Since I'm not sure what problems you are having here are some things to
&gt;&gt;&gt; look at when working with Ajax:
&gt;&gt;&gt;
&gt;&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML. So
&gt;&gt;&gt; depending on what you stream back to the browser you probably want to 
&gt;&gt;&gt; override the Page#getContentType
&gt;&gt;&gt; to specify the correct type:
&gt;&gt;&gt;
&gt;&gt;&gt;    public String getContentType() {
&gt;&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;&gt;    }
&gt;&gt;&gt;
&gt;&gt;&gt; - If you want to render partial results (and not have the default Page
&gt;&gt;&gt; template invoked) you have to set the Page path to null. Have a look 
&gt;&gt;&gt; at the method "export" in the
&gt;&gt;&gt; example here[1].
&gt;&gt;&gt;
&gt;&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt;&gt; especially the ajax-select demo.
&gt;&gt;&gt;
&gt;&gt;&gt; There is also a project underway to add Ajax components but it targets
&gt;&gt;&gt; Click 2.1.0
&gt;&gt;&gt;
&gt;&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; [1]: 
&gt;&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; dshah wrote:
&gt;&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate a 
&gt;&gt;&gt;&gt; way to
&gt;&gt;&gt;&gt; dynamically load partial forms based on the user's selection - does
&gt;&gt;&gt;&gt; anyone
&gt;&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax with 
&gt;&gt;&gt;&gt; Click
&gt;&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to get any 
&gt;&gt;&gt;&gt; ajax
&gt;&gt;&gt;&gt; to
&gt;&gt;&gt;&gt; work with click.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate it.
&gt;&gt;&gt;&gt; Dipita
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt; 
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B19E04F.7040409@gmail.com%3e"/>
<id>urn:uuid:%3c4B19E04F-7040409@gmail-com%3e</id>
<updated>2009-12-05T04:23:43Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Depending on your time constraints, and since your new to Ajax and Click, you want to reconsider

using Ajax for your use cases. For example you could use a wizard style approach to present
the user 
with different options. Each step in the wizard navigates to the next Page which reacts to
values 
from the previous Page.

Otherwise I highly recommend you use a JS library such as Prototype, JQuery, Mootools etc.
They 
provide good ajax functionality and (generally) shield you from the different browser quirks.

One issue you will most likely face is that Click is stateless by default. Statelessness has
great 
benefits for some use cases, but in your case might not work very well. In your case you will
add 
fields to the form over multiple ajax requests. The Form representation on the browser will
be very 
different from the Form representation on the server. Thus when you finally submit the Form
the 
fields added with Ajax won't have a corresponding field on the server Form, and their values
won't 
be bound.

To remedy this you will probably want to switch to stateful Pages, however this is not a simple

"flip the switch" setting. Stateless vs stateful take different approaches. In stateful mode
the 
Page constructor is only called once, but the life cycle events are called for every request,
while 
stateless pages are recreated every request.

So to start I suggest you pick a JS library, create a new stateful Page and test against that
Page 
to get things working. Feel free to post your code to this list and I'll help where I can.

One note about ClickClick's AjaxAdapter is you won't have to change much in your code to use
the 
AjaxAdapter since it supports both Ajax and non-ajax calls.

So if your code looks like this:

public class MyPage extends Page {

   public void onInit() {
     Submit submit = new Submit("submit", this, "onSubmitClick");
   }

   public boolean onSubmitClick() {
      dostuff();
      return true;
   }
}

it will change to:

public class MyPage extends Page {

   public void onInit() {
     Submit submit = new Submit("submit");
     submit.setActionListener(new AjaxAdapter(){

       // This method replaces onSubmitClick() above and is called for non-Ajax requests
       public boolean onAction(Control control) {
         dostuff();
         return true;
       }

       // This method is optional and only called for Ajax requests which target the submit
button
       public Partial onAjaxAction(Control control) {
          ...
       }

     });
   }
}


kind regards

bob

dshah wrote:

&gt; 
&gt; I was looking at the ClickClick examples but it looks like in order to use
&gt; that we'd have to rewrite all our current code base to support the
&gt; AjaxAdapter etc.


&gt; 
&gt; I was hoping to use our current code base which uses Click 1.5 to simply do
&gt; what we want (which is calling the servlet to get a partial form) - our
&gt; current code base configures the form objects (using Click controls) on the
&gt; server side and then renders it on the browser.. Very minimal javascript
&gt; validation and selection is done through raw javascript, no libraries.  So
&gt; my idea was to continue using the raw libraries to do what we are doing but
&gt; also use some ajax library like JQuery or Prototype (we are not particular
&gt; what we use) to render part of the form.. The partial form is dependendant
&gt; (child selection) based on the user's selection (parent selection) and needs
&gt; to be connect (hooked to the user's selection as the dependant would change
&gt; based on the parent's selection.)
&gt; 
&gt; Any tips are appreciated.
&gt; Thanks again!
&gt; Dipita
&gt; 
&gt; 
&gt; Bob Schellink-2 wrote:
&gt;&gt; Hi Dipita,
&gt;&gt;
&gt;&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt;&gt; AutoCompleteField) but you can 
&gt;&gt; use Ajax with Click. Simply invoke a target Page and stream back the
&gt;&gt; result you need. You probably 
&gt;&gt; want to look at the method Context#renderTemplate() so you can render
&gt;&gt; different templates depending 
&gt;&gt; on the request parameter. Or you can create specific Pages to handle Ajax
&gt;&gt; requests.
&gt;&gt;
&gt;&gt; Since I'm not sure what problems you are having here are some things to
&gt;&gt; look at when working with Ajax:
&gt;&gt;
&gt;&gt; - Ajax calls can use different content types eg: HTML, JSON, XML. So
&gt;&gt; depending on what you stream 
&gt;&gt; back to the browser you probably want to override the Page#getContentType
&gt;&gt; to specify the correct type:
&gt;&gt;
&gt;&gt;    public String getContentType() {
&gt;&gt;      return "text/json; charset=UTF-8";
&gt;&gt;    }
&gt;&gt;
&gt;&gt; - If you want to render partial results (and not have the default Page
&gt;&gt; template invoked) you have to 
&gt;&gt; set the Page path to null. Have a look at the method "export" in the
&gt;&gt; example here[1].
&gt;&gt;
&gt;&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt;&gt; especially the ajax-select demo.
&gt;&gt;
&gt;&gt; There is also a project underway to add Ajax components but it targets
&gt;&gt; Click 2.1.0
&gt;&gt;
&gt;&gt; Btw are you using a JavaScript library?
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt; [1]: 
&gt;&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java
&gt;&gt;
&gt;&gt; dshah wrote:
&gt;&gt;&gt; We are using Apache Click for our webapp and need to incorporate a way to
&gt;&gt;&gt; dynamically load partial forms based on the user's selection - does
&gt;&gt;&gt; anyone
&gt;&gt;&gt; know how we can do this with Click?  Is there support for Ajax with Click
&gt;&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt;&gt; documentation. Any help is appreciated as I am struggling to get any ajax
&gt;&gt;&gt; to
&gt;&gt;&gt; work with click.
&gt;&gt;&gt;
&gt;&gt;&gt; Thank you - someone please read and respond - really appreciate it.
&gt;&gt;&gt; Dipita
&gt;&gt;
&gt;&gt;
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1259980618306-4116230.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1259980618306-4116230-post@n2-nabble-com%3e</id>
<updated>2009-12-05T02:36:58Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

THANK YOU Bob for  your response.  We are currently not using any javascript
library and have the need to do so to load partial parts of a form.

Basically, we need to send a call to the server to load a section of the
form depending on the user's selection as loading the whole form pre-user
selection makes the form too huge and useless.  We were thinking of using
some javascript libraries (JQuery or something else) to load this partial
form but I am having a hard time.. I am fairly new to both AJAX and Click
Servlet.  

I was looking at the ClickClick examples but it looks like in order to use
that we'd have to rewrite all our current code base to support the
AjaxAdapter etc.

I was hoping to use our current code base which uses Click 1.5 to simply do
what we want (which is calling the servlet to get a partial form) - our
current code base configures the form objects (using Click controls) on the
server side and then renders it on the browser.. Very minimal javascript
validation and selection is done through raw javascript, no libraries.  So
my idea was to continue using the raw libraries to do what we are doing but
also use some ajax library like JQuery or Prototype (we are not particular
what we use) to render part of the form.. The partial form is dependendant
(child selection) based on the user's selection (parent selection) and needs
to be connect (hooked to the user's selection as the dependant would change
based on the parent's selection.)

Any tips are appreciated.
Thanks again!
Dipita


Bob Schellink-2 wrote:
&gt; 
&gt; Hi Dipita,
&gt; 
&gt; For Click 1.5 there aren't any Ajax specific components (except for
&gt; AutoCompleteField) but you can 
&gt; use Ajax with Click. Simply invoke a target Page and stream back the
&gt; result you need. You probably 
&gt; want to look at the method Context#renderTemplate() so you can render
&gt; different templates depending 
&gt; on the request parameter. Or you can create specific Pages to handle Ajax
&gt; requests.
&gt; 
&gt; Since I'm not sure what problems you are having here are some things to
&gt; look at when working with Ajax:
&gt; 
&gt; - Ajax calls can use different content types eg: HTML, JSON, XML. So
&gt; depending on what you stream 
&gt; back to the browser you probably want to override the Page#getContentType
&gt; to specify the correct type:
&gt; 
&gt;    public String getContentType() {
&gt;      return "text/json; charset=UTF-8";
&gt;    }
&gt; 
&gt; - If you want to render partial results (and not have the default Page
&gt; template invoked) you have to 
&gt; set the Page path to null. Have a look at the method "export" in the
&gt; example here[1].
&gt; 
&gt; The click-examples ship a couple of Ajax examples you can look at,
&gt; especially the ajax-select demo.
&gt; 
&gt; There is also a project underway to add Ajax components but it targets
&gt; Click 2.1.0
&gt; 
&gt; Btw are you using a JavaScript library?
&gt; 
&gt; kind regards
&gt; 
&gt; bob
&gt; 
&gt; [1]: 
&gt; http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java
&gt; 
&gt; dshah wrote:
&gt;&gt; We are using Apache Click for our webapp and need to incorporate a way to
&gt;&gt; dynamically load partial forms based on the user's selection - does
&gt;&gt; anyone
&gt;&gt; know how we can do this with Click?  Is there support for Ajax with Click
&gt;&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt;&gt; documentation. Any help is appreciated as I am struggling to get any ajax
&gt;&gt; to
&gt;&gt; work with click.
&gt;&gt; 
&gt;&gt; Thank you - someone please read and respond - really appreciate it.
&gt;&gt; Dipita
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4116230.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B19C435.8050602@gmail.com%3e"/>
<id>urn:uuid:%3c4B19C435-8050602@gmail-com%3e</id>
<updated>2009-12-05T02:23:49Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Dipita,

For Click 1.5 there aren't any Ajax specific components (except for AutoCompleteField) but
you can 
use Ajax with Click. Simply invoke a target Page and stream back the result you need. You
probably 
want to look at the method Context#renderTemplate() so you can render different templates
depending 
on the request parameter. Or you can create specific Pages to handle Ajax requests.

Since I'm not sure what problems you are having here are some things to look at when working
with Ajax:

- Ajax calls can use different content types eg: HTML, JSON, XML. So depending on what you
stream 
back to the browser you probably want to override the Page#getContentType to specify the correct
type:

   public String getContentType() {
     return "text/json; charset=UTF-8";
   }

- If you want to render partial results (and not have the default Page template invoked) you
have to 
set the Page path to null. Have a look at the method "export" in the example here[1].

The click-examples ship a couple of Ajax examples you can look at, especially the ajax-select
demo.

There is also a project underway to add Ajax components but it targets Click 2.1.0

Btw are you using a JavaScript library?

kind regards

bob

[1]: 
http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/general/ExcelExportPage.java

dshah wrote:
&gt; We are using Apache Click for our webapp and need to incorporate a way to
&gt; dynamically load partial forms based on the user's selection - does anyone
&gt; know how we can do this with Click?  Is there support for Ajax with Click
&gt; 1.5 and if so, can someone PLEASE point me to some examples or
&gt; documentation. Any help is appreciated as I am struggling to get any ajax to
&gt; work with click.
&gt; 
&gt; Thank you - someone please read and respond - really appreciate it.
&gt; Dipita



</pre>
</div>
</content>
</entry>
<entry>
<title>Does Apache Click 1.5 support Ajax - please help!</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1259976204994-4115987.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1259976204994-4115987-post@n2-nabble-com%3e</id>
<updated>2009-12-05T01:23:24Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

We are using Apache Click for our webapp and need to incorporate a way to
dynamically load partial forms based on the user's selection - does anyone
know how we can do this with Click?  Is there support for Ajax with Click
1.5 and if so, can someone PLEASE point me to some examples or
documentation. Any help is appreciated as I am struggling to get any ajax to
work with click.

Thank you - someone please read and respond - really appreciate it.
Dipita
-- 
View this message in context: http://n2.nabble.com/Does-Apache-Click-1-5-support-Ajax-please-help-tp4115987p4115987.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Click Ajax Support</title>
<author><name>dshah &lt;dipitashah@exit41.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c1259960170053-4114879.post@n2.nabble.com%3e"/>
<id>urn:uuid:%3c1259960170053-4114879-post@n2-nabble-com%3e</id>
<updated>2009-12-04T20:56:10Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi SVen,
Can you please point to examples/documentation of how to use partial page
updates and AJAX form submits with click?

Thank you!
Dipita


sven.pfeiffer wrote:
&gt; 
&gt; Hi Hantsy,
&gt; 
&gt; there is an AJAX implementation in clickclick.
&gt; Take a look at http://code.google.com/p/clickclick/
&gt; 
&gt; Partial Page updates and AJAX form submits are supported.
&gt; 
&gt; hth
&gt; SVen
&gt; 
&gt; Hantsy Bai wrote:
&gt;&gt; I want some ajax features in Click, it there some feature like this?
&gt;&gt; 1. Partial Page update (may be an Ajax Panel), or  render a page 
&gt;&gt; fragment in a panel dynamically.
&gt;&gt; eg. There are three sections in a Page, header, content, footer, I 
&gt;&gt; want to update content area by click menu in header area and It no 
&gt;&gt; need to update the whole page.
&gt;&gt;
&gt;&gt; 2. Partial form submitting (for instant validation and others behavior ).
&gt;&gt; eg. Select a item form select combox, auto fill the second select 
&gt;&gt; combox options according the item selected in the first combox.
&gt;&gt;
&gt;&gt; The click extras is shipped with prototype(it think adding 
&gt;&gt; scriptaculous support is welcome), I think many feature can be added, 
&gt;&gt; such as inplace editor, drag and draw, ajax tree(lazy loading the sub 
&gt;&gt; nodes) , other some effects provide by scriptaculous(without 
&gt;&gt; programming).
&gt;&gt;
&gt;&gt; Is there some example or some control component to implement these?
&gt;&gt;
&gt;&gt; Kind regards.
&gt;&gt;
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://n2.nabble.com/Click-Ajax-Support-tp3977325p4114879.html
Sent from the click-user mailing list archive at Nabble.com.


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: [clickclick] ajax form popup</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B16ECA3.9030701@gmail.com%3e"/>
<id>urn:uuid:%3c4B16ECA3-9030701@gmail-com%3e</id>
<updated>2009-12-02T22:39:31Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
You're right the JQForm won't be processed unless its added to the Page or at least somewhere
in the 
Page controls hierarchy. You can add JQForm or the Dialog to the Page from CategorySelect
onInit 
method using the controls #getPage method.

Sven Pfeiffer wrote:
&gt; Manipulating the dom to add the form was my first idea, too.
&gt; 
&gt; I was thinking about builing the JQForm in my CategorySelect, an using 
&gt; its render-Method to get the HTML-text for it, put this in a (hidden) 
&gt; div and add it to the DOM using javascript.
&gt; But then I was wondering if the AjaxAdapter I added to the submit-button 
&gt; inside the JQForm will be able to process the request even though the 
&gt; JQForm is never added to the click-Page 
&gt; &lt;http://dict.leo.org/ende?lp=ende&amp;p=DEdPgA&amp;search=though&gt;.
&gt; 
&gt; Bob Schellink wrote:
&gt;&gt; Hi Sven,
&gt;&gt;
&gt;&gt; This is interesting. If you don't want to add the dialog as a separate 
&gt;&gt; variable to the page template, and render it as part of the select, 
&gt;&gt; you'll probably have to use JQuery to manipulate[1] the markup, and 
&gt;&gt; append the dialog to the body. You can do this from the CategorySelect 
&gt;&gt; getHeadElements method:
&gt;&gt;
&gt;&gt;   public List getHeadElements() {
&gt;&gt;     if (headElements == null) {
&gt;&gt;       headElements = super.getHeadElements();
&gt;&gt;
&gt;&gt;       String js =   "$(document).ready(function(){"
&gt;&gt;                   + "  $('" + dialogId + "').appendTo('body');
&gt;&gt;                   + "});";
&gt;&gt;       headElements.add(new JsScript(js));
&gt;&gt;     }
&gt;&gt;     return headElements;
&gt;&gt;   }
&gt;&gt;
&gt;&gt; Another option could be to pass in a container to the constructor of 
&gt;&gt; the CategorySelect, and have the CategorySelect add its dialog to that 
&gt;&gt; container, which will be rendered in the Page template. But this seems 
&gt;&gt; pretty much what you want to avoid.
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt; [1]: http://docs.jquery.com/Manipulation
&gt;&gt;
&gt;&gt;
&gt;&gt; Sven Pfeiffer wrote:
&gt;&gt;&gt; Hi Bob,
&gt;&gt;&gt;
&gt;&gt;&gt; jqModal did the trick nicely.
&gt;&gt;&gt;
&gt;&gt;&gt; Now i have the following issue:
&gt;&gt;&gt;
&gt;&gt;&gt; I built a custom select called CategorySelect, whichs option are 
&gt;&gt;&gt; based on a MySQL-table (using hibernate).
&gt;&gt;&gt; The select has an add-Button that enabled the User to add categories 
&gt;&gt;&gt; to the database (and to the select).
&gt;&gt;&gt;
&gt;&gt;&gt; Now I would like to add the CategorySelect to various Forms 
&gt;&gt;&gt; (including TabbedForms and FormTables).
&gt;&gt;&gt;
&gt;&gt;&gt; How can the CategorySelect add its JQAjax-Form (which is inside the 
&gt;&gt;&gt; JQModal-Popup) to the page.
&gt;&gt;&gt; I could render it using the CategorySelects render-Method, but then 
&gt;&gt;&gt; the ajax-form would be nested within the "normal" form.
&gt;&gt;&gt;
&gt;&gt;&gt; Is there another way to add the ajax-form to the page without having 
&gt;&gt;&gt; to add it to the template?
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks for your help
&gt;&gt;&gt; SVen
&gt;&gt;&gt;
&gt;&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt;&gt; Hi Sven,
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; If you're using JQuery you could take a look at JQModal:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; http://dev.iceburg.net/jquery/jqModal/
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Not sure how you want things to work, but if you want to have 
&gt;&gt;&gt;&gt; reusable component, you could look at creating a custom dialog 
&gt;&gt;&gt;&gt; container which includes the JQModal javascript+css. The Dialog 
&gt;&gt;&gt;&gt; should add a JavaScript function that can be called to show the dialog.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; So you end up with something that can be used as follows:
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; public MyPage extends PAge {
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;&gt;     MyDialog dialog = new MyDialog("dialog");
&gt;&gt;&gt;&gt;     Form form = buildForm();
&gt;&gt;&gt;&gt;     dialog.add(form);
&gt;&gt;&gt;&gt;     addControl(dialog);
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;     Button showForm = new Button("showForm");
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;     showForm.setAttribute("onclick", "showDialog('dialog')");
&gt;&gt;&gt;&gt;     // showDialog is the JavaScript method that MyDialog adds to the 
&gt;&gt;&gt;&gt; Page
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;     addControl(showForm);
&gt;&gt;&gt;&gt;   }
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; If its more of a one time thing your after, you can just add the 
&gt;&gt;&gt;&gt; necessary javascript/css resources and functions to your page template.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; kind regards
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; bob
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; sven.pfeiffer@madsep.de wrote:
&gt;&gt;&gt;&gt;&gt; Hi List,
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I am trying to build dynamic select boxes for my application.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I have extended the Select element and added two buttons to add and 
&gt;&gt;&gt;&gt;&gt; edit
&gt;&gt;&gt;&gt;&gt; entries, in the moment the buttons open a new window showing a 
&gt;&gt;&gt;&gt;&gt; click page to
&gt;&gt;&gt;&gt;&gt; add/edit an entry.
&gt;&gt;&gt;&gt;&gt; Now I'd like to replace the browser-popup windows by some ajax 
&gt;&gt;&gt;&gt;&gt; dialogs.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; I already implemented an ajax form for add/edit but I'm having some 
&gt;&gt;&gt;&gt;&gt; troubles
&gt;&gt;&gt;&gt;&gt; getting the form in a javascript popup/dialog.
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Has anyone tried this yet and could give me a hint?
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt; Thanks in advance
&gt;&gt;&gt;&gt;&gt; SVen
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: [clickclick] ajax form popup</title>
<author><name>Sven Pfeiffer &lt;sven.pfeiffer@madsep.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B16E25C.4080003@madsep.de%3e"/>
<id>urn:uuid:%3c4B16E25C-4080003@madsep-de%3e</id>
<updated>2009-12-02T21:55:40Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Manipulating the dom to add the form was my first idea, too.

I was thinking about builing the JQForm in my CategorySelect, an using 
its render-Method to get the HTML-text for it, put this in a (hidden) 
div and add it to the DOM using javascript.
But then I was wondering if the AjaxAdapter I added to the submit-button 
inside the JQForm will be able to process the request even though the 
JQForm is never added to the click-Page 
&lt;http://dict.leo.org/ende?lp=ende&amp;p=DEdPgA&amp;search=though&gt;.

Bob Schellink wrote:
&gt; Hi Sven,
&gt;
&gt; This is interesting. If you don't want to add the dialog as a separate 
&gt; variable to the page template, and render it as part of the select, 
&gt; you'll probably have to use JQuery to manipulate[1] the markup, and 
&gt; append the dialog to the body. You can do this from the CategorySelect 
&gt; getHeadElements method:
&gt;
&gt;   public List getHeadElements() {
&gt;     if (headElements == null) {
&gt;       headElements = super.getHeadElements();
&gt;
&gt;       String js =   "$(document).ready(function(){"
&gt;                   + "  $('" + dialogId + "').appendTo('body');
&gt;                   + "});";
&gt;       headElements.add(new JsScript(js));
&gt;     }
&gt;     return headElements;
&gt;   }
&gt;
&gt; Another option could be to pass in a container to the constructor of 
&gt; the CategorySelect, and have the CategorySelect add its dialog to that 
&gt; container, which will be rendered in the Page template. But this seems 
&gt; pretty much what you want to avoid.
&gt;
&gt; kind regards
&gt;
&gt; bob
&gt;
&gt; [1]: http://docs.jquery.com/Manipulation
&gt;
&gt;
&gt; Sven Pfeiffer wrote:
&gt;&gt; Hi Bob,
&gt;&gt;
&gt;&gt; jqModal did the trick nicely.
&gt;&gt;
&gt;&gt; Now i have the following issue:
&gt;&gt;
&gt;&gt; I built a custom select called CategorySelect, whichs option are 
&gt;&gt; based on a MySQL-table (using hibernate).
&gt;&gt; The select has an add-Button that enabled the User to add categories 
&gt;&gt; to the database (and to the select).
&gt;&gt;
&gt;&gt; Now I would like to add the CategorySelect to various Forms 
&gt;&gt; (including TabbedForms and FormTables).
&gt;&gt;
&gt;&gt; How can the CategorySelect add its JQAjax-Form (which is inside the 
&gt;&gt; JQModal-Popup) to the page.
&gt;&gt; I could render it using the CategorySelects render-Method, but then 
&gt;&gt; the ajax-form would be nested within the "normal" form.
&gt;&gt;
&gt;&gt; Is there another way to add the ajax-form to the page without having 
&gt;&gt; to add it to the template?
&gt;&gt;
&gt;&gt; Thanks for your help
&gt;&gt; SVen
&gt;&gt;
&gt;&gt; Bob Schellink wrote:
&gt;&gt;&gt; Hi Sven,
&gt;&gt;&gt;
&gt;&gt;&gt; If you're using JQuery you could take a look at JQModal:
&gt;&gt;&gt;
&gt;&gt;&gt; http://dev.iceburg.net/jquery/jqModal/
&gt;&gt;&gt;
&gt;&gt;&gt; Not sure how you want things to work, but if you want to have 
&gt;&gt;&gt; reusable component, you could look at creating a custom dialog 
&gt;&gt;&gt; container which includes the JQModal javascript+css. The Dialog 
&gt;&gt;&gt; should add a JavaScript function that can be called to show the dialog.
&gt;&gt;&gt;
&gt;&gt;&gt; So you end up with something that can be used as follows:
&gt;&gt;&gt;
&gt;&gt;&gt; public MyPage extends PAge {
&gt;&gt;&gt;
&gt;&gt;&gt;   public void onInit() {
&gt;&gt;&gt;     MyDialog dialog = new MyDialog("dialog");
&gt;&gt;&gt;     Form form = buildForm();
&gt;&gt;&gt;     dialog.add(form);
&gt;&gt;&gt;     addControl(dialog);
&gt;&gt;&gt;
&gt;&gt;&gt;     Button showForm = new Button("showForm");
&gt;&gt;&gt;
&gt;&gt;&gt;     showForm.setAttribute("onclick", "showDialog('dialog')");
&gt;&gt;&gt;     // showDialog is the JavaScript method that MyDialog adds to the 
&gt;&gt;&gt; Page
&gt;&gt;&gt;
&gt;&gt;&gt;     addControl(showForm);
&gt;&gt;&gt;   }
&gt;&gt;&gt;
&gt;&gt;&gt; If its more of a one time thing your after, you can just add the 
&gt;&gt;&gt; necessary javascript/css resources and functions to your page template.
&gt;&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; sven.pfeiffer@madsep.de wrote:
&gt;&gt;&gt;&gt; Hi List,
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I am trying to build dynamic select boxes for my application.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I have extended the Select element and added two buttons to add and 
&gt;&gt;&gt;&gt; edit
&gt;&gt;&gt;&gt; entries, in the moment the buttons open a new window showing a 
&gt;&gt;&gt;&gt; click page to
&gt;&gt;&gt;&gt; add/edit an entry.
&gt;&gt;&gt;&gt; Now I'd like to replace the browser-popup windows by some ajax 
&gt;&gt;&gt;&gt; dialogs.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I already implemented an ajax form for add/edit but I'm having some 
&gt;&gt;&gt;&gt; troubles
&gt;&gt;&gt;&gt; getting the form in a javascript popup/dialog.
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Has anyone tried this yet and could give me a hint?
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt; Thanks in advance
&gt;&gt;&gt;&gt; SVen
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;
&gt;



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: [clickclick] ajax form popup</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B16DF4C.1070201@gmail.com%3e"/>
<id>urn:uuid:%3c4B16DF4C-1070201@gmail-com%3e</id>
<updated>2009-12-02T21:42:36Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Sven,

This is interesting. If you don't want to add the dialog as a separate variable to the page

template, and render it as part of the select, you'll probably have to use JQuery to manipulate[1]

the markup, and append the dialog to the body. You can do this from the CategorySelect 
getHeadElements method:

   public List getHeadElements() {
     if (headElements == null) {
       headElements = super.getHeadElements();

       String js =   "$(document).ready(function(){"
                   + "  $('" + dialogId + "').appendTo('body');
                   + "});";
       headElements.add(new JsScript(js));
     }
     return headElements;
   }

Another option could be to pass in a container to the constructor of the CategorySelect, and
have 
the CategorySelect add its dialog to that container, which will be rendered in the Page template.

But this seems pretty much what you want to avoid.

kind regards

bob

[1]: http://docs.jquery.com/Manipulation


Sven Pfeiffer wrote:
&gt; Hi Bob,
&gt; 
&gt; jqModal did the trick nicely.
&gt; 
&gt; Now i have the following issue:
&gt; 
&gt; I built a custom select called CategorySelect, whichs option are based 
&gt; on a MySQL-table (using hibernate).
&gt; The select has an add-Button that enabled the User to add categories to 
&gt; the database (and to the select).
&gt; 
&gt; Now I would like to add the CategorySelect to various Forms (including 
&gt; TabbedForms and FormTables).
&gt; 
&gt; How can the CategorySelect add its JQAjax-Form (which is inside the 
&gt; JQModal-Popup) to the page.
&gt; I could render it using the CategorySelects render-Method, but then the 
&gt; ajax-form would be nested within the "normal" form.
&gt; 
&gt; Is there another way to add the ajax-form to the page without having to 
&gt; add it to the template?
&gt; 
&gt; Thanks for your help
&gt; SVen
&gt; 
&gt; Bob Schellink wrote:
&gt;&gt; Hi Sven,
&gt;&gt;
&gt;&gt; If you're using JQuery you could take a look at JQModal:
&gt;&gt;
&gt;&gt; http://dev.iceburg.net/jquery/jqModal/
&gt;&gt;
&gt;&gt; Not sure how you want things to work, but if you want to have reusable 
&gt;&gt; component, you could look at creating a custom dialog container which 
&gt;&gt; includes the JQModal javascript+css. The Dialog should add a 
&gt;&gt; JavaScript function that can be called to show the dialog.
&gt;&gt;
&gt;&gt; So you end up with something that can be used as follows:
&gt;&gt;
&gt;&gt; public MyPage extends PAge {
&gt;&gt;
&gt;&gt;   public void onInit() {
&gt;&gt;     MyDialog dialog = new MyDialog("dialog");
&gt;&gt;     Form form = buildForm();
&gt;&gt;     dialog.add(form);
&gt;&gt;     addControl(dialog);
&gt;&gt;
&gt;&gt;     Button showForm = new Button("showForm");
&gt;&gt;
&gt;&gt;     showForm.setAttribute("onclick", "showDialog('dialog')");
&gt;&gt;     // showDialog is the JavaScript method that MyDialog adds to the Page
&gt;&gt;
&gt;&gt;     addControl(showForm);
&gt;&gt;   }
&gt;&gt;
&gt;&gt; If its more of a one time thing your after, you can just add the 
&gt;&gt; necessary javascript/css resources and functions to your page template.
&gt;&gt;
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt; sven.pfeiffer@madsep.de wrote:
&gt;&gt;&gt; Hi List,
&gt;&gt;&gt;
&gt;&gt;&gt; I am trying to build dynamic select boxes for my application.
&gt;&gt;&gt;
&gt;&gt;&gt; I have extended the Select element and added two buttons to add and edit
&gt;&gt;&gt; entries, in the moment the buttons open a new window showing a click 
&gt;&gt;&gt; page to
&gt;&gt;&gt; add/edit an entry.
&gt;&gt;&gt; Now I'd like to replace the browser-popup windows by some ajax dialogs.
&gt;&gt;&gt;
&gt;&gt;&gt; I already implemented an ajax form for add/edit but I'm having some 
&gt;&gt;&gt; troubles
&gt;&gt;&gt; getting the form in a javascript popup/dialog.
&gt;&gt;&gt;
&gt;&gt;&gt; Has anyone tried this yet and could give me a hint?
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks in advance
&gt;&gt;&gt; SVen
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt; 
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: [clickclick] ajax form popup</title>
<author><name>Sven Pfeiffer &lt;sven.pfeiffer@madsep.de&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200912.mbox/%3c4B16D6F9.5010509@madsep.de%3e"/>
<id>urn:uuid:%3c4B16D6F9-5010509@madsep-de%3e</id>
<updated>2009-12-02T21:07:05Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Bob,

jqModal did the trick nicely.

Now i have the following issue:

I built a custom select called CategorySelect, whichs option are based 
on a MySQL-table (using hibernate).
The select has an add-Button that enabled the User to add categories to 
the database (and to the select).

Now I would like to add the CategorySelect to various Forms (including 
TabbedForms and FormTables).

How can the CategorySelect add its JQAjax-Form (which is inside the 
JQModal-Popup) to the page.
I could render it using the CategorySelects render-Method, but then the 
ajax-form would be nested within the "normal" form.

Is there another way to add the ajax-form to the page without having to 
add it to the template?

Thanks for your help
SVen

Bob Schellink wrote:
&gt; Hi Sven,
&gt;
&gt; If you're using JQuery you could take a look at JQModal:
&gt;
&gt; http://dev.iceburg.net/jquery/jqModal/
&gt;
&gt; Not sure how you want things to work, but if you want to have reusable 
&gt; component, you could look at creating a custom dialog container which 
&gt; includes the JQModal javascript+css. The Dialog should add a 
&gt; JavaScript function that can be called to show the dialog.
&gt;
&gt; So you end up with something that can be used as follows:
&gt;
&gt; public MyPage extends PAge {
&gt;
&gt;   public void onInit() {
&gt;     MyDialog dialog = new MyDialog("dialog");
&gt;     Form form = buildForm();
&gt;     dialog.add(form);
&gt;     addControl(dialog);
&gt;
&gt;     Button showForm = new Button("showForm");
&gt;
&gt;     showForm.setAttribute("onclick", "showDialog('dialog')");
&gt;     // showDialog is the JavaScript method that MyDialog adds to the Page
&gt;
&gt;     addControl(showForm);
&gt;   }
&gt;
&gt; If its more of a one time thing your after, you can just add the 
&gt; necessary javascript/css resources and functions to your page template.
&gt;
&gt; kind regards
&gt;
&gt; bob
&gt;
&gt; sven.pfeiffer@madsep.de wrote:
&gt;&gt; Hi List,
&gt;&gt;
&gt;&gt; I am trying to build dynamic select boxes for my application.
&gt;&gt;
&gt;&gt; I have extended the Select element and added two buttons to add and edit
&gt;&gt; entries, in the moment the buttons open a new window showing a click 
&gt;&gt; page to
&gt;&gt; add/edit an entry.
&gt;&gt; Now I'd like to replace the browser-popup windows by some ajax dialogs.
&gt;&gt;
&gt;&gt; I already implemented an ajax form for add/edit but I'm having some 
&gt;&gt; troubles
&gt;&gt; getting the form in a javascript popup/dialog.
&gt;&gt;
&gt;&gt; Has anyone tried this yet and could give me a hint?
&gt;&gt;
&gt;&gt; Thanks in advance
&gt;&gt; SVen
&gt;&gt;
&gt;&gt;
&gt;
&gt;



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: About click localization and encoding ???</title>
<author><name>Hantsy Bai &lt;hantsy@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200911.mbox/%3c4B11D4D5.8060901@gmail.com%3e"/>
<id>urn:uuid:%3c4B11D4D5-8060901@gmail-com%3e</id>
<updated>2009-11-29T01:56:37Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
On 11/29/2009 08:45 AM, Bob Schellink wrote:
&gt; I just checked the FAQ and there is a topic on the charset and i18n:
&gt;
&gt; http://incubator.apache.org/click/docs/faq.html#charset
&gt; http://incubator.apache.org/click/docs/faq.html#localization
&gt;
&gt; Setting charset in click.xml influences not only the request, but also
&gt; the Velocity runtime. So its best to set charset attribute in
&gt; click.xml and have all components pick up the same encoding.
&gt;
&gt; I also think browsers will use the Content-Type response header in
&gt; favor of the Content-Type meta-tag, although it doesn't hurt to set both.
&gt;
&gt; kind regards
&gt;
&gt; bob
&gt;
&gt; Hantsy Bai wrote:
&gt;&gt; On 11/28/2009 09:48 PM, Bob Schellink wrote:
&gt;&gt;&gt; Hi Hantsy,
&gt;&gt;&gt;
&gt;&gt;&gt; Hantsy Bai wrote:
&gt;&gt;&gt;
&gt;&gt;&gt;&gt; I know this, I use NetBeans to develop my project, it convert
&gt;&gt;&gt;&gt; properties
&gt;&gt;&gt;&gt; file automatically.
&gt;&gt;&gt;&gt; My project use UTF 8 encoding..
&gt;&gt;&gt;&gt; If I do not set "charset" in click.xml, It will cause the display
&gt;&gt;&gt;&gt; problem. As I set charset="UTF-8", It works.
&gt;&gt;&gt;&gt; I think it should be determined by the Client browser firstly(high
&gt;&gt;&gt;&gt; priority).
&gt;&gt;&gt;&gt; It is unreasonable I set the default encoding , but it is not applied.
&gt;&gt;&gt;
&gt;&gt;&gt; I don't follow. It sounds as if you expect the server to set the
&gt;&gt;&gt; encoding based on a browser request header? Since content is hosted on
&gt;&gt;&gt; the server I would think its the servers responsibility to set the
&gt;&gt;&gt; encoding, the client wouldn't know what the encoding will be, right?
&gt;&gt;&gt;
&gt;&gt;&gt; Furthermore HTTP 1.1 standard specifies that the default encoding is
&gt;&gt;&gt; "ISO-8859-1" which Click complies with. If no charset is set, Click
&gt;&gt;&gt; returns "ISO-8859-1". See [1].
&gt;&gt;&gt;
&gt;&gt;&gt; Let us know what you find unreasonable about this approach and we
&gt;&gt;&gt; might be able to fix it. But from what I can see Click follows the
&gt;&gt;&gt; standard regarding encoding.
&gt;&gt;&gt;
&gt;&gt;&gt; Its still easy to change the default charset using click.xml as you've
&gt;&gt;&gt; already done. Your border-template.htm should also specify the
&gt;&gt;&gt; content-type meta tag:
&gt;&gt;&gt;
&gt;&gt;&gt;   &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
&gt;&gt;
&gt;&gt; Yeah, I set this meta base border template, but if I do not set
&gt;&gt; "charset" in click.xml, It do noes display Chinese (display in template
&gt;&gt; page via getMessage() in class  from properties file ) correctly.
&gt;&gt;  
&gt;&gt;
&gt;&gt;&gt; kind regards
&gt;&gt;&gt;
&gt;&gt;&gt; bob
&gt;&gt;&gt;
&gt;&gt;&gt; [1]:
&gt;&gt;&gt; http://incubator.apache.org/click/docs/click-api/org/apache/click/Context.html#getCharset()
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;
&gt;
Ok,
Thank you for your patience.


-- 
Hantsy Bai 
Guangzhou, China
http://hantsy.blogspot.com



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: About click localization and encoding ???</title>
<author><name>Bob Schellink &lt;sabob1@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200911.mbox/%3c4B11C423.6050604@gmail.com%3e"/>
<id>urn:uuid:%3c4B11C423-6050604@gmail-com%3e</id>
<updated>2009-11-29T00:45:23Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I just checked the FAQ and there is a topic on the charset and i18n:

http://incubator.apache.org/click/docs/faq.html#charset
http://incubator.apache.org/click/docs/faq.html#localization

Setting charset in click.xml influences not only the request, but also the Velocity runtime.
So its 
best to set charset attribute in click.xml and have all components pick up the same encoding.

I also think browsers will use the Content-Type response header in favor of the Content-Type

meta-tag, although it doesn't hurt to set both.

kind regards

bob

Hantsy Bai wrote:
&gt; On 11/28/2009 09:48 PM, Bob Schellink wrote:
&gt;&gt; Hi Hantsy,
&gt;&gt;
&gt;&gt; Hantsy Bai wrote:
&gt;&gt;
&gt;&gt;&gt; I know this, I use NetBeans to develop my project, it convert properties
&gt;&gt;&gt; file automatically.
&gt;&gt;&gt; My project use UTF 8 encoding..
&gt;&gt;&gt; If I do not set "charset" in click.xml, It will cause the display
&gt;&gt;&gt; problem. As I set charset="UTF-8", It works.
&gt;&gt;&gt; I think it should be determined by the Client browser firstly(high
&gt;&gt;&gt; priority).
&gt;&gt;&gt; It is unreasonable I set the default encoding , but it is not applied.
&gt;&gt;
&gt;&gt; I don't follow. It sounds as if you expect the server to set the
&gt;&gt; encoding based on a browser request header? Since content is hosted on
&gt;&gt; the server I would think its the servers responsibility to set the
&gt;&gt; encoding, the client wouldn't know what the encoding will be, right?
&gt;&gt;
&gt;&gt; Furthermore HTTP 1.1 standard specifies that the default encoding is
&gt;&gt; "ISO-8859-1" which Click complies with. If no charset is set, Click
&gt;&gt; returns "ISO-8859-1". See [1].
&gt;&gt;
&gt;&gt; Let us know what you find unreasonable about this approach and we
&gt;&gt; might be able to fix it. But from what I can see Click follows the
&gt;&gt; standard regarding encoding.
&gt;&gt;
&gt;&gt; Its still easy to change the default charset using click.xml as you've
&gt;&gt; already done. Your border-template.htm should also specify the
&gt;&gt; content-type meta tag:
&gt;&gt;
&gt;&gt;   &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
&gt; 
&gt; Yeah, I set this meta base border template, but if I do not set
&gt; "charset" in click.xml, It do noes display Chinese (display in template
&gt; page via getMessage() in class  from properties file ) correctly.
&gt;  
&gt; 
&gt;&gt; kind regards
&gt;&gt;
&gt;&gt; bob
&gt;&gt;
&gt;&gt; [1]:
&gt;&gt; http://incubator.apache.org/click/docs/click-api/org/apache/click/Context.html#getCharset()
&gt;&gt;
&gt;&gt;
&gt; 
&gt; 



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: About click localization and encoding ???</title>
<author><name>Hantsy Bai &lt;hantsy@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/incubator-click-user/200911.mbox/%3c4B113E7B.5060103@gmail.com%3e"/>
<id>urn:uuid:%3c4B113E7B-5060103@gmail-com%3e</id>
<updated>2009-11-28T15:15:07Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
On 11/28/2009 09:48 PM, Bob Schellink wrote:
&gt; Hi Hantsy,
&gt;
&gt; Hantsy Bai wrote:
&gt;
&gt;&gt; I know this, I use NetBeans to develop my project, it convert properties
&gt;&gt; file automatically.
&gt;&gt; My project use UTF 8 encoding..
&gt;&gt; If I do not set "charset" in click.xml, It will cause the display
&gt;&gt; problem. As I set charset="UTF-8", It works.
&gt;&gt; I think it should be determined by the Client browser firstly(high
&gt;&gt; priority).
&gt;&gt; It is unreasonable I set the default encoding , but it is not applied.
&gt;
&gt;
&gt; I don't follow. It sounds as if you expect the server to set the
&gt; encoding based on a browser request header? Since content is hosted on
&gt; the server I would think its the servers responsibility to set the
&gt; encoding, the client wouldn't know what the encoding will be, right?
&gt;
&gt; Furthermore HTTP 1.1 standard specifies that the default encoding is
&gt; "ISO-8859-1" which Click complies with. If no charset is set, Click
&gt; returns "ISO-8859-1". See [1].
&gt;
&gt; Let us know what you find unreasonable about this approach and we
&gt; might be able to fix it. But from what I can see Click follows the
&gt; standard regarding encoding.
&gt;
&gt; Its still easy to change the default charset using click.xml as you've
&gt; already done. Your border-template.htm should also specify the
&gt; content-type meta tag:
&gt;
&gt;   &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;

Yeah, I set this meta base border template, but if I do not set
"charset" in click.xml, It do noes display Chinese (display in template
page via getMessage() in class  from properties file ) correctly.
 

&gt;
&gt; kind regards
&gt;
&gt; bob
&gt;
&gt; [1]:
&gt; http://incubator.apache.org/click/docs/click-api/org/apache/click/Context.html#getCharset()
&gt;
&gt;


-- 
Hantsy Bai 
Guangzhou, China
http://hantsy.blogspot.com



</pre>
</div>
</content>
</entry>
</feed>
