You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Martin Grotzke <ma...@javakaffee.de> on 2006/10/30 11:13:42 UTC

InputSuggestAjax and binding

Hey all,

the documentation for inputSuggestAjax
(http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
the binding attribute "is needed because the control object does all the
needed data transformation between the Ajax control and the
backend/frontend"...

Has someone an example how to implement the binding on the server side?

Thanx a lot,
cheers,
Martin

--

Re: InputSuggestAjax and binding

Posted by Matthias Wessendorf <ma...@apache.org>.
suggestedItems != getSuggestedItems

perhaps that is the deal.

it is method binding

so when using "suggestedItems" in the EL

name the method suggestedItems


when using getSuggestedItems in EL
name is getSuggestedItems

-M

On 10/30/06, Gerald Müllan <bi...@gmail.com> wrote:
> You have to provide exactly the same method name, so in your case it
> is getSuggestedItems. If you use the maxSuggestedItems approach, you
> also have to give the method an Integer on the way home.
>
> So:
>
> public List getSuggestedItems(String prefix, Integer maxSize)
> {
>    ..
> }
>
> If it still doesn`t work, please post the stack trace here. You can
> also have a look at the sandbox examples, where invoking the method
> works without any problems.
>
> regards,
>
> Gerald
>
> On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > On Mon, 2006-10-30 at 16:07 +0100, Gerald Müllan wrote:
> > > Well, the component doesn`t work like this.
> > >
> > > The suggestedItemsMethod takes a String which was the input of the
> > > user before the ajax-request. With the help of this string the lookup
> > > in the db is performed and the result as
> > > a list of strings is returned. Which exactly matches the pop-up.
> > Okay. I changed the backing bean so that it provides a method that
> > takes a string and returns a list of strings.
> >
> > Unfortunately, no method is invoked.
> >
> > The tag looks like the following:
> >
> > <s:inputSuggestAjax id="departures"
> >         suggestedItemsMethod="#{createReservationController.departure.suggest2.suggestedItems}"
> >         value="#{createReservationController.departure.suggest2.selectedItem}"
> >         maxSuggestedItems="10" />
> >
> > But on the createReservationController backing bean the getDeparture
> > method is never called.
> >
> > Do you have any tips what's causing this?
> > The same value expression (ok, nearly the same) works for anther field,
> > so the expression itself is correct.
> >
> > Thanx && cheers,
> > Martin
> >
> >
> > >
> > > If you want to get a behaviour like it can be found in menues with the
> > > value/label approach,
> > > you have to define a "itemLabelMethod". The suggestedItemsMethod
> > > should then return a list of objects. The label is extracted through
> > > the itemLabelMethod (which gets an object from the list) and the value
> > > through a given converter.
> > >
> > > Hope this helps,
> > >
> > > cheers,
> > >
> > > Gerald
> > >
> > > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > > On Mon, 2006-10-30 at 13:50 +0100, Gerald Müllan wrote:
> > > > > Hi,
> > > > >
> > > > > forget the binding stuff. It is not needed. The docu on this component
> > > > > is outdated.
> > > > Thanx for this hint :)
> > > >
> > > > >
> > > > > All you need to do to get it work in the simplest mode is just
> > > > > implement the suggestedItemsMethod.
> > > > But probably i can use the valueChangeListener to fetch the items
> > > > that are returned by suggestedItemsMethod?
> > > >
> > > > I just tried the component with the following sniplet:
> > > >
> > > > <s:inputSuggestAjax id="departures"
> > > >     suggestedItemsMethod="#{createReservationController.departure.suggest.items}"
> > > >     value="#{createReservationController.departure.suggest.userInput}"
> > > >     valueChangeListener="#{createReservationController.departure.suggest.userInputChanged}"
> > > >     maxSuggestedItems="10" size="10"
> > > >     tabindex="2" />
> > > >
> > > > and the following on the server side:
> > > >
> > > >     public void userInputChanged( ValueChangeEvent event ) {
> > > >         LOG.debug( "Invoked" );
> > > >         // performs a lookup in the backend
> > > >         // and updates the suggested items:
> > > >         suggestItems( true );
> > > >     }
> > > >
> > > >     public Collection<SelectItem> getItems() {
> > > >         return _items;
> > > >     }
> > > >
> > > >     public String getUserInput() {
> > > >         return _userInput;
> > > >     }
> > > >
> > > >     public void setUserInput( String input ) {
> > > >         _userInput = input;
> > > >     }
> > > >
> > > >
> > > > Unfortunately, the java code is never called, even the
> > > > createReservationController.getDeparture is not called....
> > > >
> > > > Can you tell me what is wrong with this?
> > > > We are using the nightly snapshot (today) of myfaces-api/impl, tomahawk
> > > > and the sandbox.
> > > >
> > > > Thanx && cheers,
> > > > Martin
> > > >
> > > >
> > > > >
> > > > > Sorry for the confusion on this.
> > > > >
> > > > > cheers,
> > > > >
> > > > > Gerald
> > > > >
> > > > > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > > > > Hey all,
> > > > > >
> > > > > > the documentation for inputSuggestAjax
> > > > > > (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> > > > > > the binding attribute "is needed because the control object does all the
> > > > > > needed data transformation between the Ajax control and the
> > > > > > backend/frontend"...
> > > > > >
> > > > > > Has someone an example how to implement the binding on the server side?
> > > > > >
> > > > > > Thanx a lot,
> > > > > > cheers,
> > > > > > Martin
> > > > > >
> > > > > > --
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > --
> > > > Martin Grotzke
> > > > http://www.javakaffee.de/blog/
> > > >
> > > >
> > > >
> > >
> > >
> > --
> > Martin Grotzke
> > http://www.javakaffee.de/blog/
> >
> >
> >
>
>
> --
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>


-- 
Matthias Wessendorf
http://tinyurl.com/fmywh

further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: InputSuggestAjax and binding

Posted by Gerald Müllan <bi...@gmail.com>.
You have to provide exactly the same method name, so in your case it
is getSuggestedItems. If you use the maxSuggestedItems approach, you
also have to give the method an Integer on the way home.

So:

public List getSuggestedItems(String prefix, Integer maxSize)
{
   ..
}

If it still doesn`t work, please post the stack trace here. You can
also have a look at the sandbox examples, where invoking the method
works without any problems.

regards,

Gerald

On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> On Mon, 2006-10-30 at 16:07 +0100, Gerald Müllan wrote:
> > Well, the component doesn`t work like this.
> >
> > The suggestedItemsMethod takes a String which was the input of the
> > user before the ajax-request. With the help of this string the lookup
> > in the db is performed and the result as
> > a list of strings is returned. Which exactly matches the pop-up.
> Okay. I changed the backing bean so that it provides a method that
> takes a string and returns a list of strings.
>
> Unfortunately, no method is invoked.
>
> The tag looks like the following:
>
> <s:inputSuggestAjax id="departures"
>         suggestedItemsMethod="#{createReservationController.departure.suggest2.suggestedItems}"
>         value="#{createReservationController.departure.suggest2.selectedItem}"
>         maxSuggestedItems="10" />
>
> But on the createReservationController backing bean the getDeparture
> method is never called.
>
> Do you have any tips what's causing this?
> The same value expression (ok, nearly the same) works for anther field,
> so the expression itself is correct.
>
> Thanx && cheers,
> Martin
>
>
> >
> > If you want to get a behaviour like it can be found in menues with the
> > value/label approach,
> > you have to define a "itemLabelMethod". The suggestedItemsMethod
> > should then return a list of objects. The label is extracted through
> > the itemLabelMethod (which gets an object from the list) and the value
> > through a given converter.
> >
> > Hope this helps,
> >
> > cheers,
> >
> > Gerald
> >
> > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > On Mon, 2006-10-30 at 13:50 +0100, Gerald Müllan wrote:
> > > > Hi,
> > > >
> > > > forget the binding stuff. It is not needed. The docu on this component
> > > > is outdated.
> > > Thanx for this hint :)
> > >
> > > >
> > > > All you need to do to get it work in the simplest mode is just
> > > > implement the suggestedItemsMethod.
> > > But probably i can use the valueChangeListener to fetch the items
> > > that are returned by suggestedItemsMethod?
> > >
> > > I just tried the component with the following sniplet:
> > >
> > > <s:inputSuggestAjax id="departures"
> > >     suggestedItemsMethod="#{createReservationController.departure.suggest.items}"
> > >     value="#{createReservationController.departure.suggest.userInput}"
> > >     valueChangeListener="#{createReservationController.departure.suggest.userInputChanged}"
> > >     maxSuggestedItems="10" size="10"
> > >     tabindex="2" />
> > >
> > > and the following on the server side:
> > >
> > >     public void userInputChanged( ValueChangeEvent event ) {
> > >         LOG.debug( "Invoked" );
> > >         // performs a lookup in the backend
> > >         // and updates the suggested items:
> > >         suggestItems( true );
> > >     }
> > >
> > >     public Collection<SelectItem> getItems() {
> > >         return _items;
> > >     }
> > >
> > >     public String getUserInput() {
> > >         return _userInput;
> > >     }
> > >
> > >     public void setUserInput( String input ) {
> > >         _userInput = input;
> > >     }
> > >
> > >
> > > Unfortunately, the java code is never called, even the
> > > createReservationController.getDeparture is not called....
> > >
> > > Can you tell me what is wrong with this?
> > > We are using the nightly snapshot (today) of myfaces-api/impl, tomahawk
> > > and the sandbox.
> > >
> > > Thanx && cheers,
> > > Martin
> > >
> > >
> > > >
> > > > Sorry for the confusion on this.
> > > >
> > > > cheers,
> > > >
> > > > Gerald
> > > >
> > > > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > > > Hey all,
> > > > >
> > > > > the documentation for inputSuggestAjax
> > > > > (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> > > > > the binding attribute "is needed because the control object does all the
> > > > > needed data transformation between the Ajax control and the
> > > > > backend/frontend"...
> > > > >
> > > > > Has someone an example how to implement the binding on the server side?
> > > > >
> > > > > Thanx a lot,
> > > > > cheers,
> > > > > Martin
> > > > >
> > > > > --
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > --
> > > Martin Grotzke
> > > http://www.javakaffee.de/blog/
> > >
> > >
> > >
> >
> >
> --
> Martin Grotzke
> http://www.javakaffee.de/blog/
>
>
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: InputSuggestAjax and binding

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Mon, 2006-10-30 at 16:07 +0100, Gerald Müllan wrote:
> Well, the component doesn`t work like this.
> 
> The suggestedItemsMethod takes a String which was the input of the
> user before the ajax-request. With the help of this string the lookup
> in the db is performed and the result as
> a list of strings is returned. Which exactly matches the pop-up.
Okay. I changed the backing bean so that it provides a method that
takes a string and returns a list of strings.

Unfortunately, no method is invoked.

The tag looks like the following:

<s:inputSuggestAjax id="departures"
	suggestedItemsMethod="#{createReservationController.departure.suggest2.suggestedItems}"
	value="#{createReservationController.departure.suggest2.selectedItem}"
	maxSuggestedItems="10" />

But on the createReservationController backing bean the getDeparture
method is never called.

Do you have any tips what's causing this?
The same value expression (ok, nearly the same) works for anther field,
so the expression itself is correct.

Thanx && cheers,
Martin


> 
> If you want to get a behaviour like it can be found in menues with the
> value/label approach,
> you have to define a "itemLabelMethod". The suggestedItemsMethod
> should then return a list of objects. The label is extracted through
> the itemLabelMethod (which gets an object from the list) and the value
> through a given converter.
> 
> Hope this helps,
> 
> cheers,
> 
> Gerald
> 
> On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > On Mon, 2006-10-30 at 13:50 +0100, Gerald Müllan wrote:
> > > Hi,
> > >
> > > forget the binding stuff. It is not needed. The docu on this component
> > > is outdated.
> > Thanx for this hint :)
> >
> > >
> > > All you need to do to get it work in the simplest mode is just
> > > implement the suggestedItemsMethod.
> > But probably i can use the valueChangeListener to fetch the items
> > that are returned by suggestedItemsMethod?
> >
> > I just tried the component with the following sniplet:
> >
> > <s:inputSuggestAjax id="departures"
> >     suggestedItemsMethod="#{createReservationController.departure.suggest.items}"
> >     value="#{createReservationController.departure.suggest.userInput}"
> >     valueChangeListener="#{createReservationController.departure.suggest.userInputChanged}"
> >     maxSuggestedItems="10" size="10"
> >     tabindex="2" />
> >
> > and the following on the server side:
> >
> >     public void userInputChanged( ValueChangeEvent event ) {
> >         LOG.debug( "Invoked" );
> >         // performs a lookup in the backend
> >         // and updates the suggested items:
> >         suggestItems( true );
> >     }
> >
> >     public Collection<SelectItem> getItems() {
> >         return _items;
> >     }
> >
> >     public String getUserInput() {
> >         return _userInput;
> >     }
> >
> >     public void setUserInput( String input ) {
> >         _userInput = input;
> >     }
> >
> >
> > Unfortunately, the java code is never called, even the
> > createReservationController.getDeparture is not called....
> >
> > Can you tell me what is wrong with this?
> > We are using the nightly snapshot (today) of myfaces-api/impl, tomahawk
> > and the sandbox.
> >
> > Thanx && cheers,
> > Martin
> >
> >
> > >
> > > Sorry for the confusion on this.
> > >
> > > cheers,
> > >
> > > Gerald
> > >
> > > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > > Hey all,
> > > >
> > > > the documentation for inputSuggestAjax
> > > > (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> > > > the binding attribute "is needed because the control object does all the
> > > > needed data transformation between the Ajax control and the
> > > > backend/frontend"...
> > > >
> > > > Has someone an example how to implement the binding on the server side?
> > > >
> > > > Thanx a lot,
> > > > cheers,
> > > > Martin
> > > >
> > > > --
> > > >
> > > >
> > > >
> > >
> > >
> > --
> > Martin Grotzke
> > http://www.javakaffee.de/blog/
> >
> >
> >
> 
> 
-- 
Martin Grotzke
http://www.javakaffee.de/blog/

Re: InputSuggestAjax and binding

Posted by Gerald Müllan <bi...@gmail.com>.
Well, the component doesn`t work like this.

The suggestedItemsMethod takes a String which was the input of the
user before the ajax-request. With the help of this string the lookup
in the db is performed and the result as
a list of strings is returned. Which exactly matches the pop-up.

If you want to get a behaviour like it can be found in menues with the
value/label approach,
you have to define a "itemLabelMethod". The suggestedItemsMethod
should then return a list of objects. The label is extracted through
the itemLabelMethod (which gets an object from the list) and the value
through a given converter.

Hope this helps,

cheers,

Gerald

On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> On Mon, 2006-10-30 at 13:50 +0100, Gerald Müllan wrote:
> > Hi,
> >
> > forget the binding stuff. It is not needed. The docu on this component
> > is outdated.
> Thanx for this hint :)
>
> >
> > All you need to do to get it work in the simplest mode is just
> > implement the suggestedItemsMethod.
> But probably i can use the valueChangeListener to fetch the items
> that are returned by suggestedItemsMethod?
>
> I just tried the component with the following sniplet:
>
> <s:inputSuggestAjax id="departures"
>     suggestedItemsMethod="#{createReservationController.departure.suggest.items}"
>     value="#{createReservationController.departure.suggest.userInput}"
>     valueChangeListener="#{createReservationController.departure.suggest.userInputChanged}"
>     maxSuggestedItems="10" size="10"
>     tabindex="2" />
>
> and the following on the server side:
>
>     public void userInputChanged( ValueChangeEvent event ) {
>         LOG.debug( "Invoked" );
>         // performs a lookup in the backend
>         // and updates the suggested items:
>         suggestItems( true );
>     }
>
>     public Collection<SelectItem> getItems() {
>         return _items;
>     }
>
>     public String getUserInput() {
>         return _userInput;
>     }
>
>     public void setUserInput( String input ) {
>         _userInput = input;
>     }
>
>
> Unfortunately, the java code is never called, even the
> createReservationController.getDeparture is not called....
>
> Can you tell me what is wrong with this?
> We are using the nightly snapshot (today) of myfaces-api/impl, tomahawk
> and the sandbox.
>
> Thanx && cheers,
> Martin
>
>
> >
> > Sorry for the confusion on this.
> >
> > cheers,
> >
> > Gerald
> >
> > On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > > Hey all,
> > >
> > > the documentation for inputSuggestAjax
> > > (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> > > the binding attribute "is needed because the control object does all the
> > > needed data transformation between the Ajax control and the
> > > backend/frontend"...
> > >
> > > Has someone an example how to implement the binding on the server side?
> > >
> > > Thanx a lot,
> > > cheers,
> > > Martin
> > >
> > > --
> > >
> > >
> > >
> >
> >
> --
> Martin Grotzke
> http://www.javakaffee.de/blog/
>
>
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: InputSuggestAjax and binding

Posted by Martin Grotzke <ma...@javakaffee.de>.
On Mon, 2006-10-30 at 13:50 +0100, Gerald Müllan wrote:
> Hi,
> 
> forget the binding stuff. It is not needed. The docu on this component
> is outdated.
Thanx for this hint :)

> 
> All you need to do to get it work in the simplest mode is just
> implement the suggestedItemsMethod.
But probably i can use the valueChangeListener to fetch the items
that are returned by suggestedItemsMethod?

I just tried the component with the following sniplet:

<s:inputSuggestAjax id="departures"
    suggestedItemsMethod="#{createReservationController.departure.suggest.items}"
    value="#{createReservationController.departure.suggest.userInput}"	
    valueChangeListener="#{createReservationController.departure.suggest.userInputChanged}"
    maxSuggestedItems="10" size="10"					
    tabindex="2" />

and the following on the server side:

    public void userInputChanged( ValueChangeEvent event ) {
        LOG.debug( "Invoked" );
	// performs a lookup in the backend
	// and updates the suggested items:
        suggestItems( true );
    }

    public Collection<SelectItem> getItems() {
        return _items;
    }

    public String getUserInput() {
        return _userInput;
    }

    public void setUserInput( String input ) {
        _userInput = input;
    }


Unfortunately, the java code is never called, even the
createReservationController.getDeparture is not called....

Can you tell me what is wrong with this?
We are using the nightly snapshot (today) of myfaces-api/impl, tomahawk
and the sandbox.

Thanx && cheers,
Martin


> 
> Sorry for the confusion on this.
> 
> cheers,
> 
> Gerald
> 
> On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> > Hey all,
> >
> > the documentation for inputSuggestAjax
> > (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> > the binding attribute "is needed because the control object does all the
> > needed data transformation between the Ajax control and the
> > backend/frontend"...
> >
> > Has someone an example how to implement the binding on the server side?
> >
> > Thanx a lot,
> > cheers,
> > Martin
> >
> > --
> >
> >
> >
> 
> 
-- 
Martin Grotzke
http://www.javakaffee.de/blog/

Re: InputSuggestAjax and binding

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

forget the binding stuff. It is not needed. The docu on this component
is outdated.

All you need to do to get it work in the simplest mode is just
implement the suggestedItemsMethod.

Sorry for the confusion on this.

cheers,

Gerald

On 10/30/06, Martin Grotzke <ma...@javakaffee.de> wrote:
> Hey all,
>
> the documentation for inputSuggestAjax
> (http://myfaces.apache.org/sandbox/inputSuggestAjax.html) says that
> the binding attribute "is needed because the control object does all the
> needed data transformation between the Ajax control and the
> backend/frontend"...
>
> Has someone an example how to implement the binding on the server side?
>
> Thanx a lot,
> cheers,
> Martin
>
> --
>
>
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces