You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mariano Petrakovsky <mp...@tecnonexo.com> on 2005/07/04 19:55:19 UTC

to continue with my Custom Component

 Ok... my component now is displayed :)... i'm extends of UIPanel..

public class UIShuttleList extends UIPanel implements NamingContainer {

    public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";

    SelectItem[] validList;

    SelectItem[] selectedList;

    HtmlCommandButton addButton, addAllButton, removeButton,
removeAllButton;

 ...
}

Well.. my problem is in the decode method of Renderer...

 public void decode(FacesContext context, UIComponent component) {
        this.assertValidInput(context, component);

When enter in this method, all datas setted by setProperties of Tag, and
datas setted by the Renderer when encode method is calls... all disapear
:o...

How work the JSF?... I need a method to saveState o something?... please :)
need help!...

Thanxs :)

--
Mariano G. Petrakovsky
Programmer · Software Factory
AXG Tecnonexo -  www.tecnonexo.com

Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
Argentina.
Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.

Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
Tel.: (202) 986-7541 - Fax: (202) 787-3891.


· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · ·




RE: Antwort: RE: to continue with my Custom Component

Posted by Mariano Petrakovsky <mp...@tecnonexo.com>.
Hi... thanxs for the comments.
The two list have different values... validList should be "1,2,3,4" and
userList "6,7,8"... and I need the two results.
My trouble is the binding, it's real... when I use the binding before
response is send to client, all work fine... my component lists binding with
my bean lists... but when the restoreState is called, the binding break. All
list work like independient lists.

Is a bad practice store in the state the EL Expresion for redo the binding
when Decode?

--
Mariano G. Petrakovsky
Programmer · Software Factory
AXG Tecnonexo -  www.tecnonexo.com

Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
Argentina.
Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.

Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
Tel.: (202) 986-7541 - Fax: (202) 787-3891.


· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · ·


  -----Mensaje original-----
  De: mathias.werlitz@daimlerchrysler.com
[mailto:mathias.werlitz@daimlerchrysler.com]
  Enviado el: Martes, 05 de Julio de 2005 06:44
  Para: users@myfaces.apache.org
  Asunto: Antwort: RE: to continue with my Custom Component



  Well, you are resolving the valuebinding already in the tag. This should
be done in the component itself. This way your component keeps a reference
to the binding.
  In the Tag you should do something like:

  ValueBinding vb = context.getApplication().createValueBinding(validList);
  component.setValueBinding("validList", vb);

  In the component code you get the value with:

  getValueBinding("validList").getValue(context);


  Hmm, did you provide a second attribute for the tag to specify the output
values? For me it makes no sense to double use the validList binding.
  I saw something like selectedList ...

  In the decode method you should then so something like:

  getValueBinding("selectedList").setValue(context,  ---- the new
SelectItem[]array ----);






  mpetrakovsky@tecnonexo.com schrieb am 04.07.2005 21:02:50:

  >
  >    Yap... thanxs... :) It's work... but in my .jsp I call to my
component like
  > this
  >
  >       <mat:shuttleList validList="#{myBean.list1}" />
  >
  >    myBean.list1 return a SelectItem[].
  >
  >    My component class is like this...
  >
  >
  > public class UIShuttleList extends UIPanel implements NamingContainer {
  >
  >     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
  >
  >     SelectItem[] validList;
  >
  >     SelectItem[] selectedList;
  >
  > ...
  > }
  >
  >    This is my Component... i have two SelectItem[]...
  >
  >    In the setProperties for TAG
  >
  >   protected void setProperties(UIComponent component) {
  >         FacesContext context = FacesContext.getCurrentInstance();
  >         super.setProperties(component);
  >
  >         if (null != size) {
  >             component.getAttributes().put("size", size);
  >         }
  >
  >         if (null != validList) {
  >             if (isValueReference(validList)) {
  >                 ValueBinding vb =
  > context.getApplication().createValueBinding(validList);
  >                 UIShuttleList shuttle = (UIShuttleList) component;
  >                 shuttle.validList = (SelectItem[]) vb.getValue(context);
  >             }
  >         }
  >
  >    ...
  > }
  >
  > It's work fine... but... the restoreState is called... and the next is
  > called to decode Method of Renderer for update the values of
myBean.list1...
  > but never go back to myBean... :(... what is bad?
  >
  >
  > --
  > Mariano G. Petrakovsky
  > Programmer · Software Factory
  > AXG Tecnonexo -  www.tecnonexo.com
  >
  > Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
  > Argentina.
  > Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
  >
  > Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
  > Tel.: (202) 986-7541 - Fax: (202) 787-3891.
  >
  >
  > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
  > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
  > · · · ·
  >
  >
  > -----Mensaje original-----
  > De: Bruno Aranda [mailto:brunoaranda@gmail.com]
  > Enviado el: Lunes, 04 de Julio de 2005 15:29
  > Para: MyFaces Discussion
  > Asunto: Re: to continue with my Custom Component
  >
  >
  > Yes, you have to implement the StateHolder methods saveState and
  > restoreState, with all the attributes that your component have. This
  > methods allow to gets or restores the state of the component instance
  > as a Serializable Object (normally an array[]). You could implement
  > the methods like in the following code ('attrib1' and 'attrib2' are
  > arbitrary attributes, change them with your component ones):
  >
  > [CODE]
  >
  >  public Object saveState(FacesContext context)
  >     {
  >         Object values[] = new Object[3];
  >         values[0] = super.saveState(context);
  >         values[1] = _attrib1;
  >         values[2] = _attrib2;
  >         return ((Object) (values));
  >     }
  >
  >     public void restoreState(FacesContext context, Object state)
  >     {
  >         Object values[] = (Object[])state;
  >         super.restoreState(context, values[0]);
  >         _attrib1 = (String)values[1];
  >         _attrib2 = (Integer)values[2];
  > }
  >
  > [/CODE]
  >
  > Hope this helps,
  >
  > Regards,
  >
  > Bruno
  >
  >
  > 2005/7/4, Mariano Petrakovsky <mp...@tecnonexo.com>:
  > >
  > >  Ok... my component now is displayed :)... i'm extends of UIPanel..
  > >
  > > public class UIShuttleList extends UIPanel implements NamingContainer
{
  > >
  > >     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
  > >
  > >     SelectItem[] validList;
  > >
  > >     SelectItem[] selectedList;
  > >
  > >     HtmlCommandButton addButton, addAllButton, removeButton,
  > > removeAllButton;
  > >
  > >  ...
  > > }
  > >
  > > Well.. my problem is in the decode method of Renderer...
  > >
  > >  public void decode(FacesContext context, UIComponent component) {
  > >         this.assertValidInput(context, component);
  > >
  > > When enter in this method, all datas setted by setProperties of Tag,
and
  > > datas setted by the Renderer when encode method is calls... all
disapear
  > > :o...
  > >
  > > How work the JSF?... I need a method to saveState o something?...
please
  > :)
  > > need help!...
  > >
  > > Thanxs :)
  > >
  > > --
  > > Mariano G. Petrakovsky
  > > Programmer · Software Factory
  > > AXG Tecnonexo -  www.tecnonexo.com
  > >
  > > Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
  > > Argentina.
  > > Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
  > >
  > > Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 ·
USA.
  > > Tel.: (202) 986-7541 - Fax: (202) 787-3891.
  > >
  > > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
  > ·
  > > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
  > ·
  > > · · · ·
  > >
  > >
  >
  >
  >

Antwort: RE: to continue with my Custom Component

Posted by ma...@daimlerchrysler.com.
Well, you are resolving the valuebinding already in the tag. This should 
be done in the component itself. This way your component keeps a reference 
to the binding.
In the Tag you should do something like:

ValueBinding vb = context.getApplication().createValueBinding(validList);
component.setValueBinding("validList", vb);

In the component code you get the value with:

getValueBinding("validList").getValue(context);


Hmm, did you provide a second attribute for the tag to specify the output 
values? For me it makes no sense to double use the validList binding.
I saw something like selectedList ...

In the decode method you should then so something like:

getValueBinding("selectedList").setValue(context,  ---- the new 
SelectItem[]array ----);






mpetrakovsky@tecnonexo.com schrieb am 04.07.2005 21:02:50:

> 
>    Yap... thanxs... :) It's work... but in my .jsp I call to my 
component like
> this
> 
>       <mat:shuttleList validList="#{myBean.list1}" />
> 
>    myBean.list1 return a SelectItem[].
> 
>    My component class is like this...
> 
> 
> public class UIShuttleList extends UIPanel implements NamingContainer {
> 
>     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
> 
>     SelectItem[] validList;
> 
>     SelectItem[] selectedList;
> 
> ...
> }
> 
>    This is my Component... i have two SelectItem[]...
> 
>    In the setProperties for TAG
> 
>   protected void setProperties(UIComponent component) {
>         FacesContext context = FacesContext.getCurrentInstance();
>         super.setProperties(component);
> 
>         if (null != size) {
>             component.getAttributes().put("size", size);
>         }
> 
>         if (null != validList) {
>             if (isValueReference(validList)) {
>                 ValueBinding vb =
> context.getApplication().createValueBinding(validList);
>                 UIShuttleList shuttle = (UIShuttleList) component;
>                 shuttle.validList = (SelectItem[]) vb.getValue(context);
>             }
>         }
> 
>    ...
> }
> 
> It's work fine... but... the restoreState is called... and the next is
> called to decode Method of Renderer for update the values of 
myBean.list1...
> but never go back to myBean... :(... what is bad?
> 
> 
> --
> Mariano G. Petrakovsky
> Programmer · Software Factory
> AXG Tecnonexo -  www.tecnonexo.com
> 
> Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
> Argentina.
> Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
> 
> Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
> Tel.: (202) 986-7541 - Fax: (202) 787-3891.
> 
> 
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 
· ·
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 
· ·
> · · · ·
> 
> 
> -----Mensaje original-----
> De: Bruno Aranda [mailto:brunoaranda@gmail.com]
> Enviado el: Lunes, 04 de Julio de 2005 15:29
> Para: MyFaces Discussion
> Asunto: Re: to continue with my Custom Component
> 
> 
> Yes, you have to implement the StateHolder methods saveState and
> restoreState, with all the attributes that your component have. This
> methods allow to gets or restores the state of the component instance
> as a Serializable Object (normally an array[]). You could implement
> the methods like in the following code ('attrib1' and 'attrib2' are
> arbitrary attributes, change them with your component ones):
> 
> [CODE]
> 
>  public Object saveState(FacesContext context)
>     {
>         Object values[] = new Object[3];
>         values[0] = super.saveState(context);
>         values[1] = _attrib1;
>         values[2] = _attrib2;
>         return ((Object) (values));
>     }
> 
>     public void restoreState(FacesContext context, Object state)
>     {
>         Object values[] = (Object[])state;
>         super.restoreState(context, values[0]);
>         _attrib1 = (String)values[1];
>         _attrib2 = (Integer)values[2];
> }
> 
> [/CODE]
> 
> Hope this helps,
> 
> Regards,
> 
> Bruno
> 
> 
> 2005/7/4, Mariano Petrakovsky <mp...@tecnonexo.com>:
> >
> >  Ok... my component now is displayed :)... i'm extends of UIPanel..
> >
> > public class UIShuttleList extends UIPanel implements NamingContainer 
{
> >
> >     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
> >
> >     SelectItem[] validList;
> >
> >     SelectItem[] selectedList;
> >
> >     HtmlCommandButton addButton, addAllButton, removeButton,
> > removeAllButton;
> >
> >  ...
> > }
> >
> > Well.. my problem is in the decode method of Renderer...
> >
> >  public void decode(FacesContext context, UIComponent component) {
> >         this.assertValidInput(context, component);
> >
> > When enter in this method, all datas setted by setProperties of Tag, 
and
> > datas setted by the Renderer when encode method is calls... all 
disapear
> > :o...
> >
> > How work the JSF?... I need a method to saveState o something?... 
please
> :)
> > need help!...
> >
> > Thanxs :)
> >
> > --
> > Mariano G. Petrakovsky
> > Programmer · Software Factory
> > AXG Tecnonexo -  www.tecnonexo.com
> >
> > Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
> > Argentina.
> > Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
> >
> > Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · 
USA.
> > Tel.: (202) 986-7541 - Fax: (202) 787-3891.
> >
> > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 
· ·
> ·
> > · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · 
· ·
> ·
> > · · · ·
> >
> >
> 
> 
> 

RE: to continue with my Custom Component

Posted by Mariano Petrakovsky <mp...@tecnonexo.com>.
	Yap... thanxs... :) It's work... but in my .jsp I call to my component like
this

		<mat:shuttleList validList="#{myBean.list1}" />

	myBean.list1 return a SelectItem[].

	My component class is like this...


public class UIShuttleList extends UIPanel implements NamingContainer {

    public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";

    SelectItem[] validList;

    SelectItem[] selectedList;

...
}

	This is my Component... i have two SelectItem[]...

	In the setProperties for TAG

  protected void setProperties(UIComponent component) {
        FacesContext context = FacesContext.getCurrentInstance();
        super.setProperties(component);

        if (null != size) {
            component.getAttributes().put("size", size);
        }

        if (null != validList) {
            if (isValueReference(validList)) {
                ValueBinding vb =
context.getApplication().createValueBinding(validList);
                UIShuttleList shuttle = (UIShuttleList) component;
                shuttle.validList = (SelectItem[]) vb.getValue(context);
            }
        }

	...
}

It's work fine... but... the restoreState is called... and the next is
called to decode Method of Renderer for update the values of myBean.list1...
but never go back to myBean... :(... what is bad?


--
Mariano G. Petrakovsky
Programmer · Software Factory
AXG Tecnonexo -  www.tecnonexo.com

Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
Argentina.
Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.

Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
Tel.: (202) 986-7541 - Fax: (202) 787-3891.


· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· · · ·


-----Mensaje original-----
De: Bruno Aranda [mailto:brunoaranda@gmail.com]
Enviado el: Lunes, 04 de Julio de 2005 15:29
Para: MyFaces Discussion
Asunto: Re: to continue with my Custom Component


Yes, you have to implement the StateHolder methods saveState and
restoreState, with all the attributes that your component have. This
methods allow to gets or restores the state of the component instance
as a Serializable Object (normally an array[]). You could implement
the methods like in the following code ('attrib1' and 'attrib2' are
arbitrary attributes, change them with your component ones):

[CODE]

 public Object saveState(FacesContext context)
    {
        Object values[] = new Object[3];
        values[0] = super.saveState(context);
        values[1] = _attrib1;
        values[2] = _attrib2;
        return ((Object) (values));
    }

    public void restoreState(FacesContext context, Object state)
    {
        Object values[] = (Object[])state;
        super.restoreState(context, values[0]);
        _attrib1 = (String)values[1];
        _attrib2 = (Integer)values[2];
}

[/CODE]

Hope this helps,

Regards,

Bruno


2005/7/4, Mariano Petrakovsky <mp...@tecnonexo.com>:
>
>  Ok... my component now is displayed :)... i'm extends of UIPanel..
>
> public class UIShuttleList extends UIPanel implements NamingContainer {
>
>     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
>
>     SelectItem[] validList;
>
>     SelectItem[] selectedList;
>
>     HtmlCommandButton addButton, addAllButton, removeButton,
> removeAllButton;
>
>  ...
> }
>
> Well.. my problem is in the decode method of Renderer...
>
>  public void decode(FacesContext context, UIComponent component) {
>         this.assertValidInput(context, component);
>
> When enter in this method, all datas setted by setProperties of Tag, and
> datas setted by the Renderer when encode method is calls... all disapear
> :o...
>
> How work the JSF?... I need a method to saveState o something?... please
:)
> need help!...
>
> Thanxs :)
>
> --
> Mariano G. Petrakovsky
> Programmer · Software Factory
> AXG Tecnonexo -  www.tecnonexo.com
>
> Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
> Argentina.
> Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
>
> Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
> Tel.: (202) 986-7541 - Fax: (202) 787-3891.
>
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
·
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
·
> · · · ·
>
>




Re: to continue with my Custom Component

Posted by Bruno Aranda <br...@gmail.com>.
Yes, you have to implement the StateHolder methods saveState and
restoreState, with all the attributes that your component have. This
methods allow to gets or restores the state of the component instance
as a Serializable Object (normally an array[]). You could implement
the methods like in the following code ('attrib1' and 'attrib2' are
arbitrary attributes, change them with your component ones):

[CODE]

 public Object saveState(FacesContext context)
    {
        Object values[] = new Object[3];
        values[0] = super.saveState(context);
        values[1] = _attrib1;
        values[2] = _attrib2;
        return ((Object) (values));
    }

    public void restoreState(FacesContext context, Object state)
    {
        Object values[] = (Object[])state;
        super.restoreState(context, values[0]);
        _attrib1 = (String)values[1];
        _attrib2 = (Integer)values[2];
}

[/CODE]

Hope this helps,

Regards,

Bruno    


2005/7/4, Mariano Petrakovsky <mp...@tecnonexo.com>:
> 
>  Ok... my component now is displayed :)... i'm extends of UIPanel..
> 
> public class UIShuttleList extends UIPanel implements NamingContainer {
> 
>     public static final String SHUTTLE_LIST_FAMILY = "SLFAMILY";
> 
>     SelectItem[] validList;
> 
>     SelectItem[] selectedList;
> 
>     HtmlCommandButton addButton, addAllButton, removeButton,
> removeAllButton;
> 
>  ...
> }
> 
> Well.. my problem is in the decode method of Renderer...
> 
>  public void decode(FacesContext context, UIComponent component) {
>         this.assertValidInput(context, component);
> 
> When enter in this method, all datas setted by setProperties of Tag, and
> datas setted by the Renderer when encode method is calls... all disapear
> :o...
> 
> How work the JSF?... I need a method to saveState o something?... please :)
> need help!...
> 
> Thanxs :)
> 
> --
> Mariano G. Petrakovsky
> Programmer · Software Factory
> AXG Tecnonexo -  www.tecnonexo.com
> 
> Development facilities:Av. Maipú 1252 8º (C1006ACT) · Buenos Aires ·
> Argentina.
> Tel.: (54-11) 4878-0005 - Fax: (54-11) 4878-0065.
> 
> Headquarters: 1604 Spring Hill Road, Suite 160 Vienna · VA 22182 · USA.
> Tel.: (202) 986-7541 - Fax: (202) 787-3891.
> 
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
> · · · ·
> 
>