On 6/26/06, Gary VanMatre <[EMAIL PROTECTED]> wrote:
>From: "Ryan Wynn" <[EMAIL PROTECTED]>
>
> I think that there may be a good case for symbol replacement on a
> symbol. Here is what I was trying to do:
>
> class MyBean {
> String prop = "propValue";
> public String getProp();
> public void setProp(String string);
> }
>
>
> Client.html
>  <span jsfid="clay" clayJsfid="Template.html" foo="#{myBean.prop}"/>
>
>
> Template.html (bean and property agnostic)
>
><body>
       ><span jsfid="tree" value="@foo"/>
>
       ><span jsfid="outputText value="@foo"/>
>
></body>
>
>
> Custom component
>
><component jsfid="tree" extends="panelGroup">
><element renderId="1" jsfid="outputText">
><attributes>
>       <set name="value" value="@value"/>
></attributes>
></element>
><element render="2".../>
>
></component>
>
>
> Now when client.html is rendered the 1st span is outputting
>
> @value
>
> while the 2nd span is outputting correctly (or as I had intended)
>
> myValue
>
>
> I believe that this is because the attribute override is only
> happening for first level attributes, not nested attributes.
>
> 2 possible solutions
>
> (A)
>
> I think that symbol replacement could also be done for symbols
> themselves, and I think that it would solve this case.
>
> This way the symbol table for tree and thereby it's first child would
> look like this
>
> { @value=> @foo
> @foo => #{myBean.prop}
> }
>
> so that when symbol replacement is done for @value in the 1st child
> the result is #{myBean.prop}
>
> (B)
>
> The override of value in tree in Template.html could reach down into
> tree's children as well.
>
>
> I am currently in favor of (A) as I think it might be less disruptive.
>
That's an interesting idea. I believe option (A) would be possible. I think 
this would work out if we only took one pass at it. Otherwise, we could end up 
in an infinite loop.


You could keep track of the symbols visited to stay away from the
infinite loop.  I don't think the depth will ordinally be very deep at
all.

String symbolName = context.getSymbol();
String symbolVal = null;
Set visited = new HashSet();

  do {
     if (!visited.add(symbolName))  {
            break;
            // or is it an error?
     }
     symbolVal = (String) symbolTable.get(symbolName);
  }

  while (! isSymbol(symbolVal) );

component.setAttribute(attributeName, symbolVal);


The symbols are evaluated just before they are pushed to the target JSF 
component. We create a new map that represents a newly scoped symbol table. We 
populate it from the outer scope and then override with symbols from the inner 
scope.


// create a new scoped symbol table
Map symbolTable = new Attributes();
// inherit the parents symbols
symbolTable.putAll(clayContext.getSymbols());
// override config (XML, HTML) symbols
symbolTable.putAll(displayElement.getSymbols());
// push to context
clayContext.setSymbols(symbolTable);


We might be able to perform symbol replacement on symbols just before pushing 
it to the new context.

That sounds good.



Please create a JIRA ticket on this one.

Created http://issues.apache.org/struts/browse/SHALE-201



> Ryan
>

Gary

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to