Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Implementing AspectJ in JSP with Tag

Hi

I tried using "execution" and the advice was being called whenever this
function was called.

public aspect Example{
pointcut requiredField() : execution(*
encompass.studymaintenance.beans.*.*get*(..));
before() : requiredField() {
    System.out.println("entering: " + thisJoinPoint);
    System.out.println("      at: " +
thisJoinPoint.getSourceLocation());
  }


But it was not able to serve my purpose as I want the beans to return
formatted text to the JSP. So I need to apply advice only when it's
called from the JSP and not from anywhere else. With the execution
approach it will execute for all the calls to the getters of the bean.
But I want the advice to execute only when called from jsp.

Also I tried to get the source location with the execution approach but
it's not giving the correct value from where the joint point is called.

Will appreciate if someone can help me.

Thanks
Saurabh

------------------------------------------------------------------------
---------------------------------------------------------------------
>Hi,
>
>First, it looks like you are compiling your jsps separately from your
>aspects, and then recompiling them with your aspects.  Not exactly
>sure how jspc works, if it produces Java source or Java byte code.
>Regardless, you probably want to put the jsp code on your in path so
>that ajc knows to apply aspects to it.
>
>Second, try using execution, not call.  This will pick out the join
>point inside the called method, not at the method that is doing the
>calling.  If you do this, then you may not even need to put your jsps
>through ajc at all since it is only the beans that should be affected
>by the advice.  Of course, this implies that *any* time one of these
>bean get methods are called, you want the advice to run (in your
>description you say that you only want it to run when called by a
>jsp).
>
>On Fri, Jan 23, 2009 at 4:35 AM, Saurabh Khattar, HCL-Industry
>Solutions <ksaurabh@xxxxxx> wrote:
> Hi all
>
>
>
> I am trying to implemenet AspectJ in my application.
>
>
>
> My application have package containing all the beans(
mypackage.beans). What
> I want to do is whenever I the getters of the beans are called from
the jsp
> it should call the advice and return the formatted value.
>
>
>
> What I have done is:
>
>
>
> STEP1: Created an aspect :
>
>
>
> public aspect Example{
>
>
>
> pointcut requiredField() : call(*mypackage.beans.*get*(..));
>
> before() : requiredField() {
>
>     System.out.println("entering: " + thisJoinPoint);
>
>     System.out.println("      at: " +
thisJoinPoint.getSourceLocation());
>
>   }
>
> }\
>
>
>
> STEP 2: I am usning ant in the project to build. So I first
precompiled by
> jsp  through JspC. And then I am trying to compile these jsp servlets
> through iajc.
>
>
>
> <iajc source="${javac.source}"
>
>                           deprecation="false"
>
>                           debug="${javac.debug}"
>
>                           debuglevel  =
> "${javac.debuglevel}"
>
>                           destdir="@{output.dir}"
>
>                           classpathref="@{classpath.pathref}"
>
>                           fork        = "true"
>
>                     maxmem      ="512m">
>
>                         <sourceroots>
>
>                               <path refid="@{src.pathref}" />
<!-path for
> the Java source-->
>
>                               <path location="jasper_src" />
<!--path
> for the jsp servlets source-->
>
>                         </sourceroots>
>
>                   </iajc>
>
>
>
>
>
> My problem is that I am using JSTL in my JSP's and whenever I am
fetching
> value from my bean in my jsp I am using tags rather than writing java
code
> in scriptlets to fetch the data. And the jsp compiler converts these
tags
> into :
>
>
>
>
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${bean.va
lue}",
> java.lang.Object.class, (PageContext)_jspx_page_context, null,
false));
>
>
>
> This function gets the value from the bean by calling the getter
function
> only but all this is done internally.Due to this the jointpoint is not
> applied here. Also this functions gets the vale from the bean at
runtime so
> I am not able to identify the jointpoint.
>
>
>
> Kindly let me know how to overcome this problem and my advice is
called
> whenever jsp gets the value from bean.
>
>
>
> Thanks in Advance.
>
>
>
> Saurabh

DISCLAIMER:
-----------------------------------------------------------------------------------------------------------------------
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. 
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in 
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates. 
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of 
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have 
received this email in error please delete it and notify the sender immediately. Before opening any mail and 
attachments please check them for viruses and defect.
-----------------------------------------------------------------------------------------------------------------------


Back to the top