You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Claude Dubois <cd...@gmail.com> on 2010/07/08 14:18:12 UTC

Realize operations on "blur" from a textfield

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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Realize operations on "blur" from a textfield

Posted by Geoff Callender <ge...@gmail.com>.
Your problem is almost identical to the problem of doing client-side validation with AJAX.  I think this will provide most of the solution:

	http://jumpstart.doublenegative.com.au/jumpstart/examples/input/ajaxvalidators1

You'd replace CustomError with your textfield. CustomError is listed in:

	http://jumpstart.doublenegative.com.au/jumpstart/examples/input/novalidationbubbles1

Cheers,

Geoff

On 08/07/2010, at 10:18 PM, Claude Dubois wrote:

> 
> 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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: Realize operations on "blur" from a textfield

Posted by Claude Dubois <cd...@gmail.com>.
I have found on Jumpstart Doublenegative a mixin which matches my needs.

It's the ZoneUpdater mixin by Inge Solvoll, and it is very easy to setup.

Here is the source code of the ZoneUpdater : 
     http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html

Here is the demonstration in Jumpstart : 
    
http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/ajaxonevent

If it can be useful to someone else.

Thanks for your answers !


-----
Claude Dubois
-- 
View this message in context: http://old.nabble.com/Realize-operations-on-%22blur%22-from-a-textfield-tp29106396p29115371.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Realize operations on "blur" from a textfield

Posted by Borut Bolčina <bo...@gmail.com>.
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("bob@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 <cd...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Realize operations on "blur" from a textfield

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 08 Jul 2010 09:18:12 -0300, Claude Dubois <cd...@gmail.com>  
wrote:

> Does anyone have any idea of how it is possible to detect "onBlur" like  
> we could do in Javascript?

Tapestry works on the server-side, so you need to listen to the Javascript  
event yourself then trigger a server-side event to process it. Check the  
examples in JumpStart: http://jumpstart.doublenegative.com.au/jumpstart/

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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