You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by wasim bhatti <mw...@yahoo.com> on 2005/12/05 11:22:03 UTC

Custom Component Binding problem

Greetings,
   
  I have made a custom component using myfaces 1.0.9. Everything worked fine to start with, and i was able to bind values of the component to the back end managed bean. At least there was no problem in retrieving values from the bean. The trouble occurs when the vlaue changes from the front. According to the binding principles the value should be set at the back end bean. but the setter is never called.
   
  Should the value setting take place in the decode method ?
  My decode method is as follows :
   
  public void decode( FacesContext context )
    {
        Map requestMap = context.getExternalContext().getRequestParameterMap();
        String clientId = getClientId( context );          try
        {
            String dateFrom = requestMap.get( clientId + DATE_FROM ).toString() ;     
            setSubmittedValue( dateFrom );
              setValid( true );
        }
        catch( NumberFormatException ex )
        {
            ex.printStackTrace();
            setSubmittedValue( (String)requestMap.get(clientId + DATE_FROM) );
        }
      }
   
  What is the specific function of the setSubmittedValue ? as in if i have more than 1 inputs in my encode method which ones value would be set when decode is called ?
  I can get the new values from the front using getSubmittedValue but the value is never propagated to the bean.
   
  Any help would be much appreciated.
   
  regards,
  a newbie to jsf
   

   

		
---------------------------------
 Yahoo! DSL Something to write home about. Just $16.99/mo. or less

Re: Custom Component Binding problem

Posted by wasim bhatti <mw...@yahoo.com>.
Sir
  My class is inherited from UIInput, but the problem is that, when i call setSubmittedValue in decode method, it does not work( in the sense that the bean value is not updated ).
  Waiting for ur reply.
  Regards
   
  

Martin Marinschek <ma...@gmail.com> wrote:
  If you subclass from UIInput, the rest is done implicitly in the
processValidators and the processUpdates Method.

regards,

Martin

On 12/5/05, wasim bhatti wrote:
> Hey martin,
>
> Of the three states that you have mentioned ... which one do i have to do
> explicity ?
> because i am calling the
>
> set as a submitted value (done in decoding phase)
>
> explicitly but i think the value is not being set. i have no validators for
> my component. should that cause some problem ? the rest of the 2 phases are
> invoked implicitly ?
>
> what do u mean when u say local values ?
>
> how do i check whether the value is being set when i call setSubmittedvalue.
> all i know is that i place a call to setSubmittedvalue but the setter in
> the bean is never callled.
>
> Thanx a lot.
>
> Martin Marinschek wrote:
> that needs quite a long explanation, I'll try to give you a short one ;)
>
> there are three states your component values can be in:
>
> - set as a submitted value (done in decoding phase)
> - set as a local value (done after conversion and validation has been
> processed, this is when setValid() is called, you don't have to do it
> yourself)
> - set in the backing bean (done in the update model phase)
>
> so in decode, you need to set the submitted value.
>
> for conversion and validation, you have to make sure that the value is
> convertable and valid, else the local value will never be set.
>
> if the local value is set - and all other components on the page have
> valid values, the value is written through to the backing bean in the
> update model phase.
>
> somewhat clearer?
>
> regards,
>
> Martin
>
>
>
> On 12/5/05, wasim bhatti wrote:
> > Greetings,
> >
> > I have made a custom component using myfaces 1.0.9. Everythi ng worked
> fine
>
> > to start with, and i was able to bind values of the component to the back
> > end managed bean. At least there was no problem in retrieving values from
> > the bean. The trouble occurs when the vlaue changes from the front.
> > According to the binding principles the value should be set at the back
> end
> > bean. but the setter is never called.
> >
> > Should the value setting take place in the decode method ?
> > My decode method is as follows :
>
>
> >
> > public void decode( FacesContext context )
> > {
> > Map requestMap =
> > context.getExternalContext().getRequestParameterMap();
> > String clientId = getClientId( context );
> > try
> > {
> > String dateFrom = requestMap.get( clientId + DATE_FROM
> > ).toString() ;
> > setSubmittedValue( dateFrom );
> > setValid( true );
> > }
> > catch( NumberFormatException ex )
> > {
> > ex.printStackTrace();
> > setSubmittedValue( (String)requestMap.get(clientId + DATE_FROM)
> > );
> > }
> > }
> >
> > What is the specific function of the setSubmittedVal ue ? as in if i have
> > more than 1 inputs in my encode method which ones value would be set when
> > decode is called ?
> > I can get the new values from the front using getSubmittedValue but the
> > value is never propagated to the bean.
> >
> > Any help would be much appreciated.
> >
> > regards,
> > a newbie to jsf
> >
> >
> >
> > ________________________________
> > Yahoo! DSL Something to write home about. Just $16.99/mo. or less
> >
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
>
> ________________________________
> Yahoo! Shopping
> Find Great Deals on Gifts at Yahoo! Shopping
>
>


--

http://www.irian.at

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

Professional Support for Apache MyFaces
  


			
---------------------------------
Yahoo! Shopping
 Find Great Deals on Gifts at Yahoo! Shopping 

Re: Custom Component Binding problem

Posted by Martin Marinschek <ma...@gmail.com>.
If you subclass from UIInput, the rest is done implicitly in the
processValidators and the processUpdates Method.

regards,

Martin

On 12/5/05, wasim bhatti <mw...@yahoo.com> wrote:
> Hey martin,
>
> Of the three states that you have mentioned ... which one do i have to do
> explicity ?
> because i am calling the
>
> set as a submitted value (done in decoding phase)
>
> explicitly but i think the value is not being set. i have no validators for
> my component. should that cause some problem ?  the rest of the 2 phases are
> invoked implicitly ?
>
> what do u mean when u say local values ?
>
> how do i check whether the value is being set when i call setSubmittedvalue.
> all i know is that i place a call to  setSubmittedvalue but the setter in
> the bean is never callled.
>
> Thanx a lot.
>
> Martin Marinschek <ma...@gmail.com> wrote:
> that needs quite a long explanation, I'll try to give you a short one ;)
>
> there are three states your component values can be in:
>
> - set as a submitted value (done in decoding phase)
> - set as a local value (done after conversion and validation has been
> processed, this is when setValid() is called, you don't have to do it
> yourself)
> - set in the backing bean (done in the update model phase)
>
> so in decode, you need to set the submitted value.
>
> for conversion and validation, you have to make sure that the value is
> convertable and valid, else the local value will never be set.
>
> if the local value is set - and all other components on the page have
> valid values, the value is written through to the backing bean in the
> update model phase.
>
> somewhat clearer?
>
> regards,
>
> Martin
>
>
>
> On 12/5/05, wasim bhatti wrote:
> > Greetings,
> >
> > I have made a custom component using myfaces 1.0.9. Everythi ng worked
> fine
>
> > to start with, and i was able to bind values of the component to the back
> > end managed bean. At least there was no problem in retrieving values from
> > the bean. The trouble occurs when the vlaue changes from the front.
> > According to the binding principles the value should be set at the back
> end
> > bean. but the setter is never called.
> >
> > Should the value setting take place in the decode method ?
> > My decode method is as follows :
>
>
> >
> > public void decode( FacesContext context )
> > {
> > Map requestMap =
> > context.getExternalContext().getRequestParameterMap();
> > String clientId = getClientId( context );
> > try
> > {
> > String dateFrom = requestMap.get( clientId + DATE_FROM
> > ).toString() ;
> > setSubmittedValue( dateFrom );
> > setValid( true );
> > }
> > catch( NumberFormatException ex )
> > {
> > ex.printStackTrace();
> > setSubmittedValue( (String)requestMap.get(clientId + DATE_FROM)
> > );
> > }
> > }
> >
> > What is the specific function of the setSubmittedVal ue ? as in if i have
> > more than 1 inputs in my encode method which ones value would be set when
> > decode is called ?
> > I can get the new values from the front using getSubmittedValue but the
> > value is never propagated to the bean.
> >
> > Any help would be much appreciated.
> >
> > regards,
> > a newbie to jsf
> >
> >
> >
> > ________________________________
> > Yahoo! DSL Something to write home about. Just $16.99/mo. or less
> >
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
>
>  ________________________________
> Yahoo! Shopping
>  Find Great Deals on Gifts at Yahoo! Shopping
>
>


--

http://www.irian.at

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

Professional Support for Apache MyFaces

Re: Custom Component Binding problem

Posted by wasim bhatti <mw...@yahoo.com>.
Hey martin,
   
  Of the three states that you have mentioned ... which one do i have to do explicity ?
  because i am calling the 
   
  set as a submitted value (done in decoding phase)

  explicitly but i think the value is not being set. i have no validators for my component. should that cause some problem ?  the rest of the 2 phases are invoked implicitly ?
   
  what do u mean when u say local values ?
   
  how do i check whether the value is being set when i call setSubmittedvalue. all i know is that i place a call to  setSubmittedvalue but the setter in the bean is never callled.
   
  Thanx a lot.

Martin Marinschek <ma...@gmail.com> wrote:
  that needs quite a long explanation, I'll try to give you a short one ;)

there are three states your component values can be in:

- set as a submitted value (done in decoding phase)
- set as a local value (done after conversion and validation has been
processed, this is when setValid() is called, you don't have to do it
yourself)
- set in the backing bean (done in the update model phase)

so in decode, you need to set the submitted value.

for conversion and validation, you have to make sure that the value is
convertable and valid, else the local value will never be set.

if the local value is set - and all other components on the page have
valid values, the value is written through to the backing bean in the
update model phase.

somewhat clearer?

regards,

Martin



On 12/5/05, wasim bhatti wrote:
> Greetings,
>
> I have made a custom component using myfaces 1.0.9. Everything worked fine
> to start with, and i was able to bind values of the component to the back
> end managed bean. At least there was no problem in retrieving values from
> the bean. The trouble occurs when the vlaue changes from the front.
> According to the binding principles the value should be set at the back end
> bean. but the setter is never called.
>
> Should the value setting take place in the decode method ?
> My decode method is as follows :


>
> public void decode( FacesContext context )
> {
> Map requestMap =
> context.getExternalContext().getRequestParameterMap();
> String clientId = getClientId( context );
> try
> {
> String dateFrom = requestMap.get( clientId + DATE_FROM
> ).toString() ;
> setSubmittedValue( dateFrom );
> setValid( true );
> }
> catch( NumberFormatException ex )
> {
> ex.printStackTrace();
> setSubmittedValue( (String)requestMap.get(clientId + DATE_FROM)
> );
> }
> }
>
> What is the specific function of the setSubmittedVal ue ? as in if i have
> more than 1 inputs in my encode method which ones value would be set when
> decode is called ?
> I can get the new values from the front using getSubmittedValue but the
> value is never propagated to the bean.
>
> Any help would be much appreciated.
>
> regards,
> a newbie to jsf
>
>
>
> ________________________________
> Yahoo! DSL Something to write home about. Just $16.99/mo. or less
>
>


--

http://www.irian.at

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

Professional Support for Apache MyFaces
  


			
---------------------------------
Yahoo! Shopping
 Find Great Deals on Gifts at Yahoo! Shopping 

Re: Custom Component Binding problem

Posted by Martin Marinschek <ma...@gmail.com>.
that needs quite a long explanation, I'll try to give you a short one ;)

there are three states your component values can be in:

- set as a submitted value (done in decoding phase)
- set as a local value (done after conversion and validation has been
processed, this is when setValid() is called, you don't have to do it
yourself)
- set in the backing bean (done in the update model phase)

so in decode, you need to set the submitted value.

for conversion and validation, you have to make sure that the value is
convertable and valid, else the local value will never be set.

if the local value is set - and all other components on the page have
valid values, the value is written through to the backing bean in the
update model phase.

somewhat clearer?

regards,

Martin



On 12/5/05, wasim bhatti <mw...@yahoo.com> wrote:
> Greetings,
>
> I have made a custom component using myfaces 1.0.9. Everything worked fine
> to start with, and i was able to bind values of the component to the back
> end managed bean. At least there was no problem in retrieving values from
> the bean. The trouble occurs when the vlaue changes from the front.
> According to the binding principles the value should be set at the back end
> bean. but the setter is never called.
>
> Should the value setting take place in the decode method ?
> My decode method is as follows :


>
> public void decode( FacesContext context )
>     {
>         Map requestMap =
> context.getExternalContext().getRequestParameterMap();
>         String clientId = getClientId( context );
>         try
>         {
>             String dateFrom = requestMap.get( clientId + DATE_FROM
> ).toString() ;
>             setSubmittedValue( dateFrom );
>             setValid( true );
>         }
>         catch( NumberFormatException ex )
>         {
>             ex.printStackTrace();
>             setSubmittedValue( (String)requestMap.get(clientId + DATE_FROM)
> );
>         }
>     }
>
> What is the specific function of the setSubmittedVal ue ? as in if i have
> more than 1 inputs in my encode method which ones value would be set when
> decode is called ?
> I can get the new values from the front using getSubmittedValue but the
> value is never propagated to the bean.
>
> Any help would be much appreciated.
>
> regards,
> a newbie to jsf
>
>
>
>  ________________________________
>  Yahoo! DSL Something to write home about. Just $16.99/mo. or less
>
>


--

http://www.irian.at

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

Professional Support for Apache MyFaces