yes the Struts 1.x if tag has been deprecated
you can check for specific attributes as wes suggested
OR
change your struts-spring autowire type to "constructor" in your interceptor
stack e.g.
\WEB-INF\src\java\struts.xml
<interceptors>
<interceptor name="autowire"
class="com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor">
<param name="autowireStrategy">2</param>
</interceptor>
<interceptor-stack name="autowireDefault">
<interceptor-ref name="autowire"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
and configure the springframework ContextLoaderListener in web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
where the individual bean has been configured as
<bean name="some-action" class="fully.qualified.class.name" singleton="false">
</bean>
take a brief look at the characteristics of your Bean class from Bean.java
public boolean start(Writer writer) {
boolean result = super.start(writer);
ValueStack stack = getStack();
try {
String beanName = findString(name, "name", "Bean name is required.
Example: com.acme.FooBean");
bean = objectFactory.buildBean(ClassLoaderUtil.loadClass(beanName,
getClass()), stack.getContext());
} catch (Exception e) {
LOG.error("Could not instantiate bean", e);
return false;
}
// push bean on stack
stack.push(bean);
...
}
that last statement stack.push(bean) means the bean is now on the stack to test
with!
from jsp
<s:property value="#beanname" />
we now know the bean as a constructed Bean object
(via the decorated name of the bean)
feel free to use the stack.push to push the necessary value to be accessed
later by <s:property ... /> in your jsp..
Martin
______________________________________________
Disclaimer and Confidentiality/Verzicht und Vertraulichkeitanmerkung / Note de
déni et de confidentialité
This message is confidential. If you should not be the intended receiver, then
we ask politely to report. Each unauthorized forwarding or manufacturing of a
copy is inadmissible. This message serves only for the exchange of information
and has no legal binding effect. Due to the easy manipulation of emails we
cannot take responsibility over the the contents.
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung.
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est
interdite. Ce message sert à l'information seulement et n'aura pas n'importe
quel effet légalement obligatoire. Étant donné que les email peuvent facilement
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité
pour le contenu fourni.
> From: [email protected]
> To: [email protected]
> Subject: Re: Struts2 equivalent of <logic:present role=""...>
> Date: Wed, 15 Apr 2009 16:08:59 -0400
>
> On Wednesday 15 April 2009 16:00:34 Russell Neufeld wrote:
> > Hi all,
> >
> > We're porting an app from Struts 1 to Struts 2, and I'm having
> > trouble figuring out how to conditionally include a portion of a JSP
> > depending on the role of the user principal. In Struts 1 we did this:
> >
> > <logic:present role="SERVICE,SYSTEM">
> > ... some html ...
> > </logic:present>
> >
> > What's the preferred way of doing this in Struts2? Thanks,
> >
> > Russ
>
> There are a couple of ways to do it, personally, I would use Spring Security
> and incorporate their tag library. It will eliminate quite a bit of work on
> your part.
>
> Since you are probably pressed for time since this is an upgrade effort, the
> better method would be to expose your user object in a way that you can get
> at
> the list of roles (such as putting it in the session). Then, just use s:if
> and
> some OGNL to check like this -
>
> <s:if test="#session.user.roles.contains('REQUIRED_ROLE')">
> ...
> </s:if>
>
> -Wes
>
> --
>
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
_________________________________________________________________
Rediscover Hotmail®: Get e-mail storage that grows with you.
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage1_042009