aspose file tools*
The moose likes Spring and the fly likes How do I achieve this solution? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How do I achieve this solution?" Watch "How do I achieve this solution?" New topic
Author

How do I achieve this solution?

Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
I have an application which is written using jquery and Direct Web Remoting framework.The js file works as a controller - since all the button clicks are captured using jquery.
The DWR framework is used for navigating between Javascript and Java and vice-versa.
This application has 4 tabs(not 4 urls - just 4 tabs within same url) one of which deals with managing users.

Now I have a requirement (and which I missed to see earlier) wherein if user A deletes user B while user B is using our application on his own machine,user B should be logged out on any button press or any action that he performs.
Remember,all button clicks are captured through jquery functions e.g.

$("#userSaveBtn").click(function() { ..stuff....}

So in other words,I have to check on every button press,if current user exists in db or not .If he does not exist,he needs to be logged out.
One solution can be to write a function using jquery and DWR to check this and direct user to logout screen but it would be tedious to call this function on every button press.
Is there any way I write this function and don't have to call it always?If not,any other better solution?

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Does each button click result in an eventual call the server? If so, it seems that a servlet filter would be a perfect solution.

This is something that needs to be checked on the server in any case as you cannot trust anything coming from the client.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Well,each button click results in code execution on server side - most of it is db transactions.
DWR framework does not pass a handle of request(HttpServletRequest) to java side(or maybe I do not know how to get a request object from DWR framework).
How will servlet filter help - because page does not get refreshed and the URL never changes?

Whenever a button is clicked-there is an Ajax call from javascript to java and then value is returned from java to javascript by Reverse Ajax - All this is done by DWR framework.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

It's been years since I've looked at DWR, so I can't say the best way to do it. But I recall that DWR is just a servlet.

In any case, if you're looking for a purely client-side solution, you're barking up the wrong tree.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
I am not looking for any specific kind of solution - I just want any solution to work.
So you mean I need to explore DWR to find a solution for this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

I mean you need to check this on the server, not the client.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Ok thanks Bear - I wrote a servlet filter for this purpose.It gets executed as well.
But problem now is that filters do not get value of form fields - "username" in my case.If user is invalid,I need to show login screen,otherwise normal flow continues.This is done so that if a user is deleted by some other user while first user has already logged in,he should be taken to login screen whenever he tries to perform any server side updates.

How can I get value of form fields in filter?Any workaround?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

When you say "form fields" are you referring to request parameters? You do of course get a reference to the request in the doFilter() method, so you can get the parameters from the request easily.

Or are these form fields not being sent as request parameters? If they don't get sent with the request then you can't expect the server to see them, so fix the request so that they do get sent.
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Thanks Paul - for now I am able to work my way around finding values of form fields.I will try to make it better after I have achieved my main goal.

Now challenge that I am facing is how to get an instance of session factory classes(dao classes bascically).
If I just initialize them by using new operator,I get HibernateTemplate as null.
I tried using @Autowired keyword also but that also does not work.

Here is the code for filter that I am using -


Any ideas how to get a reference for dao objects that is prepared by Spring 3.0 framework in filter ?I am trying to get a reference of UsersDao class.

here is a line in applicationcontext.xml that scans components -

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Looks like this has turned into a Spring question now, so let's move the thread over to that forum...
Jitesh Sinha
Ranch Hand

Joined: Jun 19, 2004
Posts: 146
Ok Paul,please do the needful.

I was able to get the reference of bean by writing these lines -




Still need to check why I cannot get it to solve my main issue.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Can you create a new thread for the last question in this Spring forum? The first question is confusing me in this thread. It is a new problem and should be treated as a separate thread.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I achieve this solution?