You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ramarao Venkata <ra...@gmail.com> on 2007/07/20 07:37:36 UTC

[Tobago] when
Hi,

I has a tc:in and a tc:link.  when we click on the link the form is submited
even though no value value in tc:in.
When there is no value in tc:in and pressed on <tc:link i should not submit
instead i should display an alert message.

With in tc:in when i press enter i need to invoke the action specified in
tc:link. do i need register for any key listener

My code is written as below

<tc:cell>
    <tc:in id="search" width="130px"
        value="#{search.searchText}"
        suggestMethod = "#{search.suggestSearch}" />
    <tc:link image="img/search.gif"
             action="#{search.searchItems}" />
</tc:cell>


kindly suggest a solution.

regards
Ramarao

Re: [Tobago] when Posted by Zied Hamdi <ja...@gmail.com>.
Hi Ramarao,

I suggest you to return null in search.searchItems() if the input is empty
(and use ajax to refresh only the component "search", elsewhere give an
outcome that redirects to the page of results.

for the ajax use

<tc:link ...>

<tc:attribute name="renderedPartially" value="search" />

</tc:link>
I didn't try it yet but it should work ifaoif your outcome is null. Take a
look at the demo app for examples.


p.s: maybe there's a better solution, I'm a beginner in tobago too.

Regards,
Zied

2007/7/20, Ramarao Venkata <ra...@gmail.com>:
>
> Hi,
>
> I has a tc:in and a tc:link.  when we click on the link the form is
> submited even though no value value in tc:in.
> When there is no value in tc:in and pressed on <tc:link i should not
> submit instead i should display an alert message.
>
> With in tc:in when i press enter i need to invoke the action specified in
> tc:link. do i need register for any key listener
>
> My code is written as below
>
> <tc:cell>
>     <tc:in id="search" width="130px"
>         value="#{search.searchText}"
>         suggestMethod = "#{search.suggestSearch}" />
>     <tc:link image="img/search.gif"
>              action="#{search.searchItems}" />
> </tc:cell>
>
>
> kindly suggest a solution.
>
> regards
> Ramarao
>
>
>
>
>
>
>
>
>
>
>


-- 
Zied Hamdi
zatreex.sourceforge.net

Re: [Tobago] when Posted by Volker Weber <v....@inexso.de>.
Hi Ramarao,

what you want is currently not possible in plain tobago. You need additional
javascript to archive this.



Try the following code:

<tc:cell>
    <tc:script onload="initInput('page:search')">
       initInput = function(id) {
         var input = Tobago.element(id);
         Tobago.addEventListener(input, "keyup", "submitActionOnEnter(event)");
       }
       submitActionOnEnter = function(event) {
         if (!event) { event = window.event;}

         var keyCode;
         if (event.which) {
           keyCode = event.which;
         } else {
           keyCode = event.keyCode;
         }

         if (keyCode == 13) {
           var input = Tobago.element(event);
           if (input) {
             if (input.value.length > 0) {
               var linkId = input.id.substr(0,
input.id.lastIndexOf(":") + ":searchLink");
               Tobago.submitAction(linkId);
             } else {
               alert("No value in search field!")
             }
           }
         }
       }
       checkAndSubmit = function(event) {
         if (!event) { event = window.event;}
         var link = Tobago.element(event);
         var inputId = link.id.substr(0, link.id.lastIndexOf(":") + ":search");
         var input = Tobago.element(inputId);
         if (input) {
           if (input.value.length > 0) {
             Tobago.submitAction(link.id);
           } else {
             alert("No value in search field!")
           }
         } else {
           alert("input not found");
         }
       }
    </tc:script>
    <tc:in id="search" width="130px"
        value="#{search.searchText}"
        suggestMethod = "#{search.suggestSearch}" />
    <tc:link image="img/search.gif"
             id="searchLink"
             onclick="checkAndSubmit(event)"
             action="#{search.searchItems}" />
</tc:cell>

note: I have not tested nor compiled this so there may be errors in
the javascript, but you should get how to do this.


Regards,
    Volker



2007/7/20, Ramarao Venkata <ra...@gmail.com>:
> Hi,
>
> I has a tc:in and a tc:link.  when we click on the link the form is submited
> even though no value value in tc:in.
> When there is no value in tc:in and pressed on <tc:link i should not submit
> instead i should display an alert message.
>
> With in tc:in when i press enter i need to invoke the action specified in
> tc:link. do i need register for any key listener
>
> My code is written as below
>
> <tc:cell>
>      <tc:in id="search" width="130px"
>          value="#{search.searchText}"
>          suggestMethod = "#{search.suggestSearch}" />
>      <tc:link image="img/search.gif"
>               action="#{search.searchItems}" />
>  </tc:cell>
>
>
> kindly suggest a solution.
>
> regards
> Ramarao
>
>
>
>
>
>
>
>
>
>
>