I forgot to add the line of code in the edit method that inserts into form
bean.

Also, I should have assumed that you are going to re-use the sectionEdit...

sectionEdit_execute()
{
        int id = form.getId();

        if(id==0)
        {
                try{
                        Integer idInt =
(Integer)request.getAttribute("my.NewId");
                        id =    idInt.intValue();
                }catch(Exception e){
                        //do whatEver
                }
        }

        if(id==0){ return mapping.findForward("cantEditBadId"); }

        form.setId(id);

        return mapping.findForward("displayEdit");
}







-----Original Message-----
From: Bailey, Shane C. [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 07, 2003 5:30 PM
To: 'Struts Users Mailing List'
Subject: RE: method to get new Id to next action when old Id is in request?



I guess you could do this:

sectionInsert_execute()
{
        insert into DB
        int id = someHowGetTheNewId();

        request.setAttribute("my.NewId", new Integer(id));
        return mapping.findForward("success");
}


sectionEdit_execute()
{
        int newId = 0;
        try{
                newId =
((Integer)request.getAttribute("my.NewId")).intValue();
        }catch(Exception e){
                //do whatEver
        }

        return mapping.findForward("displayEdit");
}


-----Original Message-----
From: Adam Hardy [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 07, 2003 5:26 PM
To: Struts Users Mailing List
Subject: method to get new Id to next action when old Id is in request?

I have two actions chained together. They both take the same formbean. 
The first is sectionInsert.do and the second, which sectionInsert 
forwards to on success, is sectionEdit.do

sectionInsert.do receives the properties of a Section in the request 
parameters, including id=0 where it is 0 because it does not exist in 
the DB yet. So it inserts the new Section into the DB and returns the 
new id, which is needed by sectionEdit to put into the html for the edit 
page.

I originally thought I could save the new id to the formbean and this 
would get passed on, but sectionEdit instantiates its own formbean and 
fills it with the request parameters - include id=0.

Is there an intuitive way of passing on the new id?

I already use sectionEdit.do as a first action by calling it with an id 
on a querystring, where the formbean picks it up. I would like to use a 
method that is easy for both these situations.

I'd appreciate any inspiration.
Adam


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to