Yeah, absolutely a hack.
Option #2 that I can think of is caching the action URL at
the start of the FormRenderer encoding, then re-querying it
at the end. If it's changed, add Javascript to find the form
and overwrite the action. Also gross, but at least it's not
as bad as adding a configuration switch.
-- Adam
On 9/28/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
> Yeah, that's what we figured while playing with it, but it's not the most
> elegant solution. Maybe we should make that configurable in trinidad-config
> (not supporting EL)? Most users can probably deal with the issue so it
> should not save the scope by default when it's empty, but users needing it
> would be able to without using that hack, because that's really what it is.
>
> ~ Simon
>
>
> On 9/28/07, Adam Winer <[EMAIL PROTECTED]> wrote:
> > 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
> > >
> >
>
>