Hi Claude,

you can use chenillekit mixin OnEvent (). Here is the link:
http://www.chenillekit.org/chenillekit-tapestry/ref/org/chenillekit/tapestry/core/mixins/OnEvent.html

If you are developing with Tapestry 5.1, then put

<dependency>
    <groupId>org.chenillekit</groupId>
    <artifactId>chenillekit-tapestry</artifactId>
    <version>1.2.0</version>
    <exclusions>
        <exclusion>
          <groupId>jboss</groupId>
          <artifactId>javassist</artifactId>
        </exclusion>
    </exclusions>
</dependency>

in your POM.

In your template use the mixin on the input field:

<t:label for="email"/>:
<input t:type="TextField" t:id="email" value="email"
t:validate="required,regexp,maxLength=255" t:mixins="ck/OnEvent"
event="blur" onCompleteCallback="onCompletePrefillInputFields" size="30"/>

Then in your class:

@IncludeJavaScriptLibrary("context:js/util.js")
public class Index {
...
    @Property
    private String email;
...
    @OnEvent(component = "email", value = "blur")
    public JSONObject checkIfUserWithThisEmailExists(String value) {
        UserData userData = new UserData();
        if(value.equals("b...@example.com")) {
            logger.info("Exists.");
            userData.setPostOfficeNumberAndName("1236 Trzin");
            userData.setGender("male");
            userData.setBirthDay("29");
            userData.setBirthMonth("4");
            userData.setBirthYear("1973");
        } else {
            logger.info("Bob does not exist.");
        }
        JSONObject jsonObject = new
JSONObject(JSONSerializer.toJSON(userData).toString());
        return jsonObject;
    }
...

Create util.js in src/main/webapp/js and put the callback function which
updates your page's data in there, like:

function onCompletePrefillInputFields(response)
{
    Tapestry.debug("onCompletePrefillInputFields():" +
response.postOfficeNumberAndName);
    Tapestry.debug("onCompletePrefillInputFields():" + response.gender);
    Tapestry.debug("onCompletePrefillInputFields():" + response.birthDay);
    Tapestry.debug("onCompletePrefillInputFields():" + response.birthMonth);
    Tapestry.debug("onCompletePrefillInputFields():" + response.birthYear);

    $('postOffice').value = response.postOfficeNumberAndName;

    if (response.gender == "male") {
        $('radioM').checked = true;
    } else if (response.gender == "female") {
        $('radioF').checked = true;
    }

    selectOptionByValue($('select'), response.birthDay);
    //selectOptionByValue($('select_0'), response.birthMonth); // values are
month names and not a number
    if (response.birthMonth != "") {
        $('select_0').options[response.birthMonth].selected = true; // so
find by index
    }
    selectOptionByValue($('select_1'), response.birthYear);

}


That should do it.

Cheers,
Borut

2010/7/8 Claude Dubois <cduboi...@gmail.com>

>
> Hello everybody,
>
> I'm developing a Tapestry 5 application, and I would like to add an
> autocomplete functionality, but not like the one integrated in T5.
>
> What I want to do is to search in my database the corresponding name of one
> part from its number, e.g. to detect the "onblur" action on my textfield to
> trigger this search. Once the search is over, the part name will appear in
> the corresponding textfield.
>
> Does anyone have any idea of how it is possible to detect "onBlur" like we
> could do in Javascript?
>
> Thank you in advance
>
> -----
> Claude Dubois
> --
> View this message in context:
> http://old.nabble.com/Realize-operations-on-%22blur%22-from-a-textfield-tp29106396p29106396.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to