You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Farrell <df...@farrellconsultancy.com> on 2004/10/10 13:52:48 UTC

Dynamic Include based on a bean's property.

Hi all,

I've had a look at previous messages on the list.

This one looks kind of close to what I'm looking for: 
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg81563.html

but the problem I have is that although I have been programming java for 
a number of years, I'm very new to JSP and am not really intuitive or 
familiar with that aspect of programming.  I get by due to Java knowlege 
but dont think on my feet too well with JSP.

So....

I'm NOT using tiles for this app, its too late I think to change it for 
my deadlines but I am doing something similar (next time I may use tiles).

I am putting a bean called "module" into the request.

Then I forward the user to a JSP page.

When that page loads, I want to load the html:form that is appropriate 
for this type of module (each module will have a corresponding form and 
actions to recieve the form's input).

My first attempt was:

<%@ include file="includes/<bean:write name="module" 
property="includeFile"/>" %>

But of course that doesn't work.

Then I changed the 'includeFile' property of module to actually be the 
whole include tag.

so I did:

<bean:write name="module" property="includeFile"/>

But of course, that doesnt work partially because the bean:write is 
clever enough to convert my html tags to &gr etc... but also because (as 
I found out later) the jsp engine complies the standard include tags NOT 
at run time - so this could never work.

Then I found out abotu the <jsp:include  tag - I think that eventually 
this will work for me.
Because it is not precompiled but instead compiled at run time, it 
should (if syntax allows it) be able to include a different file each time.

So... .

I think I can somehow use the <jsp:include tag and instead of just 
having a hardcoded string that specifies the file, I oughta be able to 
say " the string you want comes from bean 'module' and its' property 
called 'includeFile" but I can't figure out how to do this.

Can someone help me out and show me how to do this?

Many thanks

David

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Include based on a bean's property.

Posted by Rick Reumann <st...@reumann.net>.
David Farrell wrote the following on 10/10/2004 7:52 AM:

> When that page loads, I want to load the html:form that is appropriate 
> for this type of module (each module will have a corresponding form and 
> actions to recieve the form's input).

This is handled automagically for you by the strtus-config action 
mappings. When you want to go to XYZ.jsp to perform a certain behavior 
(say "edit employee") you would associate your form with that action in 
your struts config so it's already there for you. (no need for you to 
worry about making sure it's there).

> 
> My first attempt was:
> 
> <%@ include file="includes/<bean:write name="module" 
> property="includeFile"/>" %>
> 
> But of course that doesn't work.
> 
> Then I changed the 'includeFile' property of module to actually be the 
> whole include tag.
> 
> so I did:
> 
> <bean:write name="module" property="includeFile"/>

What kind of stuff does this "includeFile" have in it? I'm pretty sure 
there is a much easier way to skin a cat than the approach you are 
taking (although I'm not clear what you are trying to accomplish:)

<snip>
> Because it is not precompiled but instead compiled at run time, it 
> should (if syntax allows it) be able to include a different file each time.

That is correct.

> 
> So... .
> 
> I think I can somehow use the <jsp:include tag and instead of just 
> having a hardcoded string that specifies the file, I oughta be able to 
> say " the string you want comes from bean 'module' and its' property 
> called 'includeFile" but I can't figure out how to do this.

Well if you have a bean "module" put into correct scope (request if 
right before you do the forward to the page or session), I'd use the 
c:import tag since it appends the context for you...

<c:import url='/someDir/${module.includeFile}'/>

(assumed bean module is in scope and it has a getter getIncludeFile() )

I'm still thinking you are making this harder on yourself than it needs 
to be, though.



-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Include based on a bean's property.

Posted by David Farrell <df...@farrellconsultancy.com>.
The concensus seems to be 'go with tiles'

So I've done just that.

I had actually pretty much recreated the basic 'tiling engine' I guess - 
bar the code that dynamically plugs in the jsp but it was very bespoke 
and its always good to use a 'standard' as opposed to just making it up 
as you go along.

Cheers for the tips.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Dynamic Include based on a bean's property.

Posted by Joe Hertz <jh...@speakeasy.net>.
+1 for Michael's comment.

David,

Based on what youre already doing, I don't think your jsp knowledge is a
limiting factor.

I think it's possible to learn 98% of tiles by just looking at an example
Tile app's layout.jsp, and its struts-config.xml and tiles-def.xml in Struts
Console.

Tiles is really just that intuitive.

What you want to do with Tiles won't be time consuming at all. Maybe ripping
out the stuff you've already done might be though, but Tiles does exactly
what you want.

-Joe

-----Original Message-----
From: Michael McGrady [mailto:mike@michaelmcgrady.com]
Sent: Sunday, October 10, 2004 11:24 AM
To: Struts Users Mailing List
Subject: Re: Dynamic Include based on a bean's property.


You would be way far ahead just learning Tiles or templating with
Struts.  This stuff has already been done and you are reinventing the
wheel.  Sometimes that is necesasry because the default implementation
in Struts is unsatisfactory for you.  But, in this case, there is an
easy use of Tiles, etc. that will save you time, not cost you time.  It
really is easy to use Tiles.  You can learn what you need to know to be
way past where you are now in a couple hours at the most.

Michael McGrady

David Farrell wrote:

> Hi all,
>
> I've had a look at previous messages on the list.
>
> This one looks kind of close to what I'm looking for:
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg81563.html
>
> but the problem I have is that although I have been programming java
> for a number of years, I'm very new to JSP and am not really intuitive
> or familiar with that aspect of programming.  I get by due to Java
> knowlege but dont think on my feet too well with JSP.
>
> So....
>
> I'm NOT using tiles for this app, its too late I think to change it
> for my deadlines but I am doing something similar (next time I may use
> tiles).
>
> I am putting a bean called "module" into the request.
>
> Then I forward the user to a JSP page.
>
> When that page loads, I want to load the html:form that is appropriate
> for this type of module (each module will have a corresponding form
> and actions to recieve the form's input).
>
> My first attempt was:
>
> <%@ include file="includes/<bean:write name="module"
> property="includeFile"/>" %>
>
> But of course that doesn't work.
>
> Then I changed the 'includeFile' property of module to actually be the
> whole include tag.
>
> so I did:
>
> <bean:write name="module" property="includeFile"/>
>
> But of course, that doesnt work partially because the bean:write is
> clever enough to convert my html tags to &gr etc... but also because
> (as I found out later) the jsp engine complies the standard include
> tags NOT at run time - so this could never work.
>
> Then I found out abotu the <jsp:include  tag - I think that eventually
> this will work for me.
> Because it is not precompiled but instead compiled at run time, it
> should (if syntax allows it) be able to include a different file each
> time.
>
> So... .
>
> I think I can somehow use the <jsp:include tag and instead of just
> having a hardcoded string that specifies the file, I oughta be able to
> say " the string you want comes from bean 'module' and its' property
> called 'includeFile" but I can't figure out how to do this.
>
> Can someone help me out and show me how to do this?
>
> Many thanks
>
> David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Include based on a bean's property.

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
You would be way far ahead just learning Tiles or templating with 
Struts.  This stuff has already been done and you are reinventing the 
wheel.  Sometimes that is necesasry because the default implementation 
in Struts is unsatisfactory for you.  But, in this case, there is an 
easy use of Tiles, etc. that will save you time, not cost you time.  It 
really is easy to use Tiles.  You can learn what you need to know to be 
way past where you are now in a couple hours at the most.

Michael McGrady

David Farrell wrote:

> Hi all,
>
> I've had a look at previous messages on the list.
>
> This one looks kind of close to what I'm looking for: 
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg81563.html
>
> but the problem I have is that although I have been programming java 
> for a number of years, I'm very new to JSP and am not really intuitive 
> or familiar with that aspect of programming.  I get by due to Java 
> knowlege but dont think on my feet too well with JSP.
>
> So....
>
> I'm NOT using tiles for this app, its too late I think to change it 
> for my deadlines but I am doing something similar (next time I may use 
> tiles).
>
> I am putting a bean called "module" into the request.
>
> Then I forward the user to a JSP page.
>
> When that page loads, I want to load the html:form that is appropriate 
> for this type of module (each module will have a corresponding form 
> and actions to recieve the form's input).
>
> My first attempt was:
>
> <%@ include file="includes/<bean:write name="module" 
> property="includeFile"/>" %>
>
> But of course that doesn't work.
>
> Then I changed the 'includeFile' property of module to actually be the 
> whole include tag.
>
> so I did:
>
> <bean:write name="module" property="includeFile"/>
>
> But of course, that doesnt work partially because the bean:write is 
> clever enough to convert my html tags to &gr etc... but also because 
> (as I found out later) the jsp engine complies the standard include 
> tags NOT at run time - so this could never work.
>
> Then I found out abotu the <jsp:include  tag - I think that eventually 
> this will work for me.
> Because it is not precompiled but instead compiled at run time, it 
> should (if syntax allows it) be able to include a different file each 
> time.
>
> So... .
>
> I think I can somehow use the <jsp:include tag and instead of just 
> having a hardcoded string that specifies the file, I oughta be able to 
> say " the string you want comes from bean 'module' and its' property 
> called 'includeFile" but I can't figure out how to do this.
>
> Can someone help me out and show me how to do this?
>
> Many thanks
>
> David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org