[Opensource] blocks, outputs, and attributes?

Michael Rimov rimovm at centercomp.com
Tue Mar 11 15:29:49 PST 2003


At 09:14 PM 3/10/2003 -0600, you wrote:
>Every time I think I understand the nested bean thing....
>
>After a long battle, I found that to access the attribute in this structure:
>- block
>    - output
>        - attribute (of the output)
>
>I had to use this:
><bean:write property="/block/output. at attribute"/>
>

Hi Mike,
That . shouldn't have been necessary, you're absolutely right...  In fact, 
since one job I was working on wasn't working last night, that's probably 
the very issue :)  I'll see about getting that fixed.

>To get there, I used some trial and error, and eventually had to run 
>through a debugger. The "." was a surprise to me. Also, I would have 
>thought <bean:write name="/block/output" property="@attribute"/> would work.

Name is only for the name of the bean in the request scope or session 
scope, it has no knowledge of nesting.  Property is where you do all the 
nesting.

It helped me to figure out what Mike N. did by looking at the pure struts 
version.  The above is:

<struts-bean:write name="controllerResponse" 
property="block(blockName).output(outputName).attribute(attributeName)/>

So when he wrote the 'extended tags'
name is automatically controllerResponse unless specified,
property was designed to save all the typing.

>Anyone got a definitive how-to on ".", "@", and "/"? Sometimes I just go 
>crazy trying to figure out the right combo.

Ok, again, you've hit a bug in the example you gave... you were on the 
right track :)

So, here's the gist:

Think XPath first.  Forward slashes equals nesting, @ signs equals 
'Attributes' and periods equals properties.

. == bean method.  Mike didn't have access to Beanutils at the time, so he 
only specified a few properties that you can get with this.  If Somebody 
wanted to use PropertyUtils to expand this to any property, it would be 
great.  The most common use of such thing is Transition.url  so if you pick 
up a transition, having .url in the property will call getUrl();

@ = ControllerElement.getAttribute()

/ = Nesting.  Now I'm with you, I think the way Mike implemented it was a 
bit confusing and not exactly consistent.

I've found that due to the consistency issues, I've been using pure struts 
tags in my programming and then use the expresso extensions where needed. 
[The classic example is the expresso submit buttons which need to have a 
special hidden field added to them].  The nice thing is since the one is an 
extension of another, I can switch back and forth in the same code.

For example.  The following code iterates through the transitions in a 
controllerResponse and outputs a link, label, and everything, one 
transition per line. (Thanks to Malcolm Wise for this tag... it's wonderful!)

<struts-logic:iterate id="eachTransition" name="controllerResponse" 
property="transitions">
         <p><html:exLink name="eachTransition/></p>
</struts-logic:iterate>

[For my own coding, I've started using "struts-" prefixes for the real 
thing and no prefix for the expresso extensions.  so  <struts-bean:write/> 
is the pure struts write tag, and <bean:write/> is the Expresso version.

Anyway, as I said, I'm finding my jsp programming much more productive this 
way.

The other way would be to use JSTL.  I've updated the EDG chapter in CVS on 
JSP programming to show the use of pure struts and JSTL tags when dealing 
with a ControllerResponse object, you might want to give it a gander to see 
if it gives you any ideas.

Speaking of which, since I'm up to my eyeballs right now, anybody with 
commit access willing to format/edit what I just wrote and put it in EDG 
JSP Chapter???  I'd really appreciate it!
                                                 -Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.jcorporate.com/pipermail/opensource/attachments/20030311/226468cc/attachment-0002.htm


More information about the Opensource mailing list