Re: SaveState Issues

2006-10-16 Thread Martin Marinschek

Sounds good!

regards,

Martin

On 10/15/06, Cagatay Civici [EMAIL PROTECTED] wrote:

Yes Marting that's exactly the problem. After digging more, I've realized
that we dont need to change anything in restoreState of the component
because calling restoreAttachedState will simply return the value if it's
not a special wrapped type.

public Object saveState(FacesContext context)
{
Object values[] = new Object[2];
values[0] = super.saveState(context);
values[1] = getValue() instanceof StateHolder ?
saveAttachedState(context, getValue()) : getValue();
return values;
}

public void restoreState(FacesContext context, Object state)
{
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
Object value =
restoreAttachedState(context,values[1]);

ValueBinding vb = getValueBinding(value);
if (vb != null)
{
vb.setValue(context, value);
}
}

This works good both with stateholders and lists, also the ugly part is
removed since we dont need to tell the component to take special care during
restoreState.

Cagatay


On 10/15/06, Martin Marinschek [EMAIL PROTECTED] wrote:
 The problem is that a list is internally not just serialized, but
 specially treated (wrapped, and then on restore you have a different
 list than you had before - no good).

 And that's something that Cagatay understandably doesn't want

 Cagatay, how about adding an additional parameter to the component (on
 calling save-state) which tells the component on restore-state if it
 should restore the value normally or via restoreAttachedState?

 public Object saveState(FacesContext context)
 {
 Object values[] = new Object[3];
 values[0] = super.saveState(context);
 boolean stateHolder = getValue() instanceof StateHolder;
 values[1] =  stateHolder ? saveAttachedState(context,
 getValue()) : getValue();
 values[2] =  Boolean.valueOf(stateHolder);
 return values;
 }

 regards,

 Martin

 On 10/15/06, Matthias Wessendorf  [EMAIL PROTECTED] wrote:
  Hi catagay,
 
  javax.faces.component._AttachedStateWrapper is pretty
much myfaces_api isn't it?
  so shouldn't be used inside the savastate custom comp.
 
  can you explain why it is failing?
 
  Thanks!
 
 
  On 10/14/06, Cagatay Civici [EMAIL PROTECTED] wrote:
   Hi,
  
   I'd like to discuss the latest issues about the savestate component.
  
   In order to use the component with a value of type StateHolder,
   restoreAttachedState-saveAttachedState is used. But
using
   them fails with list implementations other than arraylists.
  
   See this one;
  
   See this one;
   http://issues.apache.org/jira/browse/TOMAHAWK-738
  
   It seems restoreAttachedState-saveAttachedState
should only
   be used when the value is a stateholder, I've found an ugly solution
to the
   problem as;
  
   public Object saveState(FacesContext context)
   {
   Object values[] = new Object[2];
   values[0] = super.saveState(context);
   values[1] = getValue() instanceof StateHolder ?
   saveAttachedState(context, getValue()) : getValue();
   return values;
   }
  
   public void restoreState(FacesContext context, Object state)
   {
   Object values[] = (Object[])state;
   super.restoreState(context, values[0]);
   Object value =
   values[1].getClass().getName().equals(
   javax.faces.component._AttachedStateWrapper) ?
   restoreAttachedState(context,values[1]) : values[1];
  
   ValueBinding vb = getValueBinding(value);
   if (vb != null)
   {
   vb.setValue(context, value);
   }
   }
  
   Since _AttachedStateWrapper is private, I cant use instanceof, using
class
   name is the ugly part. Other than that it works fine with all cases.
  
   Any ideas about this?
  
   Cagatay
  
  
  
  
  
 
 
  --
  Matthias Wessendorf
  http://tinyurl.com/fmywh
 
  further stuff:
  blog: http://jroller.com/page/mwessendorf
  mail: mwessendorf-at-gmail-dot-com
 


 --

 http://www.irian.at

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

 Professional Support for Apache MyFaces






--

http://www.irian.at

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

Professional Support for Apache MyFaces


Re: SaveState Issues

2006-10-15 Thread Cagatay Civici
Yes Marting that's exactly the problem. After digging more, I've realized that we dont need to change anything in restoreState of the component because calling restoreAttachedState will simply return the value if it's not a special wrapped type.
public Object saveState(FacesContext context) { Object values[] = new Object[2]; values[0] = super.saveState(context); values[1] = getValue() instanceof StateHolder ? saveAttachedState(context, getValue()) : getValue();
 return values; } public void restoreState(FacesContext context, Object state) { Object values[] = (Object[])state; super.restoreState(context, values[0]); Object value = restoreAttachedState(context,values[1]);
  ValueBinding vb = getValueBinding(value); if (vb != null) { vb.setValue(context, value); } }This works good both with stateholders and lists, also the ugly part is removed since we dont need to tell the component to take special care during restoreState.
CagatayOn 10/15/06, Martin Marinschek [EMAIL PROTECTED] wrote:
The problem is that a list is internally not just serialized, butspecially treated (wrapped, and then on restore you have a differentlist than you had before - no good).And that's something that Cagatay understandably doesn't want
Cagatay, how about adding an additional parameter to the component (oncalling save-state) which tells the component on restore-state if itshould restore the value normally or via restoreAttachedState?
public Object saveState(FacesContext context){Object values[] = new Object[3];values[0] = super.saveState(context);boolean stateHolder = getValue() instanceof StateHolder;values[1] =stateHolder ? saveAttachedState(context,
getValue()) : getValue();values[2] =Boolean.valueOf(stateHolder);return values;}regards,MartinOn 10/15/06, Matthias Wessendorf 
[EMAIL PROTECTED] wrote: Hi catagay, javax.faces.component._AttachedStateWrapper is pretty much myfaces_api isn't it? so shouldn't be used inside the savastate custom comp.
 can you explain why it is failing? Thanks! On 10/14/06, Cagatay Civici [EMAIL PROTECTED] wrote:  Hi,
   I'd like to discuss the latest issues about the savestate component.   In order to use the component with a value of type StateHolder,  restoreAttachedState-saveAttachedState is used. But using
  them fails with list implementations other than arraylists.   See this one;   See this one;  
http://issues.apache.org/jira/browse/TOMAHAWK-738   It seems restoreAttachedState-saveAttachedState should only  be used when the value is a stateholder, I've found an ugly solution to the
  problem as;   public Object saveState(FacesContext context)  {  Object values[] = new Object[2];  values[0] = super.saveState(context);
  values[1] = getValue() instanceof StateHolder ?  saveAttachedState(context, getValue()) : getValue();  return values;  }   public void restoreState(FacesContext context, Object state)
  {  Object values[] = (Object[])state;  super.restoreState(context, values[0]);  Object value =  values[1].getClass().getName().equals(
  javax.faces.component._AttachedStateWrapper) ?  restoreAttachedState(context,values[1]) : values[1];   ValueBinding vb = getValueBinding(value);
  if (vb != null)  {  vb.setValue(context, value);  }  }   Since _AttachedStateWrapper is private, I cant use instanceof, using class
  name is the ugly part. Other than that it works fine with all cases.   Any ideas about this?   Cagatay 
 -- Matthias Wessendorf http://tinyurl.com/fmywh further stuff: blog: http://jroller.com/page/mwessendorf
 mail: mwessendorf-at-gmail-dot-com--http://www.irian.atYour JSF powerhouse -JSF Consulting, Development andCourses in English and German
Professional Support for Apache MyFaces


SaveState Issues

2006-10-14 Thread Cagatay Civici
Hi,I'd like to discuss the latest issues about the savestate component.In order to use the component with a value of type StateHolder, restoreAttachedState-saveAttachedState is used. But using them fails with list implementations other than arraylists.
See this one;See this one; http://issues.apache.org/jira/browse/TOMAHAWK-738It seems restoreAttachedState-saveAttachedState should only be used when the value is a stateholder, I've found an ugly solution to the problem as;
public Object saveState(FacesContext context) { Object values[] = new Object[2]; values[0] = super.saveState(context); values[1] = getValue() instanceof StateHolder ? saveAttachedState(context, getValue()) : getValue();
 return values; } public void restoreState(FacesContext context, Object state) { Object values[] = (Object[])state; super.restoreState(context, values[0]); Object value = values[1].getClass().getName().equals(
javax.faces.component._AttachedStateWrapper) ? restoreAttachedState(context,values[1]) : values[1];  ValueBinding vb = getValueBinding(value); if (vb != null) {
 vb.setValue(context, value); } }Since _AttachedStateWrapper is private, I cant use instanceof, using class name is the ugly part. Other than that it works fine with all cases.
Any ideas about this?Cagatay


Re: SaveState Issues

2006-10-14 Thread Matthias Wessendorf

Hi catagay,

javax.faces.component._AttachedStateWrapper is pretty much myfaces_api isn't it?
so shouldn't be used inside the savastate custom comp.

can you explain why it is failing?

Thanks!


On 10/14/06, Cagatay Civici [EMAIL PROTECTED] wrote:

Hi,

I'd like to discuss the latest issues about the savestate component.

In order to use the component with a value of type StateHolder,
restoreAttachedState-saveAttachedState is used. But using
them fails with list implementations other than arraylists.

See this one;

See this one;
http://issues.apache.org/jira/browse/TOMAHAWK-738

It seems restoreAttachedState-saveAttachedState should only
be used when the value is a stateholder, I've found an ugly solution to the
problem as;

public Object saveState(FacesContext context)
{
Object values[] = new Object[2];
values[0] = super.saveState(context);
values[1] = getValue() instanceof StateHolder ?
saveAttachedState(context, getValue()) : getValue();
return values;
}

public void restoreState(FacesContext context, Object state)
{
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
Object value =
values[1].getClass().getName().equals(
javax.faces.component._AttachedStateWrapper) ?
restoreAttachedState(context,values[1]) : values[1];

ValueBinding vb = getValueBinding(value);
if (vb != null)
{
vb.setValue(context, value);
}
}

Since _AttachedStateWrapper is private, I cant use instanceof, using class
name is the ugly part. Other than that it works fine with all cases.

Any ideas about this?

Cagatay








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

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


Re: SaveState Issues

2006-10-14 Thread Martin Marinschek

The problem is that a list is internally not just serialized, but
specially treated (wrapped, and then on restore you have a different
list than you had before - no good).

And that's something that Cagatay understandably doesn't want

Cagatay, how about adding an additional parameter to the component (on
calling save-state) which tells the component on restore-state if it
should restore the value normally or via restoreAttachedState?

public Object saveState(FacesContext context)
   {
   Object values[] = new Object[3];
   values[0] = super.saveState(context);
   boolean stateHolder = getValue() instanceof StateHolder;
   values[1] =  stateHolder ? saveAttachedState(context,
getValue()) : getValue();
   values[2] =  Boolean.valueOf(stateHolder);
   return values;
   }

regards,

Martin

On 10/15/06, Matthias Wessendorf [EMAIL PROTECTED] wrote:

Hi catagay,

javax.faces.component._AttachedStateWrapper is pretty much myfaces_api isn't it?
so shouldn't be used inside the savastate custom comp.

can you explain why it is failing?

Thanks!


On 10/14/06, Cagatay Civici [EMAIL PROTECTED] wrote:
 Hi,

 I'd like to discuss the latest issues about the savestate component.

 In order to use the component with a value of type StateHolder,
 restoreAttachedState-saveAttachedState is used. But using
 them fails with list implementations other than arraylists.

 See this one;

 See this one;
 http://issues.apache.org/jira/browse/TOMAHAWK-738

 It seems restoreAttachedState-saveAttachedState should only
 be used when the value is a stateholder, I've found an ugly solution to the
 problem as;

 public Object saveState(FacesContext context)
 {
 Object values[] = new Object[2];
 values[0] = super.saveState(context);
 values[1] = getValue() instanceof StateHolder ?
 saveAttachedState(context, getValue()) : getValue();
 return values;
 }

 public void restoreState(FacesContext context, Object state)
 {
 Object values[] = (Object[])state;
 super.restoreState(context, values[0]);
 Object value =
 values[1].getClass().getName().equals(
 javax.faces.component._AttachedStateWrapper) ?
 restoreAttachedState(context,values[1]) : values[1];

 ValueBinding vb = getValueBinding(value);
 if (vb != null)
 {
 vb.setValue(context, value);
 }
 }

 Since _AttachedStateWrapper is private, I cant use instanceof, using class
 name is the ugly part. Other than that it works fine with all cases.

 Any ideas about this?

 Cagatay







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

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




--

http://www.irian.at

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

Professional Support for Apache MyFaces