Results 1 to 4 of 4

Thread: Spring.Web.Process / Controller forgets values

  1. #1

    Default Spring.Web.Process / Controller forgets values

    Hello,

    I have a simple webform where the user can administrate departments. The user can add, delete and edit departments. When he chooses to add or edit he get's to see a popup dialog (inside the same page) where he can enter the new data.

    I have written a class DepartmentController which has a property Department and methods to load and save the department. My problem is, that spring seems to forget about the controller and creates it new everytime I access the page. So that I cannot save a modified department.

    How can I tell spring to use everytime the same controller (in the user's specific session of course). Have I got to deal with processes?

    And I would like to ask anybody here to explain me what exactly a process is and what it's for and how to use it... I haven't found anything in the documentation yet ;-)

    Thanks a lot! Regards,
    Dominik

  2. #2
    Join Date
    Nov 2005
    Location
    Fairfield, CT
    Posts
    21

    Default

    Hi Dominik,

    Aleks goes over the basics of his Process implementation toward the end of this post - http://forum.springframework.net/vie...?t=392&start=0.

    Basically, a process is a user workflow (registration, checkout, etc.). Session is encapsulated within the process. The process also is responsible for moving a user from view to view.

    To use it, there are a few steps to follow... Below is a sample registration process...

    1. web.config process definition

    Code:
    <object id="registration" type="Spring.Web.Process.AnthemProcess, Spring.Web.Anthem" singleton="false">
            <property name="Controller" ref="registrationController" />
            <property name="DefaultView" value="RegistrationForm" />
            <property name="Views">
              <dictionary>
                <entry key="registrationConfirmation" value="RegistrationConfirmation" />
              </dictionary>
            </property>
          </object>
    2. web config controller definition

    Code:
    <object id="registrationController" type="zblock.Registration.RegistrationController" singleton="false">
             
             <property name="Member" ref="member" />
          </object>
    3. web.config definitions for model objects

    Code:
    <object id="member" type="zblock.Membership.Member, zblock">
      </object>
    4. web.config view definitions

    Code:
    <object type="RegistrationForm.aspx" parent="standardPage">
          </object>
    
          <object type="RegistrationConfirmation.aspx" parent="standardPage">
          </object>
    The important thing, as Aleks mentions in his post, is to browse to Registration.aspx... You should then see the view you defined under the DefaultView property of the process...

    Your controller methods should return strings that get passed into the SetView method of a Page's Process to determine which view to display next...

    Code:
    Process.SetView&#40;Controller.RegisterMember&#40;&#41;&#41;;
    In the above example, RegisterMember would return the string "registrationConfirmation" on a successful registration. Note that this is the key to the confirmation form view defined in the registration process...

    Finally, the Anthem process works well out of the box, but if you wanted to use your own, you need only implement the two abstract methods of AbstractProcess

    Code:
    public class AnotherProcess &#58; AbstractProcess
        &#123;
            protected override void NavigateToCurrentView&#40;&#41;
            &#123;
                HttpContext.Current.Response.Redirect&#40;this.ProcessUrl + "?" + ProcessIdParamName + "=" + this.Id&#41;;
            &#125;
    
            protected override void NavigateToStartView&#40;&#41;
            &#123;
                HttpContext.Current.Response.Redirect&#40;this.ProcessUrl + "?" + ProcessIdParamName + "=" + this.Id&#41;;
            &#125;
        &#125;
    Hope that helps (and is accurate!)...

    -- John

  3. #3

    Default

    Dear John,

    thank you for the detailled overview! It's great to know what a process is. But it doesn't help me for the small part of my project I am just working on...

    I have only one page and the user may edit/create/delete rows in one table. So I do not need that many views and therefore I don't want to use processes here, though I already know where I can use them perfectly ;-) Or I should make this administrationpage differently - but that's not what I want to do.

    So could you also explain me how to tell spring to memorize the current controller state? I was planning to do it like that:

    1. User opens Departments.aspx and sees a list (GridView) of Departments.
    2. User clicks edit. I load the selected Department to Controller.Department like that:

    Code:
    Controller.Department = DepartmentDAO.GetById&#40;Selected ID from gridview&#41;;
    Then I open my popupdialog (same aspx-page).
    3. User clicks cancel/edit:

    Here I would like to say:
    Controller.SaveDepartment(); or
    Controller.Cancel();

    But the Controller doesn't know anymore about the selected Department.

    How to fix that? Do you also know that? :-)

    Regards,
    Dominik

  4. #4

    Default

    Hi there,

    I inserted the logic to memorize the Controller state during a session into my base page class like that:

    Code:
    public class BasePage &#58; Spring.Web.UI.Page
    &#123;
        private bool _DeleteForeignControllers = true;
    
        public bool DeleteForeignControllers
        &#123;
            get &#123; return _DeleteForeignControllers; &#125;
            set &#123; _DeleteForeignControllers = value; &#125;
        &#125;
    
        protected override void OnPreInit&#40;EventArgs e&#41;
        &#123;
            IDictionary controllers = &#40;IDictionary&#41;Session&#91;"SpringControllers"&#93;;
            if &#40;controllers != null&#41;
            &#123;
                if &#40;controllers&#91;this.TemplateControl.AppRelativeVirtualPath&#93; != null&#41;
                    Controller = controllers&#91;this.TemplateControl.AppRelativeVirtualPath&#93;;
            &#125;
            if &#40;DeleteForeignControllers&#41;
                Session.Remove&#40;"SpringControllers"&#41;;
        &#125;
    
        protected override void OnPreRenderComplete&#40;EventArgs e&#41;
        &#123;
            IDictionary controllers = &#40;IDictionary&#41;Session&#91;"SpringControllers"&#93;;
            if &#40;controllers == null&#41;
                controllers = new Hashtable&#40;&#41;;
            controllers&#91;this.TemplateControl.AppRelativeVirtualPath&#93; = Controller;
            Session.Add&#40;"SpringControllers", controllers&#41;;
    
            base.OnPreRenderComplete&#40;e&#41;;
        &#125;
    &#125;
    Perhaps this helps some of you, too ;-)

    Regards,
    Dominik

Similar Threads

  1. Possibility to delete DataBindings
    By sir-archimedes in forum Web
    Replies: 7
    Last Post: 05-06-2006, 07:33 AM
  2. Front Controller vs Page Controller
    By jross in forum Web
    Replies: 1
    Last Post: 02-19-2006, 08:18 AM
  3. Unit tests (lack of), SpringAir, and aspx controller
    By scottnelsonsmith in forum Web
    Replies: 2
    Last Post: 12-16-2005, 04:08 PM
  4. Replies: 3
    Last Post: 09-08-2005, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •