Re: Struts starter
strikethis is strike-through formatting/strike On 8 Mar 2004, at 05:36, Martin Gainty wrote: I'll ask the dumb question What is Strike-thru formatting? ~Martin~ - Original Message - From: Joe Germuska [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 6:12 PM Subject: Re: Struts starter At 9:14 PM + 3/7/04, Frank Burns wrote: Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! Frank: Don't blame yourself: you've stumbled onto one of my personal top priorities to improve in Struts: prefilling forms with non-request data. While I was writing this, John McGrath described a general strategy which works *if* you don't already need to use the single ActionForm that is passed to Action.execute for processing *input* data. However, in most cases, you have a chain of events where you have different input and output forms. We've developed a few strategies for ealing with this where I work, but they're all the sort of thing which may not be ready for prime time -- that is, officially adding to the Struts core. Right now, Struts doesn't provide a particularly convenient way to get an instance of what we call the output form -- the form which will be in the view to which control is directed. Since 1.2.0, I've committed a few changes which make it a little easier for you to get Form Bean instances, but what is still missing right now is a proposal for a standard place to configure Struts to know which form bean you want. Practically speaking, you can get an Object of the right class from a static method of RequestUtils with no more than a FormBeanConfig and the ActionServlet. You can get a FormBeanConfig from a ModuleConfig instance, which you can get using ModuleUtils. So inside any Action, you can bootstrap yourself to having a Form bean object, which you can populate however you need. http://jakarta.apache.org/struts/api/org/apache/struts/util/ RequestUtils.htm l#createActionForm(org.apache.struts.config.FormBeanConfig,%20org.apach e.str uts.action.ActionServlet) http://jakarta.apache.org/struts/api/org/apache/struts/config/ ModuleConfig.h tml#findFormBeanConfig(java.lang.String) http://jakarta.apache.org/struts/api/org/apache/struts/util/ ModuleUtils.html #getModuleConfig(javax.servlet.http.HttpServletRequest) One possible flaw with this (as it is now) is that it doesn't honor the scope parameter and search the request or session for possibly existing bean instances. Of course, that code is available inside non-public methods of RequestUtils; it's just a matter of choosing the right way of exposing them publicly. The sticky parts, in terms of packing this up so that it's easy for everyone to use in Struts is configuring the form bean name and scope in the right place -- where in the struts-config.xml (or in some other file) would you tell Struts the name (and scope) of the bean you want? At work, we're using the struts-chain ComposableRequestProcessor with a request chain command PagePrep, which looks up config information and choreographs finding a form bean and making it available to a piece of Java code which might know how to populate it. But Struts is still a good bit away from officially switching to the ComposableRequestProcessor, and our config information is part of a general UIToolkit which is not currently a part of Struts in any way. The general strategy we use would fit decently well into a Tiles Controller, except that a Tiles Controller doesn't have access to the running Servlet, and if you use ValidatorForms, your FormBean must have access to the Servlet object. There's been some talk about trying to apply the general controller pattern to all Struts forwards, and in some ways, that's what we do with our PagePrep strategy, but it's been a while since anyone suggested a specific approach, and I don't think I've ever seen any actual code to do it. I'd be open to community discussions about how to integrate some behavior like this into Struts before we get there, but I must admit that since I have a solution where I need it, I'll need some external motivation to work on a solution that fits into the current RequestProcessing model. This was discussed at great length last Spring (that long ago?!) http://marc.theaimsgroup.com/?l=struts-devm=105415755227385w=2 but nothing ever congealed the point where code was cut for the core Struts distribution. Joe -- Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time
Re: Struts starter
At 11:36 PM -0500 3/7/04, Martin Gainty wrote: I'll ask the dumb question What is Strike-thru formatting? As noted, strike-thru formatting is just a text decoration that draws the text with a line through it. Regarding the wiki, the idea was to preserve the removed text for a while so that people wouldn't be confused by the change. Then again, that wiki entry is so old that its confusing anyway! Joe ~Martin~ - Original Message - From: Joe Germuska [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 6:12 PM Subject: Re: Struts starter At 9:14 PM + 3/7/04, Frank Burns wrote: Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! Frank: Don't blame yourself: you've stumbled onto one of my personal top priorities to improve in Struts: prefilling forms with non-request data. While I was writing this, John McGrath described a general strategy which works *if* you don't already need to use the single ActionForm that is passed to Action.execute for processing *input* data. However, in most cases, you have a chain of events where you have different input and output forms. We've developed a few strategies for ealing with this where I work, but they're all the sort of thing which may not be ready for prime time -- that is, officially adding to the Struts core. Right now, Struts doesn't provide a particularly convenient way to get an instance of what we call the output form -- the form which will be in the view to which control is directed. Since 1.2.0, I've committed a few changes which make it a little easier for you to get Form Bean instances, but what is still missing right now is a proposal for a standard place to configure Struts to know which form bean you want. Practically speaking, you can get an Object of the right class from a static method of RequestUtils with no more than a FormBeanConfig and the ActionServlet. You can get a FormBeanConfig from a ModuleConfig instance, which you can get using ModuleUtils. So inside any Action, you can bootstrap yourself to having a Form bean object, which you can populate however you need. http://jakarta.apache.org/struts/api/org/apache/struts/util/RequestUtils.htm l#createActionForm(org.apache.struts.config.FormBeanConfig,%20org.apache.str uts.action.ActionServlet) http://jakarta.apache.org/struts/api/org/apache/struts/config/ModuleConfig.h tml#findFormBeanConfig(java.lang.String) http://jakarta.apache.org/struts/api/org/apache/struts/util/ModuleUtils.html #getModuleConfig(javax.servlet.http.HttpServletRequest) One possible flaw with this (as it is now) is that it doesn't honor the scope parameter and search the request or session for possibly existing bean instances. Of course, that code is available inside non-public methods of RequestUtils; it's just a matter of choosing the right way of exposing them publicly. The sticky parts, in terms of packing this up so that it's easy for everyone to use in Struts is configuring the form bean name and scope in the right place -- where in the struts-config.xml (or in some other file) would you tell Struts the name (and scope) of the bean you want? At work, we're using the struts-chain ComposableRequestProcessor with a request chain command PagePrep, which looks up config information and choreographs finding a form bean and making it available to a piece of Java code which might know how to populate it. But Struts is still a good bit away from officially switching to the ComposableRequestProcessor, and our config information is part of a general UIToolkit which is not currently a part of Struts in any way. The general strategy we use would fit decently well into a Tiles Controller, except that a Tiles Controller doesn't have access to the running Servlet, and if you use ValidatorForms, your FormBean must have access to the Servlet object. There's been some talk about trying to apply the general controller pattern to all Struts forwards, and in some ways, that's what we do with our PagePrep strategy, but it's been a while since anyone suggested a specific approach, and I don't think I've ever seen any actual code to do it. I'd be open to community discussions about how to integrate some behavior like this into Struts before we get there, but I must admit that since I have a solution where I need it, I'll need some external motivation to work on a solution that fits into the current RequestProcessing model. This was discussed at great length last Spring (that long ago?!) http
RE: Struts starter
on the first hit to you personForm.do, or whatever (i presume you're not hitting the jsp directly at any point), the backing Action class should get the values from the validUser bean and populate the PersonDetailsForm bean, which then gets used by the jsp. it sounds like maybe you're using the values in the validUser bean directly with the struts html:form... tags. i think what you have like this: html:text name=validUser... maybe should be this: html:text name=PersonDetailsForm... so the validUser bean is used by the Action classes, and the PersonDetailsForm bean by the jsp, and logic in the Action classes dictates when and how data is transfered between the two. validation failure just redisplays the form (which should display what the user just tried to enter, not the original data from validUser). validation success might call another action that updated validUser with the new info from PersonDetailsForm. at least i think so, if i understand you correctly. works like that in similar situations here. -Original Message- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 9:06 PM To: Struts Users Mailing List Subject: Re: Struts starter John, This is very good ... Please bear with me for a final bit of clarification. I neglected to explain that I had already created what you call the PopulatePersonAction in your example and also set up the struts-config as you suggested. I have the equivalent of this: form-beans form-bean name=personalDetailsForm type=com.foo.PersonalDetailsForm / /form-beans action path=/PersonForm type=com.foo.PopulatePersonAction name=personalDetailsForm scope=request validate=true input=/pages/PersonalDetails.jsp forward name=success path=/pages/TheNextPageToCall.jsp / /action Note that the value assigned to the input parameter is /pages/PersonalDetails.jsp. In my PersonalDetails.jsp the action in the html:form tag is PopulatePersonAction. When I initially call PersonalDetails.jsp, there is already a validUser bean in the session scope, representing the current, logged-in user. On first being displayed, I want the fields of PersonalDetails.jsp to be populated with data from the validUser bean. Say I have an emailAddress field that I populate, like this: html:text name=validUser property=emailAddress size=20 /. Let's say the user enters some invalid data into the email address field and then clicks the submit button. The controller calls the personalDetailsForm and executes its validate() method, which fails. Because of the failure, the controller then calls PersonalDetails.jsp -- because it is the value in the input parameter for the /PersonForm action defined in struts-config. The newly called PersonalDetails.jsp now has access to the PersonalDetailsForm form bean containing the data entered by the user. HOWEVER, HOW WILL THE NEWLY CALLED PersonalDetails.jsp POPULATE THE emailAddress FIELD WITH THE VALUE THAT THE USER ENTERED? Won't it just re-display the value from the validUser bean? Because that's how it's defined in the page, i.e., html:text name=validUser property=emailAddress size=20 /. Thanks, Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 10:19 PM Subject: RE: Struts starter i'm a relative newcomer myself, but i think the part you're missing is an Action class. Put an entry in struts-config something like this: action path=/PersonForm type=com.foo.PopulatePersonAction name=PersonalDetailsForm scope=request validate=true forward name=success path=/pages/PersonalDetails.jsp / /action Then write a PopulatePersonAction (or whatever) class that extends the struts Action class. When you hit /PersonForm.do, PopulatePersonAction can hit a datastore, create a DTO (validUser or whatever), and transfer the values from your DTO to the form (probably using the apache BeanUtils classes). When the Action class forwards to a mapping ('success'), the struts tags in the form will be able to access the bean that was created by the Action class. likewise, if you have the form submitting to a struts-config entry that maps to another Action class, the validate method will be called before the 'execute' method of the action mapped to the *.do that form is submitting to. because the validate method is called after the form bean has been populated, but before the Action class' 'execute' method has been called, when the validate method forwards back to the input form (the default behavior on failure to validate), i think the user's newly submitted fields should be prepopulated, so long as you used the html:form... tags for the form. This seemed unnecessarily complicated to me when i started using struts, but we soon found that if we kept things suitably atomic, the extra effort up front quickly paid of in code reusability (we reuse our action classes like mad) and standardization
Re: Struts starter
John, You have answered my question perfectly! Thank you very much. Thanks, also, to everyone else who has given their advice on this subject. Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Monday, March 08, 2004 1:58 PM Subject: RE: Struts starter on the first hit to you personForm.do, or whatever (i presume you're not hitting the jsp directly at any point), the backing Action class should get the values from the validUser bean and populate the PersonDetailsForm bean, which then gets used by the jsp. it sounds like maybe you're using the values in the validUser bean directly with the struts html:form... tags. i think what you have like this: html:text name=validUser... maybe should be this: html:text name=PersonDetailsForm... so the validUser bean is used by the Action classes, and the PersonDetailsForm bean by the jsp, and logic in the Action classes dictates when and how data is transfered between the two. validation failure just redisplays the form (which should display what the user just tried to enter, not the original data from validUser). validation success might call another action that updated validUser with the new info from PersonDetailsForm. at least i think so, if i understand you correctly. works like that in similar situations here. -Original Message- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 9:06 PM To: Struts Users Mailing List Subject: Re: Struts starter John, This is very good ... Please bear with me for a final bit of clarification. I neglected to explain that I had already created what you call the PopulatePersonAction in your example and also set up the struts-config as you suggested. I have the equivalent of this: form-beans form-bean name=personalDetailsForm type=com.foo.PersonalDetailsForm / /form-beans action path=/PersonForm type=com.foo.PopulatePersonAction name=personalDetailsForm scope=request validate=true input=/pages/PersonalDetails.jsp forward name=success path=/pages/TheNextPageToCall.jsp / /action Note that the value assigned to the input parameter is /pages/PersonalDetails.jsp. In my PersonalDetails.jsp the action in the html:form tag is PopulatePersonAction. When I initially call PersonalDetails.jsp, there is already a validUser bean in the session scope, representing the current, logged-in user. On first being displayed, I want the fields of PersonalDetails.jsp to be populated with data from the validUser bean. Say I have an emailAddress field that I populate, like this: html:text name=validUser property=emailAddress size=20 /. Let's say the user enters some invalid data into the email address field and then clicks the submit button. The controller calls the personalDetailsForm and executes its validate() method, which fails. Because of the failure, the controller then calls PersonalDetails.jsp -- because it is the value in the input parameter for the /PersonForm action defined in struts-config. The newly called PersonalDetails.jsp now has access to the PersonalDetailsForm form bean containing the data entered by the user. HOWEVER, HOW WILL THE NEWLY CALLED PersonalDetails.jsp POPULATE THE emailAddress FIELD WITH THE VALUE THAT THE USER ENTERED? Won't it just re-display the value from the validUser bean? Because that's how it's defined in the page, i.e., html:text name=validUser property=emailAddress size=20 /. Thanks, Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 10:19 PM Subject: RE: Struts starter i'm a relative newcomer myself, but i think the part you're missing is an Action class. Put an entry in struts-config something like this: action path=/PersonForm type=com.foo.PopulatePersonAction name=PersonalDetailsForm scope=request validate=true forward name=success path=/pages/PersonalDetails.jsp / /action Then write a PopulatePersonAction (or whatever) class that extends the struts Action class. When you hit /PersonForm.do, PopulatePersonAction can hit a datastore, create a DTO (validUser or whatever), and transfer the values from your DTO to the form (probably using the apache BeanUtils classes). When the Action class forwards to a mapping ('success'), the struts tags in the form will be able to access the bean that was created by the Action class. likewise, if you have the form submitting to a struts-config entry that maps to another Action class, the validate method will be called before the 'execute' method of the action mapped to the *.do that form is submitting to. because the validate method is called after the form bean has been populated, but before the Action class' 'execute' method has been called, when the validate method
Re: Struts starter
John, A final question on this, please. How do I obtain *the* PersonalDetailsForm bean from the Action class so that I can populate it? Thanks, Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Monday, March 08, 2004 1:58 PM Subject: RE: Struts starter on the first hit to you personForm.do, or whatever (i presume you're not hitting the jsp directly at any point), the backing Action class should get the values from the validUser bean and populate the PersonDetailsForm bean, which then gets used by the jsp. it sounds like maybe you're using the values in the validUser bean directly with the struts html:form... tags. i think what you have like this: html:text name=validUser... maybe should be this: html:text name=PersonDetailsForm... so the validUser bean is used by the Action classes, and the PersonDetailsForm bean by the jsp, and logic in the Action classes dictates when and how data is transfered between the two. validation failure just redisplays the form (which should display what the user just tried to enter, not the original data from validUser). validation success might call another action that updated validUser with the new info from PersonDetailsForm. at least i think so, if i understand you correctly. works like that in similar situations here. -Original Message- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 9:06 PM To: Struts Users Mailing List Subject: Re: Struts starter John, This is very good ... Please bear with me for a final bit of clarification. I neglected to explain that I had already created what you call the PopulatePersonAction in your example and also set up the struts-config as you suggested. I have the equivalent of this: form-beans form-bean name=personalDetailsForm type=com.foo.PersonalDetailsForm / /form-beans action path=/PersonForm type=com.foo.PopulatePersonAction name=personalDetailsForm scope=request validate=true input=/pages/PersonalDetails.jsp forward name=success path=/pages/TheNextPageToCall.jsp / /action Note that the value assigned to the input parameter is /pages/PersonalDetails.jsp. In my PersonalDetails.jsp the action in the html:form tag is PopulatePersonAction. When I initially call PersonalDetails.jsp, there is already a validUser bean in the session scope, representing the current, logged-in user. On first being displayed, I want the fields of PersonalDetails.jsp to be populated with data from the validUser bean. Say I have an emailAddress field that I populate, like this: html:text name=validUser property=emailAddress size=20 /. Let's say the user enters some invalid data into the email address field and then clicks the submit button. The controller calls the personalDetailsForm and executes its validate() method, which fails. Because of the failure, the controller then calls PersonalDetails.jsp -- because it is the value in the input parameter for the /PersonForm action defined in struts-config. The newly called PersonalDetails.jsp now has access to the PersonalDetailsForm form bean containing the data entered by the user. HOWEVER, HOW WILL THE NEWLY CALLED PersonalDetails.jsp POPULATE THE emailAddress FIELD WITH THE VALUE THAT THE USER ENTERED? Won't it just re-display the value from the validUser bean? Because that's how it's defined in the page, i.e., html:text name=validUser property=emailAddress size=20 /. Thanks, Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 10:19 PM Subject: RE: Struts starter i'm a relative newcomer myself, but i think the part you're missing is an Action class. Put an entry in struts-config something like this: action path=/PersonForm type=com.foo.PopulatePersonAction name=PersonalDetailsForm scope=request validate=true forward name=success path=/pages/PersonalDetails.jsp / /action Then write a PopulatePersonAction (or whatever) class that extends the struts Action class. When you hit /PersonForm.do, PopulatePersonAction can hit a datastore, create a DTO (validUser or whatever), and transfer the values from your DTO to the form (probably using the apache BeanUtils classes). When the Action class forwards to a mapping ('success'), the struts tags in the form will be able to access the bean that was created by the Action class. likewise, if you have the form submitting to a struts-config entry that maps to another Action class, the validate method will be called before the 'execute' method of the action mapped to the *.do that form is submitting to. because the validate method is called after the form bean has been populated, but before the Action class' 'execute' method has been called, when the validate method forwards back to the input form (the default
Struts starter
Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! HERE'S THE BACKGROUND I have a session bean (validUser) and I want to use its properties to initially populate a PersonalDetails form. Then I want to use the validate() method of the related ActionForm (PersonalDetailsForm) to check the newly submitted details and, if failing validation, redisplay them in the PersonalDetails form, so that the user can correct them. HERE'S THE QUESTION: Where and how do I initialize (prepopulate) the form fields with the properties from the validUser bean, but then enable them to be populated with the information entered by the user when the form fails validation? HERE'S WHAT I'VE TRIED I've tried using html:text ... tags in the form, but they only seem to accept values from either the default form bean or from a specified bean -- so that seems only to a give a single source for populating the fields. Thanks, Frank.
Re: Struts starter
Frank, please, correct me if i'm wrong: You have a Java Bean (validUser) and an ActionForm (PersonalDetailsForm) and you want to transfer property values from validUser to PersonalDetailsForm. Is it right ? If the name of these properties are the same, you can use BeansUtil.copyProperties(dest,src) (from commons) to copy the values. Remember that the PersonalDetailsForm is also a bean (so you can direct set the values in it)... Frank Burns wrote: Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! HERE'S THE BACKGROUND I have a session bean (validUser) and I want to use its properties to initially populate a PersonalDetails form. Then I want to use the validate() method of the related ActionForm (PersonalDetailsForm) to check the newly submitted details and, if failing validation, redisplay them in the PersonalDetails form, so that the user can correct them. HERE'S THE QUESTION: Where and how do I initialize (prepopulate) the form fields with the properties from the validUser bean, but then enable them to be populated with the information entered by the user when the form fails validation? HERE'S WHAT I'VE TRIED I've tried using html:text ... tags in the form, but they only seem to accept values from either the default form bean or from a specified bean -- so that seems only to a give a single source for populating the fields. Thanks, Frank. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Struts starter
i'm a relative newcomer myself, but i think the part you're missing is an Action class. Put an entry in struts-config something like this: action path=/PersonForm type=com.foo.PopulatePersonAction name=PersonalDetailsForm scope=request validate=true forward name=success path=/pages/PersonalDetails.jsp / /action Then write a PopulatePersonAction (or whatever) class that extends the struts Action class. When you hit /PersonForm.do, PopulatePersonAction can hit a datastore, create a DTO (validUser or whatever), and transfer the values from your DTO to the form (probably using the apache BeanUtils classes). When the Action class forwards to a mapping ('success'), the struts tags in the form will be able to access the bean that was created by the Action class. likewise, if you have the form submitting to a struts-config entry that maps to another Action class, the validate method will be called before the 'execute' method of the action mapped to the *.do that form is submitting to. because the validate method is called after the form bean has been populated, but before the Action class' 'execute' method has been called, when the validate method forwards back to the input form (the default behavior on failure to validate), i think the user's newly submitted fields should be prepopulated, so long as you used the html:form... tags for the form. This seemed unnecessarily complicated to me when i started using struts, but we soon found that if we kept things suitably atomic, the extra effort up front quickly paid of in code reusability (we reuse our action classes like mad) and standardization. good luck! john -Original Message- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 4:15 PM To: [EMAIL PROTECTED] Subject: Struts starter Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! HERE'S THE BACKGROUND I have a session bean (validUser) and I want to use its properties to initially populate a PersonalDetails form. Then I want to use the validate() method of the related ActionForm (PersonalDetailsForm) to check the newly submitted details and, if failing validation, redisplay them in the PersonalDetails form, so that the user can correct them. HERE'S THE QUESTION: Where and how do I initialize (prepopulate) the form fields with the properties from the validUser bean, but then enable them to be populated with the information entered by the user when the form fails validation? HERE'S WHAT I'VE TRIED I've tried using html:text ... tags in the form, but they only seem to accept values from either the default form bean or from a specified bean -- so that seems only to a give a single source for populating the fields. Thanks, Frank. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts starter
At 9:14 PM + 3/7/04, Frank Burns wrote: Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! Frank: Don't blame yourself: you've stumbled onto one of my personal top priorities to improve in Struts: prefilling forms with non-request data. While I was writing this, John McGrath described a general strategy which works *if* you don't already need to use the single ActionForm that is passed to Action.execute for processing *input* data. However, in most cases, you have a chain of events where you have different input and output forms. We've developed a few strategies for ealing with this where I work, but they're all the sort of thing which may not be ready for prime time -- that is, officially adding to the Struts core. Right now, Struts doesn't provide a particularly convenient way to get an instance of what we call the output form -- the form which will be in the view to which control is directed. Since 1.2.0, I've committed a few changes which make it a little easier for you to get Form Bean instances, but what is still missing right now is a proposal for a standard place to configure Struts to know which form bean you want. Practically speaking, you can get an Object of the right class from a static method of RequestUtils with no more than a FormBeanConfig and the ActionServlet. You can get a FormBeanConfig from a ModuleConfig instance, which you can get using ModuleUtils. So inside any Action, you can bootstrap yourself to having a Form bean object, which you can populate however you need. http://jakarta.apache.org/struts/api/org/apache/struts/util/RequestUtils.html#createActionForm(org.apache.struts.config.FormBeanConfig,%20org.apache.struts.action.ActionServlet) http://jakarta.apache.org/struts/api/org/apache/struts/config/ModuleConfig.html#findFormBeanConfig(java.lang.String) http://jakarta.apache.org/struts/api/org/apache/struts/util/ModuleUtils.html#getModuleConfig(javax.servlet.http.HttpServletRequest) One possible flaw with this (as it is now) is that it doesn't honor the scope parameter and search the request or session for possibly existing bean instances. Of course, that code is available inside non-public methods of RequestUtils; it's just a matter of choosing the right way of exposing them publicly. The sticky parts, in terms of packing this up so that it's easy for everyone to use in Struts is configuring the form bean name and scope in the right place -- where in the struts-config.xml (or in some other file) would you tell Struts the name (and scope) of the bean you want? At work, we're using the struts-chain ComposableRequestProcessor with a request chain command PagePrep, which looks up config information and choreographs finding a form bean and making it available to a piece of Java code which might know how to populate it. But Struts is still a good bit away from officially switching to the ComposableRequestProcessor, and our config information is part of a general UIToolkit which is not currently a part of Struts in any way. The general strategy we use would fit decently well into a Tiles Controller, except that a Tiles Controller doesn't have access to the running Servlet, and if you use ValidatorForms, your FormBean must have access to the Servlet object. There's been some talk about trying to apply the general controller pattern to all Struts forwards, and in some ways, that's what we do with our PagePrep strategy, but it's been a while since anyone suggested a specific approach, and I don't think I've ever seen any actual code to do it. I'd be open to community discussions about how to integrate some behavior like this into Struts before we get there, but I must admit that since I have a solution where I need it, I'll need some external motivation to work on a solution that fits into the current RequestProcessing model. This was discussed at great length last Spring (that long ago?!) http://marc.theaimsgroup.com/?l=struts-devm=105415755227385w=2 but nothing ever congealed the point where code was cut for the core Struts distribution. Joe -- Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time with computers, and nobody thinks of complaining. -- Jef Raskin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts starter
John, This is very good ... Please bear with me for a final bit of clarification. I neglected to explain that I had already created what you call the PopulatePersonAction in your example and also set up the struts-config as you suggested. I have the equivalent of this: form-beans form-bean name=personalDetailsForm type=com.foo.PersonalDetailsForm / /form-beans action path=/PersonForm type=com.foo.PopulatePersonAction name=personalDetailsForm scope=request validate=true input=/pages/PersonalDetails.jsp forward name=success path=/pages/TheNextPageToCall.jsp / /action Note that the value assigned to the input parameter is /pages/PersonalDetails.jsp. In my PersonalDetails.jsp the action in the html:form tag is PopulatePersonAction. When I initially call PersonalDetails.jsp, there is already a validUser bean in the session scope, representing the current, logged-in user. On first being displayed, I want the fields of PersonalDetails.jsp to be populated with data from the validUser bean. Say I have an emailAddress field that I populate, like this: html:text name=validUser property=emailAddress size=20 /. Let's say the user enters some invalid data into the email address field and then clicks the submit button. The controller calls the personalDetailsForm and executes its validate() method, which fails. Because of the failure, the controller then calls PersonalDetails.jsp -- because it is the value in the input parameter for the /PersonForm action defined in struts-config. The newly called PersonalDetails.jsp now has access to the PersonalDetailsForm form bean containing the data entered by the user. HOWEVER, HOW WILL THE NEWLY CALLED PersonalDetails.jsp POPULATE THE emailAddress FIELD WITH THE VALUE THAT THE USER ENTERED? Won't it just re-display the value from the validUser bean? Because that's how it's defined in the page, i.e., html:text name=validUser property=emailAddress size=20 /. Thanks, Frank. - Original Message - From: John McGrath [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 10:19 PM Subject: RE: Struts starter i'm a relative newcomer myself, but i think the part you're missing is an Action class. Put an entry in struts-config something like this: action path=/PersonForm type=com.foo.PopulatePersonAction name=PersonalDetailsForm scope=request validate=true forward name=success path=/pages/PersonalDetails.jsp / /action Then write a PopulatePersonAction (or whatever) class that extends the struts Action class. When you hit /PersonForm.do, PopulatePersonAction can hit a datastore, create a DTO (validUser or whatever), and transfer the values from your DTO to the form (probably using the apache BeanUtils classes). When the Action class forwards to a mapping ('success'), the struts tags in the form will be able to access the bean that was created by the Action class. likewise, if you have the form submitting to a struts-config entry that maps to another Action class, the validate method will be called before the 'execute' method of the action mapped to the *.do that form is submitting to. because the validate method is called after the form bean has been populated, but before the Action class' 'execute' method has been called, when the validate method forwards back to the input form (the default behavior on failure to validate), i think the user's newly submitted fields should be prepopulated, so long as you used the html:form... tags for the form. This seemed unnecessarily complicated to me when i started using struts, but we soon found that if we kept things suitably atomic, the extra effort up front quickly paid of in code reusability (we reuse our action classes like mad) and standardization. good luck! john -Original Message- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 4:15 PM To: [EMAIL PROTECTED] Subject: Struts starter Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! HERE'S THE BACKGROUND I have a session bean (validUser) and I want to use its properties to initially populate a PersonalDetails form. Then I want to use the validate() method of the related ActionForm (PersonalDetailsForm) to check the newly submitted details and, if failing validation, redisplay them in the PersonalDetails form, so that the user can correct them. HERE'S THE QUESTION: Where and how do I initialize (prepopulate) the form fields with the properties from the validUser bean, but then enable them to be populated with the information
Re: Struts starter
I'll ask the dumb question What is Strike-thru formatting? ~Martin~ - Original Message - From: Joe Germuska [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, March 07, 2004 6:12 PM Subject: Re: Struts starter At 9:14 PM + 3/7/04, Frank Burns wrote: Hi, I'm in the middle of working with my first application using Struts and desperately need some help. I've read nearly all of Ted Husted's Struts In Action book and browsed the mailing list archives but have not found a solution for what I want to do. I mention this to let you know that I have already tried hard, unsuccessfully, to find an answer to what seems to me to be a basic requirement. However, I may be struggling with my own misunderstanding! Frank: Don't blame yourself: you've stumbled onto one of my personal top priorities to improve in Struts: prefilling forms with non-request data. While I was writing this, John McGrath described a general strategy which works *if* you don't already need to use the single ActionForm that is passed to Action.execute for processing *input* data. However, in most cases, you have a chain of events where you have different input and output forms. We've developed a few strategies for ealing with this where I work, but they're all the sort of thing which may not be ready for prime time -- that is, officially adding to the Struts core. Right now, Struts doesn't provide a particularly convenient way to get an instance of what we call the output form -- the form which will be in the view to which control is directed. Since 1.2.0, I've committed a few changes which make it a little easier for you to get Form Bean instances, but what is still missing right now is a proposal for a standard place to configure Struts to know which form bean you want. Practically speaking, you can get an Object of the right class from a static method of RequestUtils with no more than a FormBeanConfig and the ActionServlet. You can get a FormBeanConfig from a ModuleConfig instance, which you can get using ModuleUtils. So inside any Action, you can bootstrap yourself to having a Form bean object, which you can populate however you need. http://jakarta.apache.org/struts/api/org/apache/struts/util/RequestUtils.htm l#createActionForm(org.apache.struts.config.FormBeanConfig,%20org.apache.str uts.action.ActionServlet) http://jakarta.apache.org/struts/api/org/apache/struts/config/ModuleConfig.h tml#findFormBeanConfig(java.lang.String) http://jakarta.apache.org/struts/api/org/apache/struts/util/ModuleUtils.html #getModuleConfig(javax.servlet.http.HttpServletRequest) One possible flaw with this (as it is now) is that it doesn't honor the scope parameter and search the request or session for possibly existing bean instances. Of course, that code is available inside non-public methods of RequestUtils; it's just a matter of choosing the right way of exposing them publicly. The sticky parts, in terms of packing this up so that it's easy for everyone to use in Struts is configuring the form bean name and scope in the right place -- where in the struts-config.xml (or in some other file) would you tell Struts the name (and scope) of the bean you want? At work, we're using the struts-chain ComposableRequestProcessor with a request chain command PagePrep, which looks up config information and choreographs finding a form bean and making it available to a piece of Java code which might know how to populate it. But Struts is still a good bit away from officially switching to the ComposableRequestProcessor, and our config information is part of a general UIToolkit which is not currently a part of Struts in any way. The general strategy we use would fit decently well into a Tiles Controller, except that a Tiles Controller doesn't have access to the running Servlet, and if you use ValidatorForms, your FormBean must have access to the Servlet object. There's been some talk about trying to apply the general controller pattern to all Struts forwards, and in some ways, that's what we do with our PagePrep strategy, but it's been a while since anyone suggested a specific approach, and I don't think I've ever seen any actual code to do it. I'd be open to community discussions about how to integrate some behavior like this into Struts before we get there, but I must admit that since I have a solution where I need it, I'll need some external motivation to work on a solution that fits into the current RequestProcessing model. This was discussed at great length last Spring (that long ago?!) http://marc.theaimsgroup.com/?l=struts-devm=105415755227385w=2 but nothing ever congealed the point where code was cut for the core Struts distribution. Joe -- Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time