The first Action-Mapping in order to set-up the MemberAddressForm was defined as:
<action path="/address_update"
type="com.tjh.csaa.beans.MemberAddressAction"
name="MemberAddressForm"
scope="request"
validate="false">
<forward name="choice" path="/membership/membership_choice.jsp"/>
<forward name="success" path="/membership/membership_address.jsp" />
</action>
There is another Action-Mapping that is for when the form is actually submitted. It is defined as:
<action path="/membership_address" type="com.tjh.csaa.beans.MemberAction" name="memberAddressForm" scope="request" input="/membership/membership_address.jsp" validate="true"> <forward name="choice" path="/membership/membership_choice.jsp"/> <forward name="failure" path="/membership/membership_address.jsp"/> <forward name="success" path="/membership/membership_updated.jsp"/> </action>
SOOOOOOOOOOO, the solution is the "name" name="memberAddressForm" name="MemberAddressForm"
The correct one is the first one because that matches the form-bean definition. Problem solved.
Why do my toughest problems have the simplest solution? That question was rhetorical. Thanks for all the help and being so patient with me.
Thanks again.
Tom
Tom Holmes Jr. wrote:
I've done a lot more research on this issue and the I found the web-site: http://husted.com/struts/catalog.html
which proved to be an invaluable aid in the best practices of how to create a Struts-based wab-application.
I also found this site which seemed to give me all the answers I needed or so I thought: http://www.reumann.net/struts/lesson2/step9.do
So, I have a link from a JSP menu that looks like: http://www.mydomain.net/update_address.do
The struts-config.xml has the following declared:
In the form-bean definitions I have:
<form-bean name="memberAddressForm" type="com.tjh.csaa.beans.MemberAddressForm"/>
In the Action Mappings I have: <action path="/address_update" type="com.tjh.csaa.beans.MemberAddressAction" name="MemberAddressForm" scope="request" validate="false"> <forward name="choice" path="/membership/membership_choice.jsp"/> <forward name="success" path="/membership/membership_address.jsp" /> </action>
So, the idea is like the example, that is I call the Action (MemberAddressAction) which is going to get my "member" (MemberDTO) from the session (because the user has previously logged-in) and the MemberDTO is now in session. So, MemberAddressAction gets this "member" and uses the "populate" method I wrote to transfer the data from this "member" into the Form-Bean (MemberAddressForm).
Here is some of the code from the MemberAddressAction:
HttpSession session = request.getSession(); MemberDTO member = (MemberDTO)session.getAttribute("member"); if( member == null) { System.out.println("user has not signed in"); return (mapping.findForward("choice")); } else { MemberAddressForm memberForm = (MemberAddressForm)form; copyBeanToForm(member,memberForm); } return (mapping.findForward("success"));
I can vouch for sure that the "member" (MemberDTO) does exist in session correctly ... however, the form does not get created and as a result is null. So, question is WHY?
Why does this code not work and how can I correct it? MemberAddressForm memberForm = (MemberAddressForm) form;
Thanks again for any help.
Tom
Tom Holmes Jr. wrote:
Thanks for the info.
"membership_address.do" is the Action from the JSP page when I do my submit. If I call the this Action with validate=true, then it's going to call the FormBean Validate method first, and if anything is required, then it would get errors and return to the calling page with a bunch of error codes even though the user wasn't there the first time. I've seen other people ask that question before.
The Action you suggest I call, is this a new Action altogether with no validation? This action could either get data from the database, or if that is already done, then I could just take the data from the MemberDTO and put that into the formbean as you suggest, then I would automatically forward to the Membership_Address.jsp page. Is that correct, or do you mean go to the same Action as when I do a submit.
So, I won't be a bother to the list, can you re-direct me to the struts-example web-app? Can I download that app from the Struts web-site directly?
Thanks again for the help.
Tom
Wendy Smoak wrote:
From: "Tom Holmes Jr." <[EMAIL PROTECTED]>
So, the way I started to handle this is call the JSP page directly with the form. I got the 'member' object from session and I populated the value field as follows: <html:text property="address1" value="${member.address1}"/> Would this be appropriate? It works except for my checkboxes.
No. Set those values in the Action code, before forwarding to the JSP.
The struts-example webapp shows how to do this-- look for the calls to
BeanUtils.copyProperties(...) that copy the values back and forth from the
DTO to the form bean.
Don't forget to write a reset method to handle those checkboxes.
--------------------------------------------------------------------- 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]