Using static Delegates within Struts' Action classes

HI,
I have a struts app. I also have several delegate classes that connect to ejbs (session beans) used within my action classes. I was thinking about putting the delegates into a helper class as static properties. That way my action classes can just reference the same delegate. I don't want to have to create a new instance of a delegate with every request an action class handles.
However, I'm wondering if this will cause synchronization issues with multiple requests being handle, as our site handles a heavy load of requests. Any suggestions would be appreciated?

static will work - but IMO here's a better option
1. Have multiple delegates (one per module - one for login, another for business process1, another for business process2)
Advantages : Cleaner segregation, easier maintenance and readability.
2. Maintain the business delegates as individual classes and access them through instance variables from action.
Advantages : All the advantages of inheritance, one business process may be the child of another - for example you can have a BasePaymentDelegate and then a specific CreditCardPaymentDelegate extending it. Similarly a PaypalDelegate may also extend BasePaymentDelegate and then common functionality can be moved to the Base class.
3. Cache the delegate instance variables in your action - so you dont have to create one per invocation. Having said that, all the business delegate methods should be stateless - all the data to a business method should be passed as local params.
Advantages : Local variables are thread safe as long as the object itself are thread safe. So no synchronization issues.
Hope that helps some
Ram.

Similar Messages

  • Can we call the pure java variable into the struts action class?

    Hi Everybody,
    I have created the binary tree data structure in java,Could I use the value of the variable called value in the struts action class?,pls help me thro ur reply.I have attached the java code here.Thanks in Advance
    package com.recipes.wizard.common;
    public class BinaryTreeTest {
      public static void main(String[] args) {
        new BinaryTreeTest().run();
      static class Node {
        Node left;
        Node right;
        int value;
        public Node(int value) {
          this.value = value;
      public void run() {
        Node root = new Node(5);
        System.out.println("Binary Tree Example");
        System.out.println("Building tree with root value " + root.value);
        insert(root, 1);
        insert(root, 8);
        insert(root, 6);
        insert(root, 3);
        insert(root, 9);
      public void insert(Node node, int value) {
        if (value < node.value) {
          if (node.left != null) {
            insert(node.left, value);
          } else {
            System.out.println("  Inserted " + *value* + " to left of "
                + node.value);
            node.left = new Node(value);
        else if (value > node.value) {
          if (node.right != null) {
            insert(node.right, value);
          } else {
            System.out.println("  Inserted " + *value* + " to right of "
                + node.value);
            node.right = new Node(value);
          if(node.value==1)
               System.out.println("The value is one");
             int output=node.value;
               System.out.println(output);
    }

    Hi,
    You can change the filter with the new cost element variable,Or you can assign the value of the new variable(if of same type)to old cost element ,but for that assignment again u have to change  planning function which you don't want.
    Regards,
    Indu

  • Is it possible to use a Script within an action? - it doesn't seem to work...

    Is it possible to use a Script within an action? - it doesn't seem to work...
    I'm using the 'round any corner' script from SATO Hiroyuki..., and  I'd like to apply it to only one anchor point (on multiple boxes)

    An Action can call a script from the File>Scripts menu by means of the Add Menu Item Action step. But it will only work for the duration of your Illustrator work session. If you quit AI and then restart it, the Add Menu Item step will be blank. This bug has been reported for FOUR FULL VERSIONS of this sloppy program.
    However, if I am correctly understanding your description of what you are trying to automate, an Action will not be able to automate the selection of a particular anchorpoint in multiple paths. You'd have to make the selections all at first. Whether the script would then apply as desired to each path depends on how the script is written.
    JET

  • Values from JSP to Struts Action Class

    Dear All,
    Am working on a small struts project, i want to get values from JSP in the Action class, i tried with sending variables using request through URL, it works fine, any other way is there to send the values from JSP to action class. Am not having any input fields in the JSP.I have links.
    Thanks,
    vyrav.

    I have a dispatch action for that am calling the action like this viewfiles.do?parameter=edit, and i have to send a variable ID from the same page, so am doing like this through java script, viewfiles.do?parameter=edit&id=10. Am able to get the id in the dispatch action edit, but when i start tomcat with security manager its not calling the action itself and its giving accesscontrol exception, but when i directly type viewfiles.do in URL its calling the action.
    I dont know wats the problem, tomcat security manager not allowing this. Please help me.
    Thanks,
    vyrav.

  • How to log exception from a struts action class

    Hi guys,
    I am recoding my application to use the strut framework. There's one small thing i wonder is that how i can log an exception arrise in an action class. In my original servlet, wherever an exception arise, i use:
    catch(Exception e)
             getServletContext().log("User enter an invalid date");
             throw e;
          }However, when i move this servlet into a action class, the getServletContext method doesnt work anymore. I thought action is a child of httpServlet but since getServletContext is not available in action, then how can i log the error?
    Hope to get some help
    Message was edited by:
    lnthai2002

    Hi guys,
    I am recoding my application to use the strut
    framework. There's one small thing i wonder is that
    how i can log an exception arrise in an action class.
    In my original servlet, wherever an exception arise,
    i use:
    catch(Exception e)
    getServletContext().log("User enter an invalid
    valid date");
             throw e;
          }However, when i move this servlet into a action
    class, the getServletContext method doesnt work
    anymore. I thought action is a child of httpServlet
    but since getServletContext is not available in
    action, then how can i log the error?
    Hope to get some help
    Message was edited by:
    lnthai2002Action class is just a POJO and works a handler of your request. ActionServlet invoke your Action class based on the action you call in your URL. When you are usign the Struts why do you need your Original Servel, use the ActionServlet and if required you can extend it and create your own servlet

  • OrdHttpUploadFormData.parseFormData() failed within Struts2 action class

    I got the example servlet PhotoAlbumServlet.java works just fine. So the setup should be good. However, when I need to get upload photo work with Struts2, I got error:
    [5/24/11 17:08:30:189 PDT] 00000020 webapp E com.ibm.ws.webcontainer.webapp.WebApp logError SRVE0293E: [Servlet Error]-[IMW-00005: end-of-stream; client terminated request (or invalid Content-Length)]: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: IMW-00005: end-of-stream&#59; client terminated request &#40;or invalid Content-Length&#41;
    at parseFormData();
    The the request form is fine, since I use same request form and changed the action to point to the demo servlet and it works. So I copy the worked servlet code into my action class and debuged into the code. It failed at parseFormData();
    Here is my action class code:
    public String execute() throws Exception {
    OrdHttpUploadFormData formData = new OrdHttpUploadFormData( request );
    if ( !formData.isUploadRequest() )
         System.out.println("Not upload request!!");
    return INPUT;
    formData.parseFormData();  // <= this step failed.
    So, I guess that struts2 may alternated request object which make the parse failed.
    Has Anyone used ORD work with Struts successfully before? Or if possible that I can get source code of this OrdHttpUploadFormData so that I can debug into it and see what's going on?
    Is there any other alternation or work around for this?
    Thanks in advance for any tips.
    Regards,
    Joe

    By add try - catch block to the parseFormData:
    try {
         formData.parseFormData();
    } catch (Exception e) {
         e.printStackTrace();
    I got:
    [5/25/11 8:28:20:489 PDT] 00000024 SystemErr R oracle.ord.im.OrdHttpUploadException: IMW-00005: end-of-stream; client terminated request (or invalid Content-Length)
    [5/25/11 8:28:20:505 PDT] 00000024 SystemErr R      at oracle.ord.im.OrdMultipartInputStream.read(OrdMultipartInputStream.java:92)
    [5/25/11 8:28:20:505 PDT] 00000024 SystemErr R      at oracle.ord.im.OrdMultipartReader.readLine(OrdMultipartReader.java:152)
    [5/25/11 8:28:20:505 PDT] 00000024 SystemErr R      at oracle.ord.im.OrdMultipartReader.readCheckDelimiter(OrdMultipartReader.java:132)
    ...

  • Using a brush within an action

    I'm trying to find a way to incorporate a brush into my action without actually having to stop and using the brush and then continue. More specifically, I would like to apply the art history to the entire image as a step within an action, but I want it to automatically be applied without me having to actually brush it.
    Is there a way to do this?

    What about using snapshots, and copy/paste, instead of the history brush?
    Or, you could use a path that crosses the canvas and stroke it with a very large history brush. To apply a path to an action use the action flyout menu "insert path".
    I'd probably just copy/paste and arrange layers, avoiding the history panel altogether.

  • Struts action classes not reloaded in WLS 8.1 SP5

    Hi,
              We are in the process of upgrading from WLS6.1 to WLS8.1(SP5). I installed WLS8.1 in development mode with no change to any of the default settings and got our app up and running. However, one issue that I noticed was that WLS8.1 is not reloading new classes copied int WEB-INF/classes directory within the webapp.
              I read the document at http://edocs.bea.com/wls/docs81/webapp/deployment.html#157139 and it clearly says that any changes to classes are automatically picked up.
              I have verified that "servlet-reload-check-secs" is set to 1. Is there any configuration item that I am missing here ?
              Thanks in advance,
              Prasad

    Hi,
              I am deploying my application on bea weblogic 8.1SP5........and it showing errors below::::while iit's working fine on sp4........
              JVMDG217: Dump Handler is Processing OutOfMemory - Please Wait.
              JVMDG315: JVM Requesting Heap dump file
              .........JVMDG318: Heap dump file written to /soft_dump/BEA815/user_projects/dom
              ains/mydomain/heapdump274442.1150373114.phd
              JVMDG303: JVM Requesting Java core file
              JVMDG304: Java core file written to /soft_dump/BEA815/user_projects/domains/mydo
              main/javacore274442.1150373147.txt
              JVMDG274: Dump Handler has Processed OutOfMemory.
              Is dere any solution for it?
              Thanks
              Samit Katiyar
              [email protected]

  • How to send a String value  from Servlet to  Action class in Struts .

    when iam trying to send string value from Servlet to Struts Action class through Http Session, iam getting null value, iam really in big confusion, help me.

    please elaborate clearly or put you code of both action and servlet here
    Are both of them in same web application

  • Pass html data to struts action

    There is a user registration page where in a login-name is required. I have a "Check if loginame is available" link (Typical web-sites have such facility).
    Now,for this scenario i am still not submitting the form and only need to pass the login-name text value to the appropriate (Struts) action class where further business logic is implemented and return a status whether its available or not.
    How do i go about passing the value of the jsp page to Java.
    Regards,
    Gyan

    ragh_dr wrote:
    So, you have two separate Action classes for login and check login name? What you could do is call a javascript method on clicking the link (onclick="javascript:checkLoginName();"). In this method, get the value of the user entered login name and pass it to your check login Action either as a query string (document.forms[0].action="/CheckLoginName.do?loginId=userentered") and submit the form. You can get the value of loginId from the request object in your Action class. You could also set the target of the form as new or something document.forms[0].target="_new", so that the check results are shown in a new window if required.Why would you abuse JS for this and not just let the Login class delegate/call the CheckLogin class?
    About that JS, although this is not a Javascript forum and I normally don't go in detail with JS here, but I would say that using document.forms[0] is a terribly bad practice. Why should your code expect that the form you're looking for is always the first form element of the document? Just use document.formname or document.getElementById() or if you're smart, the 'this' reference.

  • Passing values from a JSP to Action class

    Hi,
    I have one JSP in this I have two select boxes.
    The first select box is populated with default values.
    From the first select box I am selecting the value and moving to the other select box using java script.
    Now the value in the second select box has to be submitted alongwith some other values which I am getting.
    These values are to be submitted to a Action class and further to the form bean using struts.
    In the form tag in JSP I am calling the struts action class.
    The issue here is,I am able to get other values except the values in the second select box.
    I am using simple JSP page to get form values and submitting.
    I am not using struts tlds because of project constraints.
    Please advise on how to pass these values.
    Regards,
    Ram

    If the value from the select box isn't submitted, then it's not inside the form. Check the HTML output of your JSP to debug this problem.

  • Struts controller classes and ADF in JDeveloper 10.1.3 EA

    I've noticed that ADF Struts has changed quite a bit from JDev 10.1.2. In the previous version of ADF Struts, the default data action class was oracle.adf.controller.struts.actions.DataForwardAction. In version 2 of ADF Struts, the default action class is oracle.adf.controller.v2.lifecycle.PageController. When overiding a lifecycle method in the DataForwardAction class, the method was always passed a DataActionContext object. The DataActionContext class had a method called getHttpServletRequest() so I could get a handle on the request object. On the other hand, the PageController lifecycle methods use the LifecycleContext object and I have yet to find a way to get access to the request object. Does anyone know of a way to get a handle on the Http request object? I've looked at the javadocs for the new Struts action classes but have found nothing that would help.
    I also noticed that the DataForwardAction class (package = oracle.adf.controller.v2.struts.actions) has been changed in version 2 of ADF Struts and only a few methods remain. So I would assume that this class will no longer be used the same way it was in the past. Is this a safe assumption?

    The task of customizing the PageLifecycle or handling events are now delegated to the PageController. These tasks were previously done in a subclass of the DataForwardAction. The DataForwardAction is now only responsible of bootstrapping the PageLifecycle.
    </br></br>
    In 10.1.2, reference to the model BindingContainer was done using a <set-property> for each DataAction. This is now done in the DataBindings.cpx file using a mapping between the path and the BindingContainer. This new mechanism is identical for Struts or Faces. Same with the PageController which is in 10.1.3 the common place to extend the behavior of the PageLifecycle or a ControlBinding for Struts and Faces.

  • How to call a method of an Action class from JSP on load?

    Hi guys
    Due to bad design pattern, i am forced to do something which i have not tried before.
    I need to call a method of a struts action class which invalidated the user session FROM the JSP itself on load. Which means it would not require user input.
    We have a subclass of a DispatchAction that handles all the incoming .dos.
    So http://blarblarblar:7001/blar/blar/doSomething.do?method=logout will dispatch to an Action class called DoSomething, into a method called logout().
    So when the webapp throws an exception, the ActionMapping actually displays an error.jsp and i have to invalidate the user at this stage.
    I can't change the most top level code in the base action class so i got to do it this way.
    Any help is much appreciated.
    Thanks.

    hi :-) DispatchAction is quite cool ;-)
    dont get much of your question but hope
    the suggestion below could help.
    A. use redirect?
    or
    B. autosubmit the form
    1. create your form in a jsp
       <html:form action="/doSomething" />
         <html:hidden name="method" value="logout" />
       </html:form>2. auto submit the form with method = logout
    put the function autosubmit in the "onLoad" event of the body
       <script>
         function autosubmit(){
         var form = document.yourformname;
         form.submit();
       <script>regards,

  • JMaki and Struts Action

    Hello,
    I'm tempted to use jMaki dojo.dropdowndatepicker in my struts1 application, but dont know how to pass selected value from calendar picker to my struts action class?
    I dont need any source code, just need something to put me in the right direction ;)
    Thanks in advance.

    I am trying the same thing, but haven't found success. I have added listener in glue.js and try to retrieve via http listener. No success yet

  • XML: Using static & placeholder text inside element with children?

    Hi there
    I’m working with simple XML data with the following structure:
    Root
         Row
              Company_name
              Physical_address
              Phone
              Website
              Email_address
         Row
              Company_name
              Physical_address
              Phone
              Website
              Email_address
    etc.
    The row element will be repeated many times. In setting up my InDesign document I’d like to use static text within each Row element. What’s confusing me is where I should use the Row tag. I’d like my imported XML data to run as continuous text, thus:
    Company: placeholder text
    Address: placeholder text
    placeholder text
    placeholder text
    placeholder text
    Company: placeholder text
    Address: placeholder text
    placeholder text
    placeholder text
    placeholder text
    I tried setting it up like this, with the parent text frame given the Root tag:
    <Row>Company: <Company_name>placeholder text</Company_name>
    Address: <Physical_address>placeholder text</Physical_address>
    <Phone>placeholder text</Phone>
    <Website>placeholder text</Website>
    <Email_address>placeholder text</Email_address></Row>
    …but when I import my XML file I lose all my static text and each child element is indented more than its parent element. I would guess that by placing my static text within the Row tag it gets replaced when each Row element is imported, but where else would I place it? Do I have to create anchored text frames (tagged with Row) within the Root frame to hold each Row element?
    I’d appreciate any insights.
    Message was edited by: Graham vdR

    OK, I’ve figured out the first problem. I just needed to play around with the options in the dialogue that comes up when importing XML. Specifically, the “Do not import contents of whitespace-only elements” needs to be checked. I still don’t see why that should affect whether or not my static text stays in place.
    Now, my new question is this: It looks like all the child elements of a container element have to appear in the document in the same order in which they appear in the XML file. Is this right? If I swap my Email_address and Website tags around in my placeholder text, either the email address disappears or it appears at the end (depending on the options I select in the dialogue upon import). So if I want to change the order in which they appear I have to do so in the XML file as well?

Maybe you are looking for