I want to create some reusable JSP tag files for form fragments in my Stripes
application.  For example, say I have a "Foo" domain object that has a "Bar"
property that can be manipulated via a form.  It's easy to set up a form, using
field names like "foo.bar".  This assumes, of course, that the ActionBean
handling the form has a "Foo" property.

Say I also have a "Baz" domain object that has a "Foo" property, and that in
some situations, I need to manipulate a Foo object in the context of its owning
Baz instance in a form.  Assuming the ActionBean has a "Baz" property, I would
want my field labels to look like "baz.foo.bar" instead.

My problem derives from the fact that I'd like to have a reusable tag file
that encapsulates the details of a Foo object, such that I could include it
on forms where I need to edit a lone Foo object, as well as on forms for the
Baz object.    If my ActionBean already has a Baz property, I don't want to
add a Foo property just to use the tag file, and then have to manually wire up
that Foo with the Baz object.  I've got a rather intricately interconnected
domain model, and this approach will not scale well.

One solution I've hit upon is declaring the tag to take a String attribute that
I use to create the field names.  For example, I have fields in the JSP
declared like:

    <stripes:text name="${fooProperty}.bar"/>

In the case of editing a Foo object, you'd use "foo" as the value of 
${fooProperty}.  In the case of a Baz object, you'd use "baz.foo" instead.

If I want to do anything in the tag that manipulates the actual Foo object
(e.g. EL tests), I don't know of a nice way to get a hold of that object from
the property string I passed in.  Ideally, I'd like to be able to do something
like this when I need the actual object:

    ${${fooProperty}}

That is, evaluate "fooProperty" to the string "baz.foo", and then evaluate
*that* to get to the actual Foo object (i.e. bazInstance.getFoo()).  Obviously,
that's not possible, since this is an invalid EL expression.

I thought of writing a custom EL function that uses an EL evaluator internally
so I could evaluate the property string how I want and return the object.  As
near as I can tell, however, I would have to pass the PageContext into the
function as well, which is pretty ugly.

Arguably as ugly, though considerably simpler to implement, is to require
another attribute on my JSP tag file that passes in the actual object as well.
This would end up looking something like this:

    <tags:myFooTag fooProperty="baz.foo" fooObject="${actionBean.baz.foo}"/>

Yes, it's redundant, but for simplicity and expediency, this is the approach
I've settled on.

With all that being said, is there a better way to do what I'm trying to do?


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to