Best way to dynamically load an action controller?
Say all requests go through a front controller. The front controller delegates that request to a particular action controller. The name of the controller, and the name of the action comes from the URL. What's the cleanest way to get an instance of the action controller based on its name, then run a method in it, alo based on its name. Example:
You've got action controllers for two different areas of your application, "forum" and "store". Each of these controllers will deal with different requests, but the front controller is the component which determines the class and the method to invoke.
The controllers have a basic skeleton layout like so:
org.yoursite.controller.actions.ForumActions;
public class ForumActions extends ActionController {
public void executeCreatePost() {
//deal with the "CreatePost" action
public void executeDeleteThread() {
//you get the idea
}org.yoursite.controller.actions.StoreActions;
public class StoreActions extends ActionController {
public void executeViewCart() {
public void executeAddItem() {
}You make a request to http://site.tld/servlet/FrontController?module=store&action=viewCart
The FrontController has enough information to know what you want to do:
StoreController ctl = new StoreController();
ctl.executeViewCart();But what's the cleanest way to actually do that locating of the class, instantiating it and then running the correct method? Reflection? Can anyone give an example of how relfection can be used? I've got this but it seems to to sporadically throw "MethodInvokationException" errors if the servlet container has not been used for a while, then it starts working again after the first rquest has erred.
My code so far... not too happy with it:
* Get an instance of the action controller for this request.
* @return ActionController
public ActionController getActionController() throws ActionNotFoundException {
if (actionController == null) {
try {
Class actionClass = Class.forName("org.w3style.controllers.actions." + getModuleName() + "Actions");
actionController = (ActionController) actionClass.newInstance();
} catch (Exception e) {
throw new ActionNotFoundException("Action controller class for " + getModuleName() + " cannot be found." + e);
return actionController;
* Run the requested action from the cotroller.
protected void doExecuteAction() throws ActionNotFoundException {
ActionController ac = getActionController();
try {
Class acClass = ac.getClass();
Class[] params = { };
Object[] args = { };
Method acMethod = acClass.getMethod("execute" + getActionName(), params);
acMethod.invoke(ac, args);
} catch (Exception e) {
throw new ActionNotFoundException("Action " + getActionName() + " cannot be found." + e);
}
Hmmm, I think my struggle to handle this indicated a design smell so I've refactored to something more modular. Now all "ActionController" classes extend an abstract so that their vital method signatures are already known. Now I have:
org.w3style.controller.actions.forum.CreatePostAction
public class CreatePostAction extends ActionController {
public void execute() {
}org.w3style.controller.actions.forum.DeleteThreadAction
public class DeleteThreadAction extends ActionController {
public void execute() {
}This works much better and it's still laid out well enough for components of the same module to be easily accessible. It's fixed my MethodInvocationTargetException too. I guess I can throw in validate() and handleError() methods now too :)
Similar Messages
-
What is the best way to call a pageflow action from JavaScript?
What is the best way to call a pageflow action from JavaScript?
Thanks,
JohnJohn,
How would I do this from a grid??? Unfortunately there are no JavaScript attributes
on any of the grid tags that I can see.
Thanks,
John
"John H" <[email protected]> wrote:
>
Thanks John!
"John Rohrlich" <[email protected]> wrote:
John,
If you want to put up a confirm dialog before calling an action from
an
anchor it is done as follows.
Here is an example from code of mine that deletes a customer order,if
the
user confirms the delete. I pass the order id as a parameter.
- john
Here is the JavaScript -
function confirmDelete() {
if(confirm('Continue with order delete?'))
return true;
else
return false;
Here is a sample anchor tag -
<netui:anchor action="requestToDeleteOrder" onClick="return
confirmDelete(); return false;">
Delete
<netui:parameter name="orderId" value="{container.item.orderId}"/>
</netui:anchor>
"John H" <[email protected]> wrote in message
news:402138f5$[email protected]..
Thanks for the replies. I figured it was going to require buildingmy own
url
to call the action. I had hoped there was an easier way to do it.Rich,
the
reason I want to do this is because I want to call the JavaScript
function
confirm()
when a user clicks on a link (in a repeater/grid) to drop a record,I only
want
to call the drop action if the user confirms the drop. Maybe thereis a
better
way to do what I am trying to do??? I really appreciate any help
you
guys
can
give me on this, I am pretty new to this sort of stuff.
Thanks,
John
"Rich Kucera" <[email protected]> wrote:
"John H" <[email protected]> wrote:
What is the best way to call a pageflow action from JavaScript?
Thanks,
JohnTry figuring out the URL to the pageflow action, create a hidden
form
in the
page, then use JS to submit the form. Why would you want to though,
isn't
the server going to want to send you to the next page? -
What is the best way to repeatedly load random commercials?
Hi Everyone,
Any help with the above question would be useful. Here's my end goal: I want to display commercials on a screen at my wife's bakery. The script should load one commercial, play it, then unload it, randomly load another, and so on.
I am completely new to as3 and have unsuccessfully been following several online tutorials. My first attempt had code in each commercial file (swf), that randomly called up another commercial, which in turn called up another file, and so on--but this became a memory hog and crashed the program after a few minutes.
Since then I have created one main swf file that loads an xml file, which holds all the information for the commercials. However, when the swf commercials are loaded according to the xml file, they don't play properly: when the first commercial finishes playing, the next one is already partially done. Obviously it started playing earlier. The swfs should unload and load the next according to a timer, with the length of the timer being different for each swf according to the xml data. Even with this, the first swf didn't always stop when it should. My code is getting complicated and the display looks sloppy.
I think something like this should be a simple way to display media such as these commercials, but I still haven't found a working solution. Now I'm wondering if I'm even approaching this wisely.
Would it be better to convert the swf to flv and create an flv player that has 'continuous play' and 'shuffle' features? Would it be better to convert each swf into movieclips and put them all into one swf? (I like the manageability of using an external xml file; I will be adding and removing commercials frequently and want to keep this as simple as possible.)
Please let me know what you think is the wisest approach and refer me to any relevant tutorials.
Peace,
TrevorThanks again kglad,
I followed your advice, but it is still not working properly. Here's my problem:
The external swfs continue playing in the background. Consequently, the event "playcomplete" was dispatched not only at the end of the swf that is being shown, but also at the end of the looping, previously loaded swfs that are not visible; this made the next swf play before the one being shown finished. That seemed easy enough to fix by adding stop(); to each external swf on the last frame. I thought everything was fixed -- but those swfs must still be there and are hogging memory before they can be collected for garbage. I've developed a loop that continues to load swfs, taking more and more memory, eventually causing a crash. So:
After a swf is loaded, how do I completely remove it to free up memory? I'll attach the code I'm using, but I've made some adjustments to your previous examples (using a string with a random number instead of an array, using different variable names, etc). Would I still have this memory problem if I used an array? I have tried to remove eventListeners, to use weak eventListeners, and to remove the loaded Child as best as I know how, but I need some guidance on memory management before I can use this.
Peace,
Trevor
var swfLoader:Loader = new Loader();
var klaesiSwfs:XMLList;
var totalSwfs:Number;
//var swfArray:Array = ["swfs/movie1.swf", "swfs/movie2.swf", "swfs/movie3.swf", "swfs/movie4.swf", "swfs/movie5.swf"];
//loads xml//
var klaesiXmlLoader:URLLoader = new URLLoader ();
klaesiXmlLoader.load(new URLRequest("xml/swf_depot.xml"));
klaesiXmlLoader.addEventListener(Event.COMPLETE, processXML, false, 0, true);
//finds how many swfs are on xml//
function processXML (e:Event):void{
var klaesiXml:XML = new XML(e.target.data);
klaesiSwfs=klaesiXml.ID;
totalSwfs=klaesiSwfs.length();
//trace ("Total is " + totalSwfs);
loadRandomSwf();
klaesiXmlLoader.removeEventListener(Event.COMPLETE, processXML)
klaesiXmlLoader = null;
//loads swfs//
function loadRandomSwf():void {
var num:Number = (Math.floor(Math.random() * totalSwfs) + 1);
var swfName:String = "swfs/movie"+ num +".swf";
var requestSwf:URLRequest = new URLRequest (swfName);
swfLoader.load(requestSwf);
addChild(swfLoader);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, playComplete, false, 0, true);
//listens for the end of each swf//
function playComplete(e:Event){
MovieClip(swfLoader.content).addEventListener("playNextCommercial", nextSwf, false, 0, true);
swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, playComplete)
//removes old swf, starts new swf//
function nextSwf(e:Event){
MovieClip(swfLoader.content).removeEventListener(Event.COMPLETE, nextSwf);
removeChild(swfLoader);
loadRandomSwf(); -
Hi,
I have a huge table and it will keep growing. I have a date column in this table and thought of partition the table by year and month. Can any you suggest better approach so that partition will create automatically for new data also along with the existing
data? Nothing but automatically/dynamically partition should create along with file group and partition files.
Thanks in advance!
Palash Also this one
http://weblogs.sqlteam.com/dang/archive/2008/08/30/Sliding-Window-Table-Partitioning.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Best way for HTTP load balancing in OSB
Hi everybody,
We have setup an OSB cluster and we need to load balance HTTP requests across managed servers. Looking for info about load balancing in OSB I found that there are mainly two options: using a hardware load balancer or a software solution like Weblogic HttpClusterServlet. At the moment we have no hardware balancer available so we will have to take the software option. I found some articles about configuring HttpClusterServlet like http://redstack.wordpress.com/2010/12/20/using-weblogic-as-a-load-balancer.
But I have a question about this configuration. If we use a managed server as an HTTP proxy that balances requests between OSB managed servers, what would happen if this server goes down? I think one of the main goals of a clustered deployment is avoiding a single point of failure but with that setup all requests would depend on the availability of the proxy managed server.
Could you recommend us a setup for implementing load balancing in OSB?
Thank you in advance,
Daniel.Load balancing in a cluster for http requests can be achieved using atleast 4 different ways:
(1)- use a hardware load balancer like F5 BigIP LTM
(2)- use a web server with weblogic plugin to frontend the cluster
(3)- use weblogic with HTTPClusterServlet
(4)- use DNS round robin - this works if you have managed servers running on 2 machines (say mach1, mach2) but on the same port. HTTP clients use hostname 'mach' to access the URL's and the dns does a round robin name resolution of mach to mach 1 and mach2 IP addresses..
All the options except (1) achieve only load balancing and not auto failover on all instances.. Hardware load balancers has the extra feature of probing [ sending periodic pings to the targets] , by which it can detect whether the target resource is alive and if not send the traffic to other nodes which are alive.. this is why hardware load balancers are worth their investment..
other options may work if client is coded to do retrying on failure.. so on 2nd or subsequent attempt, the routing is done to the machine which is alive..
For options (1),(2) and (3), you also need some redundancy of load balancing device ( web server, weblogic or hardware load balancer) to prevent single point of failure.. Hardware load balancers are usually deployed in redundant pairs to achieve this..
Edited by: atheek1 on 22/11/2011 15:31 -
What's the best way to coordinate loading multiple modules.
I have a number of resource modules that I'd like to load before loading my main UI module.
I'm doing this now, but to make sure that everything loaded OK, I need to have a chain of Event.COMPLETE callbacks for every resource module load.
In other (threaded) languages, I'd set a flag and run a wait on my main loop before loading the UI module.
Is there a good compact way to wait for n modules to load in Flex?I don't think you need a chain if load order doesn't matter. Just keep a
Dictionary of them and remove them from the Dictionary as they load. Then
run a quick test of the Dictionary has any items left. -
Best way to load components seperate from the main movie
When my flash movie loads, it takes a while to diaplay the
loading frame because it is too busy exporting the components on
the first frame. What is the best way of avoiding this, while still
being able to use the components through the .swf?
Thanks for any help,
~Oni.OniLink wrote:
> When my flash movie loads, it takes a while to diaplay
the loading frame
> because it is too busy exporting the components on the
first frame. What is the
> best way of avoiding this, while still being able to use
the components through
> the .swf?
>
> Thanks for any help,
> ~Oni.
>
loadMovie("component.swf", _container);
the best way is to load it externally but if you don't get
it, check out
www.gotoandlearn.com ...
they have the best tutorials basic and advanced. -
What Is the best way to up load and down load psd files from desktop photo shop to photo shop touch? For on the go touch up or. I'm using psd files at 90 percent 300 depi when in photo shop on desktop. To ps touch
Hi Bford225,
I'd recommend using your favorite web browser and going to https://creative.adobe.com/files for uploading from the computer.
Keep in mind tablet capabilities are much less than a computer, so large files might take a long time to download and be very system intensive to work on. Although you can import files up to 12 megapixels I'd recommend something more mid range, like 6 or 7 megapixels, ie 2880 x 2160 or 3072 x 2304.
Also, PSD files are flattened when imported into Photoshop Touch.
Hope that helps,
-Dave -
Hi
In my application I need to dynamically create objects of types specified by string which is passed as parameter. I am able to do this if the class is inside the same jar. But I need to load the class from any jar name specified. How do i go about doing this? Is there a way to dynamically loading jar files?It's easy. You use [url http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html]URLClassLoader:String jarPath = ...;
String className = ...;
URLClassLoader ucl = new URLClassLoader(new URL[] { new File(jarPath).toURL() });
Class cls = Class.forName(className, true, ucl);
...Regards -
Best way to load "Action Essentials"
Kinda new with using Macs....need to know the BEST way to load Action Essentials?
well I was really over-thinking it! ha
Thanks so much Rick!
On Fri, Sep 12, 2014 at 12:24 PM, Rick Gerard <[email protected]> -
What is the best way to delete dynamically-generated symbols from another symbol?
in the onClick handler for 1 symbol, I have:
var sandwhichQty1 = sym.createChildSymbol("sandQty1", "Stage");
another symbol inside sandQty1 has the onClick method:
this.deleteSymbol();
which works fine, deleting sandQty1. I'd like to delete it, and others, from another button, in the circumstance where users don't close them this way.
I notice that id and class are dynamically assigned to the child symbol, which makes it hard for me.
any ideas?Hi, I did it in this way, and functions well; maybe this is not the best way, but worked for me. Obviously this code is based on the elainafineell's correct solution.
This is my scenario:
In a Trigger @ xxxxms there is that:
var i = 1;
$.each(results, function(index, element)
var s = sym.createChildSymbol("mySymbol", "someContainer");
// some code here
// Creating the variable that save my new instance of mySymbol
sym.setVariable("var_id"+i, s);
i++;
// a global var, take care with the name
numOfInstances = i;
Then, in a click action of some button, symbol, anything that support an action, I code this:
sym.eraseSymInstance();
And, in the creationComplete, I code the function like this:
sym.eraseSymInstance = function()
for(var i = 1; i <= numOfInstances; i++)
var s = sym.getVariable("var_id"+i);
s.deleteSymbol();
For me function well.
I hope this can be usefull for somebody else. -
Best way for using Property Loader with Excel
I am trying to architect a test system to run a variety of tests (DIO, AIO, PWM...etc) and I noticed that Property Loader can be quite handy. I am trying to find the best method to utilize NI TestStand Property Loader to load test properties from Excel into some sort of parameter database. The properties shall be loaded only once when the test sequence is opened. The parameters of the excel table will have a format like this:
TestType TestCondition ECUPin# Limits.High Limits.Low Units PWM_Frequency CAN_TX CAN_RX
DI ON 1 0x0102 0x0304
AI OFF 2 0 0.1 V 0x1324 0x0405
The table will look much more complex than this one, but once I know how to do this I should be fine. Does anyone have suggestions for what I am trying to do ?
Thanks,
AymanThere are a couple methods of thought here:
Property Loader- You can use the tool to export and import properties. The best way to do it is to export the properties that you want in the Excel file using the tool. Then make copies of the file and change the values in there. This will ensure that once the values come back into TestStand they will all go to the correct place.
FileGlobals Method- You can create a large container which has all the correct variables in it in your file globals or locals. There is an object in the TS API called a PropertyObjectFile. This file is a simple text file that contains the properties, sub properties and values of any property object in TS. You can easily just pass the container into it. The problem with this is that you then have to create a VI or some tool to edit the values in it. You can go in there and manually change them but it's not as intuitive.
Property Loader to FileGlobal Container- This would basically be a hybrid of the two. Pretty much what you described in your post. Where the property loader only has to load the container in your FileGlobals.
Which method is best? It all depends on your application. If you ever need to dynamically export the properties then you can't use the Property Loader.
One thing to remember is that you should only Import/Export properties that need to be changed in the Excel file. This will help reduce the number of properties.
Hope this helps,
jigg
CTA, CLA
teststandhelp.com
~Will work for kudos and/or BBQ~ -
Best way to Unit Test Controller Layer
Hi, I was hoping to get the opinion on this matter. My group is currently discussing which method would be the best to Unit test the Controller Layer (using StrutsTestCase). Basically with StrutsTestCase, you can test your Action methods and verify that the action forwards to the correct place, or that certain errors come up. The problem is that these Action classes will make Model layer calls that affect the DB. Whats the best way to test the Action classes? Some possibilities are:
#1) Make a mock model layer that instead of hitting the DB uses a "switch" statement to return the correct value.
#2) Use a test DB to test this. The problem with this is that after running tests, you want to leave the test DB in the same state as when you started the test. This is not very easy to do if your web application only does inserts to the DB. In addition, the Model layer Unit testing will be designed such that it will insert, select, update, select, and delete (in that order), so the state of the DB will remain the same after the test is run (unless JUnit crashes halfway).
#3) Use a copy of a test DB on your local computer. This is beneficial because you can do anything to the DB, and then just delete it because a "master" copy is located elsewhere. The problem with this is, we also hoped to do performance testing of the model layer by running multiple threads of the Model layer unit tests. This won't work now because each thread would make a copy of the master DB....
Thanks for any suggestions you might have!
-LI have never unit tested just a controller. I have always done end to end testing with the systems I have worked on, so I am coming from a different viewpoint than yourself. I would tend to think that just running a full unit test all the way to your database would be the best test. You will be more likely to find the issues with your program if you are testing with an environment as similar to production as possible.
After running a test you can either purge the data you entered from your test by having sql scripts run against the db, or if this is difficult just reload the database from its original backup. You would probably be able to purge the data quicker than reloading the database from my experience, but it depends on your complexity of the sql scripts.
best of luck. -
What is the best way to kill/stop a data load?
Hi.
What is the best way to kill/stop a data load?
I have a data load from my QA R/3 system that is extracting 115.000.000+ records. The problem is that the selection in the function module used in the data source does not work, and the problem was not detected because of the nature of the data on the development system.
I could kill processes owned by my background user (on both R/3 and BW) but I risk killing other loads, and sometimes the job seems to restart if I just try to kill processes. If I remove transactional RFCs in SM58 the load does not terminate; I only skip one or more datapackages. I have also tried to change the QM-status in the monitor to red, but that does not stop the load either...
So isn't there a nice fool-proof way of stopping a dataload?
Best regards,
Christian FrierHi,
There r 2 ways to kill the job.
One is using transation RSMO locate the job and display the status tab double click on the yellow light that is shown on the line total, a pop will come 'set overall status ' is displayed select the desired status that is red and save it. Then return to the monitor page and select the header tab double ckick on the data target right click and then goto 'manage',there should be request sitting there probably with yellow lights , highlight the line with the faulty request click the delete button then click refresh button.
Second is goto SM37 and click on the active selection and enter the jobname and then click excute the particulr job should appear highlight the jobname then click on the stop iconthat appears on the taskbar( 3 rd from left)
hope it is clear.
Regards-
Siddhu -
What's the best way to load balance multiple protocols on one vserver?
Hi,
We have a CSM blade on a 6513, in bridge mode. I'm just wondering what is the best way to serve HTTP and HTTPS (or any two or more ports) from the same group of servers. As I see it, we have two options:
1. Don't set a port on the vserver, so it is load balancing "any" or "tcp". This is easy but I want to be sure there isn't a downside to this, other than the obvious security issue.
2. Create multiple vservers and point them at the same serverfarm. I tried this and I got some odd results with the health checks.
Any ideas? Thanks a lot.you listed the only 2 options available.
The advantage of solution #2 is that you can apply specific config for each protocol ie: for HTTP you can turn 'persistent rebalance' if needed.
If you want to use specific probes [not icmp], it is also a good practice to create a different serverfarm for each protocol.
Like this, if the HTTP service goes down but not the server, you can still have other protocols loadbalanced.
Regards,
Gilles.
Thanks for rating this answer.
Maybe you are looking for
-
Need Help Cloning Old Windows XP to Mac with VMWare Fusion
Hello I'm new to the forums and I have been searching all over for a good answer on how to do this. I have a ton of applications, docs, etc. on my old windows xp machine that I need and I am looking for a way to clone the drive it to my mac that is u
-
How to move all info from original user identity to new user identity
I bought a new printer and had some problems. In the process of 'fixing' the problems with the help of HP tech support I have since lost the ability to print from my original printer. I have found that I can print from a new user identity to both pri
-
PS CS5 version 12.0 x32 extended for MAC stopped detecting GPU
Up until very recently my Photoshop CS5 was working perfectly. I was able to rotate images and canvas using the Rotate View Tool. I am not quite sure when did it exactly stop working, but I know I used it last time about a month ago. I have installed
-
Which table the dynamic selection view will be stored
Dear Freinds, I have created a dynamic selections view form Se80 > Editobject>Selection view > Created by adding the required tables pa0002,pa006,pa0009 . But the transport request we have saved it locally now i want to create a tr
-
Photos not available for downloading to word. Photo booth comes up instead
I downloaded an update to my iMac today and now I can's access my photos for Word. Photo Booth comes up instead.