Struts DispatchAction and Formbeans

I'm writing a webapp that involves administering a bunch of computers from a table like interface.
I have an Action class "ManageActions" extending DispatchAction, and offers 3 methods: view, edit, and update.
The view method calls up a view JSP which displays a table in which rows represent computers, and columns represent attributes such as disk size, and other stuff.
In this table, each cell is hyperlinked to /Manage?method=edit&columnToEdit=something&idToEdit=something
So the edit() method of ManageActions will take the parameters "columnToEdit" (which attribute) and "idToEdit" (which machine), put the appropriate Machine bean in the request, and forward to a JSP such as editSomeAttribute.jsp or editSomeOtherAttribute.jsp (different JSPs because some attributes are numbers, some are times, some are lists of strings, etc).
So the thing is, each one of these edit JSPs is a form, and needs a formbean. But because they are just mappings from a single DispatchAction method (ManageActions.edit), I don't really know how to declare the appropriate formbeans in the <action> mapping in struts-config.
Does anyone know how I might do this?
        <action
            path="/Manage"
            type="com.wizzysoft.configservice.confapp.actions.ManageActions"
            <!-- want to declare multiple form beans here, but not sure how -->
            parameter="method"
            scope="request">
            <!-- want form bean for each of these -->
            <forward name="editSomething"    path="/jsp/editSomethingjsp" />
            <forward name="editSomethingElse" path="/jsp/editSomethingElse.jsp" />
        </action>

http://frustratedprogrammer.blogspot.com/2004/07/struts-121-mappingdispatchaction.html

Similar Messages

  • DispatchAction and formbeans

    I'm writing a webapp that involves administering a bunch of computers from a table like interface.
    I have an Action class "ManageActions" extending DispatchAction, and offers 3 methods: view, edit, and update.
    The view method calls up a view JSP which displays a table in which rows represent computers, and columns represent attributes such as disk size, and other stuff.
    In this table, each cell is hyperlinked to /Manage?method=edit&columnToEdit=something&idToEdit=something
    So the edit() method of ManageActions will take the parameters "columnToEdit" (which attribute) and "idToEdit" (which machine), put the appropriate Machine bean in the request, and forward to a JSP such as editSomeAttribute.jsp or editSomeOtherAttribute.jsp (different JSPs because some attributes are numbers, some are times, some are lists of strings, etc).
    So the thing is, each one of these edit JSPs is a form, and needs a formbean. But because they are just mappings from a single DispatchAction method (ManageActions.edit), I don't really know how to declare the appropriate formbeans in the <action> mapping in struts-config.
    Does anyone know how I might do this?
            <action
                path="/Manage"
                type="com.wizzysoft.configservice.confapp.actions.ManageActions"
                <!-- want to declare multiple form beans here, but not sure how -->
                parameter="method"
                scope="request">
                <!-- want form bean for each of these -->
                <forward name="editSomething"    path="/jsp/editSomethingjsp" />
                <forward name="editSomethingElse" path="/jsp/editSomethingElse.jsp" />
            </action>

    http://frustratedprogrammer.blogspot.com/2004/07/struts-121-mappingdispatchaction.html

  • How is the processing speed while using struts,spring,and JSF framework

    Hi friends,
    As per earlier technology like Servlets,I mean that there would have much more performance speed than other new technologies like JSP,struts,spring and hibernate framework.Because,in new technologies,flow of processings implicitly via MVC2 basis will probably much more time than older one.
    Total goal is only for attaining MVC2 or any other purpose?
    Please clarify my doubt?
    With Regards,
    Stalin.G

    Home grown applications have a problem in that as more and more features are added, it becomes increasingly impossible to maintain the application and enhance it. This is especially true when the original programmers leave the company. A framework provides a standard design approach that other programmers can hopefully more easily pick up.
    A lot of work has gone into creating these frameworks and they have been used in web sites that have millions of hits from users per day. They have high preformance. Of course, programmers can still write bad code in them that slows down the system. I believe anyone using these frameworks should study them well before using them (such as reading books on them).

  • COMMIT problem in TopLink, Struts, JSP and ADF Databinding sample

    In the sample Developing a J2EE Application using TopLink, Struts, JSP and ADF Databinding,
    I followed all the steps to build a department browse page and a edit page.
    But when I get to Step number 23 in "Create a JSP to Edit Departments" I have a problem with the commit.
    Only after I make a change in the form and click the sumbit button, the commit and rollback buttons become active. And After I click the commit button the data gets commited to the database but the page inofmation changes to the very first department record, not the current one.
    How do I make those buttons active with out the extra click on the submit?
    After I click the commit button, how do I keep the current data on the screen?
    Thanks for you help.

    Shay,
    Thanks for the reply.
    For #1, I was able to do the following and get away with not having to press submit first. I just removed the bindings for disable. I hope that does not cause any problems?
    <input type="submit" name="event_Commit" value="Commit" />
    <input type="submit" name="event_Rollback" value="Rollback" />
    For #2, How I add an action on an HTML button? My UIModel.xml for the edit department page currently has two actions on it. Commit and RollBack. Is it linked through the "name" attribute of the input tag?

  • Struts Actions and events in one jsp?!

    Hello,
    I have a problem with Struts actions and events in a jsp.
    It is a search page and when the user clicks the search button I trigger an event and when the user clicks on a link in the result table (same page) I use an action that opens a new detail jsp. The first search query works well, I get a result, open the detail page, go back (using an action).
    Then I start a new search, but struts tries to open the detail page. While debugging I found out, that struts apparantly has no action or event. Why does it work at first time?
    Any ideas?
    Thanks in advance
    Britta

    Thanks for answer,
    I work with actions AND events. I think that`s the problem. When I go back from detail page to search page I use a custom DataForwardAction class with the following method:
    public void onCancel(DataActionContext ctx)
    DCBindingContainer bc = ctx.getBindingContainer();
    HttpServletRequest request = ctx.getHttpServletRequest();
    WebUtils.setSession(request);
    String ziel = request.getParameter("ziel");
    JUCtrlActionBinding action = (JUCtrlActionBinding) bc.findCtrlBinding("Rollback");
    action.doIt();
    try
    ctx.setActionForward(ziel);
    catch (Exception e)
    ctx.setActionForward("liste_freig");
    Ziel has the correct value ("search") and I think the struts config is also correct:
    <action path="/material" type="view.actions.materialAction" className="oracle.adf.controller.struts.actions.DataActionMapping" parameter="/material.jsp" name="DataForm">
    <set-property property="modelReference" value="generalUIModel"/>
    <forward name="liste_freig" path="/liste_freig.do"/>
    <forward name="liste_angelegt" path="/liste_angelegt.do"/>
    <forward name="list_bewertet" path="/list_bewertet.do"/>
    <forward name="liste_abgelehnt" path="/liste_abgelehnt.do"/>
    <forward name="liste_onhold" path="/liste_onhold.do"/>
    <forward name="search" path="/search.do?action=search"/>
    </action>
    But when I get back from material page to search page (the first time it works). The location pathname is material.do not search.do When start a new search the material page opens, not, as desired, the search page with new results.
    Search Action:
    public class searchAction extends DataForwardAction
    public searchAction()
    protected void prepareModel(DataActionContext ctx) throws Exception
    HttpServletRequest request = ctx.getHttpServletRequest();
    DataActionMapping acmap = ctx.getActionMapping();
    DCBindingContainer bc = ctx.getBindingContainer();
    WebUtils.setSession(request);
    JUCtrlActionBinding action = (JUCtrlActionBinding) bc.findCtrlBinding("delSearchQuery");
    action.doIt();
    String sEvent=null;
    try
    sEvent=request.getParameter("event");
    catch (Exception e)
    sEvent=null;
    if (sEvent==null)
    if (request.getParameter("action") != null)
    if (request.getParameter("action").equals("material"))
    Number mat_no=new Number(request.getParameter("MaterialNumber"));
    Number userId=new Number(WebUtils.getUserId(request));
    bc = ctx.getBindingContainer();
    action = (JUCtrlActionBinding) bc.findCtrlBinding("prepareMaterial");
    ArrayList arrayList= new ArrayList();
    arrayList.add(0,mat_no);
    arrayList.add(1,userId);
    action.setParams(arrayList);
    action.doIt();
    ctx.setActionForward("material");
    if (request.getParameter("action").equals("material_datasheet"))
    ctx.setActionForward("material_datasheet");
    super.prepareModel(ctx);
    public void onSearch(DataActionContext ctx)
    DCBindingContainer bc = ctx.getBindingContainer();
    HttpServletRequest request = ctx.getHttpServletRequest();
    WebUtils.setSession(request);
    ctx.setActionForward("search");
    Struts config:
    <action path="/search" className="oracle.adf.controller.struts.actions.DataActionMapping" type="view.actions.searchAction" name="DataForm" parameter="/search.jsp">
    <set-property property="modelReference" value="searchUIModel"/>
    <forward name="search" path="/search.do?action=search"/>
    <forward name="material" path="/material.do?action=material"/>
    <forward name="material_datasheet" path="/material_datasheet.do?action=material_datasheet"/>
    </action>
    I think it`s a Struts bug. Or is there something I don`t see?

  • Integrating Struts, Tiles, and JavaServer Faces

    I have tried some sample applications in jsf. They are working properly. Basically, our application is based on struts. We fee that that it will be difficult to convert struts based application into jsf. So we plan to integrate jsf components into struts application. I found a site http://www.ibm.com/developerworks/library/j-integrate/ where jsf-struts integration material has been given. For this integaration, struts-faces.jar is required. when i try to start the server after struts-faces-1.3.8.jar placed in Tomcat 5.5\common\lib folder, server is not started properly. I have found struts-faces-1.3.8.jar in struts-1.3.8-lib. Should I user struts-faces.jar? if it is so, Where to find struts-faces.jar Please provide a solution for this problem.

    Wow, Srikanth. What a great contribution! I'm right at the begining of the design phase of a project that will hopefully go live in March and while I had already settled on a Tiles/Struts approach, I was really wanting to bring in JSF as well. I'm glad to see that someone is actively working on the integration components. I hope that the code modifications you propose make it into the Struts-Faces libraries soon.
    One question. While I've been deveolping J2EE webapps for a couple of years now,
    I'm still a little new to the Struts/Tiles arena. After reading your article at IBM developerWorks I wasn't able to ascertain whether or not what you proposed worked with the idea of individual controllers for each tile, which is a pattern that my project will need to adopt (I read about it in the short article here - http://www.theserverside.com/resources/article.jsp?l=Tiles101).
    Can you shed some light on the subject? Will the modifications you proposed allow Tiles to continue to work in that fashion?
    -Matt Welch
    Hi,
    Currently JSF, Struts and Tiles cannot work together
    out of the box.
    Craig McClanahan has come up with Struts-Faces which
    lets you integrate Struts and JSF. This is ideal for
    projects who want to protect their code investment in
    Struts and also want to take advantage of JSF once it
    is final.
    Unfortunately if you are also using Tiles, this is not
    possible because of some showstoppers on your way. I
    started on this venture a while back and ran into the
    same problems and decided to write some code - on top
    of Struts-Faces and was pretty successful.
    I am sharing this knowledge with the rest of you with
    this article of mine on IBM developerWorks
    http://www-106.ibm.com/developerworks/library/j-integra
    e/
    As already pointed out in this forum earlier, this
    article covers the steps to integrate the three and
    provides complete source code and also a working
    example.
    Hope you will find the article and the code useful.
    Thanks,
    Srikanth

  • Struts Diagram and CVS Problems

    We're having a difficult time with the StrutsPageFlow.oxd_struts and CVS. Anytime a developer makes a change to the Struts diagram and commits the struts-config.xml file, the StrutsPageFlow.oxd_struts file also gets committed. When a different developer updates the struts-config.xml file the StrutsPageFlow.oxd_struts file has a conflict on just about every item. We're also encountering this on our *.jpr and bc4j.xcfg files.
    JDeveloper 10g is stealing a lot of our time as we're having to manually work around a lot of CVS conflicts on files that are not shown in the project but associated with project files like the struts-config.
    Anyone else having CVS issues with these "behind-the-scene" files?

    Hi Jason,
    Unfortunately, this is a known issue. The only workaround we can suggest for struts at the moment is using an exclusive editing mode. Whenever a developer needs to modify the struts diagram, he should issue a cvs edit. Other developers should use the "List Editors" functionality in JDev to check whether someone is currently editing the file.
    We're working on resolving these team development issues in the 10.1.3 release.
    Thanks,
    Brian

  • A problem with struts -  DispatchAction class

    Hi,
    I am facing a problem with DispatchAction class in struts 1.1.
    Here is my senario:
    I have a two classes that extend DispatchAction - classA and classB.
    In classA, I have a start method. In classB, I have two methods - display and submit.
    When my application starts, my index.jsp does a logic:forward to the struts-config.xml file.
    e.g.:
    index.jsp<logic:forward name="startApp"/>
    struts-config.xml<form-beans>
         <form-bean name="testFormBean" type="package.testFormBean">
         </form-bean>
    </form-beans>
    <global-forwards>
         <forward name="startApp" path="/startApp.do?method=start"/>
    </global-forwards>
    <action-mappings>
         <action name="testFormBean"
    path="/startApp"
    parameter="method"
    validate="false"
    scope="request"
    type="package.StartAppActions">
         <forward name="successOneUser" path="/runSearch.do?method=display"/>
         </action>
         <action name="testBean"
    path="/runSearch"
    parameter="method"
    validate="false"
    scope="request"
    type="package.SearchActions">
                   <forward name="success" path="/html/jsps/success.jsp"/>
         </action>
    </action-mappings>
    when my application starts, the control goes to the index.jsp and then because of the logic forward goes to the start method of the /startApp action(i.e. the StartAppActions class). I return a ActionForward element with the value of "successOneUser".
    Uptill this point everything works fine.
    But now it should go the /runSearch element (i.e. SearchActions class) and the display method of it. But it is not going there. The error I am getting is action[runSearch] does not have a method named "start".
    I checked the value for the method parameter using the RAD/WSAD debugger, the value of parameter is "method" is still "start".
    I do not understand why it is not overiding the value of parameter "method" with display even though I am doing a
    <forward name="successOneUser" path="/runSearch.do?method=display"/> in the /startApp element, which should send the control to the display method of the [runSearch] element (i.e. in the startActions class).
    Can anyone tell me what the problem is ?
    Thanks in advance.
    kaushal

    Try this:
    Runtime.getRuntime().exec("your_batch_file.bat");
    where your_batch_file is:
    SET CLASSPATH=....(place all needed classes here)
    javac.exe filename
    must work,but there is some limitation...
    you must think to solve this problems.
    i hope that will help,
    Marius

  • For struts - fwd the formbean in multiple JSP-action-JSPs

    Hello All,
    I know this is EJB forum but just I had one Qn so posting.
    I know you all must be doing struts as you are doing EJbs.
    I have following things and I want to HIT the DB only at last JSP
    submit click. How do I keep the formbeans ?
    READ EVERYTHING CAREFULLY ---------
    I can use session but, I want request or some similar way, or
    if there is any thing struts way,
    if all is not possible then I will go for session.
    Please don't tell me any request or action chaining because
    that is not something the case here and as it is highly discouraged
    I am NOT going to use that. its not that case anyways,
    JSP 1 - has a formbean 1
    - submit - goes to Action1
    ACTION1 - get the formBean1 ( I get the values1 here hahahaha)
    do any processing on formBean1 if needed
    set the formbean1 in request ( i am doing this )
    mapping.findfwd("success") - to JSP 2
    JSP2 - <%get the formbean1 from request and SOP it
    (I get the values1 here hahaha) %>
    has its own field and formBean2
    submit - goes to Action2
    ACTION2 - get the formBean2 (I get the values2 haha)
    get the formBean1 (I get NULL ?????)
    Point is I want to set the formBean1 from request
    orginating from JSP2 -submit. JSP2-formBean2 gets submitted there
    properly but how can keep fwding formBean1.
    Please don't tell me to keep ALLL formBean1 values as hidden
    in JSP2. as its not good logic and its tooo much values. etc. etc.
    As a matter of fact I have 4 such JSPs and if user selectes codes
    on page 4 then only send all earlier 3 formBeans + current formBean4
    to DB, else ignore all ( means just ignore, go to new jsp or main menu
    let all formBeans garbage collected... hahahaha )
    How can I do this ?
    I will reply to any Qn s immly as I am in hurry....delivery is very very near
    guys ..........:)
    anyways,
    Enjoy the coding.....!!!
    Sandeep

    Off hand, the only thing I can think of is to create two completely separate projects.
    However, if you want to maintain a good development team and project, I suggest you keep it as one project and not try to hide anything from one group of developers. Instead, install CVS as your repository. It will track what changes were made and by who and you can roll back to a previous version of a JSP or java class if necessary. Your team should be briefed on the architecture you decide on (Spring, Sturts, etc), and basic good coding practices you want enforced.
    Here are a few rules:
    * nothing is to be checked into CVS that doesn't compile cleanly.
    * nothing is to be checked into CVS that has any error or warning messages form your IDE outstanding.
    * nothing is checked into CVS without the comment field of the commit dialog box being filled in.
    * You have one build.xml file that eveyone uses to compile all code.
    * All JSP pages are to be well formed xml (no dangling tags).
    * all java classes and JSP pages are to be properly indented.
    * all classes are to have javadoc describing what a class is for, and all functions are to have javadoc describing what the function does (not how it does it).

  • Struts ActionForm and Model Objects design

    I've managed to make a pretty nice model with persistence managed by hibernate logic encapsulated in DAO's.
    But now Ive reached the web layer and I'm with struts, and I'm kind of stuck so I would love to hear some suggestions.
    How should I create ActionForms without duplicating the model state in ActionForm classes?
    Right now, my model implements ActionForm, which is tight coupling .
    But this increases maintenability.
    Other suggestions?

    It is a very bad idea to have your model implement ActionForm, for the reason you mentioned -- tight coupling. When you do that, you are tied to a web application; and, more specifically, Struts. "Best practice" says you need to duplicate a bit of your model in your ActionForm (Jakarta Commons BeanUtils makes this painless). As you probably know, the ActionForm should correspond to the form being displayed in the browser; each HTML form element should have a corresponding property in your ActionForm class. These properties might come from various parts of your domain model, so this gives you a place to muster them all together. I use an initXXXAction to populate the ActionForm, if needed, before display and a completeXXXAction to process the users input after they submit (although I'm thinking about switching to one of the DispatchAction flavors). Also, if the idea of maintaining the ActomForm classes is a hang-up, I'd suggest looking into the DynaXXX classes.
    Just to re-iterate, having your model implement ActionForm is BAD.

  • Problem with html:select or html:options tags using struts,jsp and tomcat

    Hi
    I'm updating a Struts-Project to a new layout and therefore rework all jsp Sites.
    I'm also using a new Folder-Structure and update therefore my struts-config file.
    My Problem now is:
    Till now, we had a select-field with a code like this:
    < html:form action="/timetableAction" method="POST">
    < table width="53%" border="0">
    < tr>
    < td>< html:radio property="dauer" value="semester"
    /></ td>
    < html:select property="semester" size="1">
    < htmlptions name="semesterList" />
    </ html:select>
    </ html:form>
    The problem now is, that whenever I use any <html:xy> tag, the tomcat server I use can not show the page, he shows just the headers of the template, but not the
    content.-jsp-File where the form would be in. He stops right in the middle of the html page, when he notices the <html:xy> tags.
    And the funny thing is, that he has no problem to show a page when there is a <html:errors> within it? Why could this be? the struts-html.tld File is well included and teh Tomcat Server shows no exceptions.
    Waiting for you answers and thanks

    Thank you, I already got the answer in another forum

  • JSF and Struts - differences and integration goal.

    I am a newbie J2EE developer and I am not clear about main differences between JSF and Struts also I saw couple of articles describing integration between JSF and Struts. Could someone give me an explanation, what the main conceptual differences between those technologies and what's the goal of integration both of them?

    I describe the main differences between JSF and Struts in this sample Chapter from my JSF book:
    http://www.oreilly.com/catalog/jsvrfaces/chapter/ch01.pdf
    Hope that helps.

  • Struts: passing a formbean from action to action

    Hi,
    I need to share the same bean between actions, not only by declaring it in all of them (already done, some validated, some not), but also if in action 1 i populate the bean (it's an insertion page), i want to pass it on to action 2 (who must display it).
    How is that done in Struts?
    Right now i put the populated bean into the session as an attribute after action 1, then i call the next action but even if the jsp associated with action has an html:form declaration and should look for the bean in the session, it doesn't.
    It correctly pulls out the bean declared, but the values inserted in page1 are not there.
    Can you help me? Please ask for any additional info..

    I'm sorry I think I got it solved.. I can fill the bean with data from a form and retrieve the same bean from the next action, as long as it's in the request or in the session scope in both (same scope both actions).

  • Struts actionform and checkboxes

    hi!
    I'm having trouble creating an actionform for a jsp that i have. Basically, my jsp lists files which have their corresponding checkboxes. The user can click multiple checkbox representing the files he wants to download. On clicking the download button, it submits it to my DownloadAction.
    My problem is that only the first checkbox is stored in my actionform.
    here's my actionform:
    package mybeans;
    import org.apache.struts.action.ActionForm;
    import java.util.*;
    public class FilesForm extends ActionForm
        Vector files = new Vector();
        String file = null;
        public String getFile() {
             System.out.println( "getting file" );
             return file;
        public void setFile( String string ) {  
             System.out.println( "setting file" );      
             file += string + ",";
             files.add( string );
        public Vector getFiles() {
             return files;
    }my jsp is a bit big. here's the form part:
    <html:form action="/download">
      <table>
        <tr>
          <td><input type="checkbox" name="file" value="someDynamicID"></td>
          <td>filename</td>
        </tr>
      ...more files here...
      </table>
    </html:form>Thanks in advance!

    Make your setter take a String[] argument and your getter return a String[] argument (I think List or Set might also work).

  • Add Image to Jasper Report with Struts 2 and Hibernate

    Hi I want to add image to jasper report[pdf] in the environment of Struts 2 framework and hibernate. I am trying
    this for last couple of days, but i am unable to get the work done. if any body know the steps to add image to
    jasper reports, please help me or if u have any tutorials please let me know. I am using iReport-nb-3.5.0 to generate jasper files.
    Thanks in advance

    Finally i found a way to add image to jasper report. It is pretty simple, just give the exact image location to the image expression. In your web application, the image location may vary so, dynamically set the image location from your model class. Also, make sure that your lib folder contains itext-1.3.1.jar. If your lib folder contains itext-1.3.1.jar and iText-2.1.3.jar u will get like: java.lang.NoSuchMethodError: com.lowagie.text.Image.plainWidth()F
    So remove the iText-2.1.3.jar and keep only itext-1.3.1.jar, try this will work

Maybe you are looking for