Struts...strange behaviour

Discussions

Web tier: servlets, JSP, Web frameworks: Struts...strange behaviour

  1. Struts...strange behaviour (5 messages)

    i have a main index page with a form for a user to log in AND a seperate link to "register" with the system.

    the form for the user to login is mapped to LogonAction using a respective LogonForm.

    the link to register with the system SHOULD direct the user to a page with a new form to fill out with all their registration info.

    my problem is that when a person clicks the "register" link (associated with saveRegistrationAction and a RegistrationForm) it creates a blank RegistrationForm and attempts to populate it with data from the logon form on the main index page.

    the link for saveRegistrationAction is NOT inside of the <form>..</form> declaration for the logon form.

    shouldn't it create a new RegistrationForm and send it directly to saveRegistrationAction since the link mapped to this action is not enclosed inside of a <form> element???

    thank you in advance..im bewildered

    Threaded Messages (5)

  2. Struts...strange behaviour[ Go to top ]

    Sounds like a mixup in struts-config. Can you post struts-config.xml?

    Are you sure you have the correct type and name like:
    <action path="/registration" type="saveRegistrationAction" name="registrationForm" input="/reg/register.jsp">

    Make sure your form-bean is properly mapped to RegistrationForm also.

    I don't believe the <form></form> code has anything to do with it since a link isn't a trigger to submit a form.
  3. hmmm[ Go to top ]

    I am really convinced that pressing a link that points to the /saveRegistration action will immediately generate a RegistrationForm and try to populate it with fields from any <form> element on the same page as the link that was just pressed.

    basically i have a logon form with a submit button that does the /logon action
    then a link outside of the <form> element that points to /saveRegistration (which should display a new page with a registration form and a save button again mapped to /saveRegistration)

    <action
    path="/saveRegistration"
    type="capcare.web.patientInterface.SaveRegistrationAction"
    name="RegistrationForm"
    input="/registration.jsp"
    validate="true"
    scope="request">
    <forward name="cancel" path="/logon.jsp"/>
    <forward name="success" path="/mainMenu.jsp"/>
    </action>

    <action
    path="/logon"
    type="capcare.web.patientInterface.LogonAction"
    name="LogonForm"
    validate="true"
    input="/logon.jsp"
    scope="request">
    <forward name="success" path="/mainMenu.jsp"/>
    </action>
  4. hmmm[ Go to top ]

    <form-bean name="RegistrationForm" type="capcare.web.patientInterface.RegistrationForm"/>

    <form-bean name="LogonForm" type="capcare.web.patientInterface.LogonForm"/>
  5. ohh[ Go to top ]

    Ohh, I understand now. You should only use use /saveRegistration as a form action. For the Register link you want to setup something like this in your struts-config.xml:
    <action path="/register" forward="/pages/register.jsp"/>
    Then use /register for your register link instead.

    /saveRegistration is just a form handler so it creates a RegistrationForm and tries to populate it with POST vars, but there are none because you clicked it via a link.
  6. gotcha[ Go to top ]

    yeah i was using at the time what i considered a 'temporary fix' by introducing an intermediary action called /displayRegistrationPage similar to what u described. ok...now im glad i know how to properly design this. thanks