[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

struts: using same property of different beans in the header

If I have a header.jsp that I include with other jsp and it needs to use a specific property of a bean, corresponding to the page that it's included with - which of course changes all the time, except that all beans have that same property.  How would I do that, preferrably without using c:set prior to the <%@ include.
0
aturetsky
Asked:
aturetsky
  • 4
  • 3
1 Solution
 
bloodredsunCommented:
hi alex,

have you tried using <c:import> rather than @include, as @include is for static files while <jsp:include> and <c:import >perform at runtime.

I prefer c:import as it's faster and more stable.
0
 
aturetskyAuthor Commented:
thanks
so, ok, say I use c:import.  How would I deal with the fact that I don't know the bean name.

Now, you may say I should do a <c:set> first, but currently that doesn't seem to be working for me for a different reason (i.e. http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21413918.html)

So, until I solve that issue, is there a way to do it w/o c:set?
0
 
bloodredsunCommented:
yes use a c:import with c:param to pass this info along

e.g.

<c:import url='page.jsp'>
    <c:param name='beanName' value='${requestScope.myBean.name}'/>
</c:import>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aturetskyAuthor Commented:
thanks, brs

I must be doing something wrong since it's not working for me.

I now have a.jsp containing
<c:import url='b.jsp'>
    <c:param name="pageName" value="Buyer's Queue"/>
</c:import>

Then b.jsp contains:

      <td class="titlebar2" align="right" valign="middle">
         &nbsp;
         <c:out value="${requestScope.pageName}"/>
         &nbsp;
      </td>

And what I get when I pull it a.jsp up in the browser is this:

      <td class="titlebar2" align="right" valign="middle">
         &nbsp;

         
         &nbsp;
      </td>
      <td class="titlebar" align="right" valign="middle">

So the import works, but the parameter passing does not.  Any thoughts?
0
 
aturetskyAuthor Commented:
oh, I think I see why - requestScope.pageName would give me a pageName attribute of request, not pageName parameter.

So is there a nice c tag way to output a parameter?
0
 
aturetskyAuthor Commented:
Got it!!!

<c:out value="${param.pageName}"/>

That worked.

Thanks, brs
0
 
bloodredsunCommented:
no probs, it looks like you did all the hardwork ;-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now