It's a long-standing problem with form URL encoding.

If you don't add anything to pageFlowScope until Render Response,
those objects will be lost, 'cause the token is written out on the
form too early.  We try to be conservative and not generate new
pageFlowScopes unless its necessary.

The "workaround" is to make sure that at least one object
gets set on the pageFlowScope by beforePhase() of
Render Response.  Could be :
  pageFlowScope.put("foo", "bar");
... doesn't matter what.

-- Adam


On 9/28/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> We have a client who played with page flow scope and bit and came to the
> following. Of course, the use case is extremely synthetic, but it's still
> strange:
>
> page.jspx
> <f:view>
>   <tr:document>
>     <tr:form>
>       <tr:inputText value="#{bean.value}"/>
>       <tr:commandButton text="Go"/>
>      </tr:form>
>   </tr:document>
>  </f:view>
>
> Bean.java
>  public class Bean
> {
>   public Bean()
>   {
>     RequestContext rContext =
> RequestContext.getCurrentInstance ();
>
>     Map<String, Object> pageFlowScope = rContext.getPageFlowScope();
>
>     if (!pageFlowScope.containsKey("someKey"))
>     {
>       System.out.println("Creating the long to create object and we sure
> don't want to create it twice for the page flow");
>       pageFlowScope.put("someKey", getAnExpensiveToCreate Object());
>     }
>    }
>
>   public String getValue()
>   {
>     RequestContext rContext =
> RequestContext.getCurrentInstance ();
>
>      Map<String, Object> pageFlowScope = rContext.getPageFlowScope();
>
>     return
> ((SomeClass)pageFlowScope.get("someKey")).getStringAttribute();
>   }
>
>    public void setValue(String value)
>    {
>      RequestContext rContext =
> RequestContext.getCurrentInstance();
>
>      Map<String, Object> pageFlowScope = rContext.getPageFlowScope();
>
>
> ((SomeClass)pageFlowScope.get("someKey")).setStringAttribute(value
> );
>    }
> }
>
> With that code, the expensive object is going to be created twice, when the
> page is first rendered and on first postback. This happen because at the
> time the form is rendered, the page flow scope is still empty (bean was
> never referenced) and the default behavior in that case is to not add the
> token to the action url thus losing the object. Therefore, if you change the
> page to
>
> page.jspx
>  <f:view>
>    <tr:document>
>     <tr:outputText value="#{bean.value}"/>
>      <tr:form>
>        <tr:inputText value="#{bean.value}"/>
>        <tr:commandButton text="Go"/>
>      </tr:form>
>    </tr:document>
>  </f:view>
>
> Then the expensive object get created only once. Personally I think we
> should consider that a bug as it's very counter intuitive and hard to debug.
> Am I missing something?
>
>
> Regards,
>
> ~ Simon
>

Reply via email to