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