Hi Roger,

You should let a managed bean create your saveState bean. We use a managed
bean to do essentially what your converter is trying to do. Of course, you
have more lattitude using a managed bean than a converter to manipulate the
model :). You can also save the managed bean in the session (session scope)
which allows you to persist session-specific retrieval params for the object
store.

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Roger Keays
Sent: Saturday, May 20, 2006 7:27 AM
To: [email protected]
Subject: Re: using saveState on non-managed bean?


>> I'm trying to use t:saveState to make a bean available across several 
>> requests. Unfortunately it doesn't seem to work (I get a bean is null 
>> error after submitting the form) and AFAICT this is because saveState 
>> restores the bean by doing some magic with ValueBindings, and not 
>> directly manipulating the scope.

I didn't find out why the t:saveState tag wasn't working for me, although I
suspect it is because the ValueBinding had no way of knowing how to create
my bean.

I did come up with an interesting alternative though, and it also works for
non-serialized beans. My trick is to use a converter to fetch the bean from
the database and put it back into the request scope. I make the component
immediate to make sure my bean is in scope before any other conversions or
validations:

<h:inputText value="#{item}" converter="ItemRestorer" immediate="true"/>

public class ItemRestorer implements Converter {
   public String getAsString(...) {
     return ((Content) object).getUuid() + "");
   }

   public Object getAsObject(...) {
     object = fetch from db using uuid;
     requestMap.put("object", object);
     return object;
   }
}

This wouldn't work with non-persistent beans of course.

Roger


--
----------------------------------------
Ninth Avenue Software
p: +61 7 3137 1351 (UTC +10)
f: +61 7 3102 9141
w: http://www.ninthavenue.com.au
e: [EMAIL PROTECTED]
----------------------------------------

Reply via email to