RE: How to set the selected value in an select rendered by optionsCollection
> From: Frank Schaare [mailto:[EMAIL PROTECTED] > > This would only be true if the action that was called > specified that form in its mapping. > Sorry, but i guess you are wrong. > The declared formBeans are digested during ActionServlets.init(). Actually, he's right. :) My advice only applies if you have name="myForm" in your tag. If not, Struts will pass a null form into the execute method. It may have digested struts-config.xml, but without the name attribute in the form tag, it will not have actually instantiated one for you. I don't use any pre-processing Actions. Mine are all LookupDispatchAction, so the form is always there, although if it comes in with no parameter, the unspecified method will pre-fill the form from the database. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: rePost: How to set the selected value in an select rendered by optionsCollection
Its the name/property specified on the tag that causes OptionsCollection to set "selected" - in your case the select tag needs to look at he country property of the customer bean - if optionsCollection finds a value that matches that, it will set selected. Niall - Original Message - From: "Frank Schaare" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, March 11, 2004 11:49 AM Subject: rePost: How to set the selected value in an select rendered by optionsCollection > Hi all, > > i´m reposting my problem trying to be a little bit more specific. This > problem is very important for me, though i made another 'book like' > example to show where i am. > > There are three beans playing in my theatre: > 1. the CommonValuesBean which stores frequently asked data for my JSP > HTMLForms > 2. the CustomerBean which is an buisiness objekt representing a customer > 3. the DynaForm which stores data coming from my JSP HTMLForms. > > First of all, the CommonValuesBean is initialised. Therefore, i´ve got > the sessionListener that puts data in it, anytime a new session is creatd: > > public void sessionCreated(HttpSessionEvent event) { > CommonValuesBean commonValuesBean = new CommonValuesBean(); // create > new bean instance > HashMap countries = new HashMap(); // Create new map > countries.put("countryCode1","country1") > countries.put("countryCode2","country2") > countries.put("countryCode3","country3") > > countries.setCountries(countries); // Our example map is now stored > > HttpSession session = event.getSession(); > session.setAttribute("commonValuesBean",CommonValuesBean); > } > > Now we begin to deal with the customers. There is listCustomers Action > that shows all of the customers. You can klick one to > get more detailed information using the customersDetailsAction: > > public class customersDetailsAction extends Action > { > private Customer customer = new Customer(); > > public ActionForward execute(ActionMapping mapping,ActionForm > form,HttpServletRequest req,HttpServletResponse res) > throws IOException, ServletException > { > customer.setFirstName("Frank"); > customer.setLastName("Schaare"); > customer.setCountry("country2"); > > req.setAttribute("customer",customer); // storing customer in request > > return mapping.findForward("customerShowDetails"); // mapped to > customerShowDetails.jsp > } > } > > The customerShowDetails.jsp looks like this: > > > . > . tons of markup > . > > property="countries" label="value" value="key"/> > > . > . again: tons of markup > . > > > > The problem is, that the renders a select like > this: > > > country1 > country2 > country3 > > > i desperately NEED to render the select like this: > > > country1 > country2 > country3 > > > because my customer lives in country2 ! > > Is there any way to tell Struts to do this ? > > > - > 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]
rePost: How to set the selected value in an select rendered by optionsCollection
Hi all, i´m reposting my problem trying to be a little bit more specific. This problem is very important for me, though i made another 'book like' example to show where i am. There are three beans playing in my theatre: 1. the CommonValuesBean which stores frequently asked data for my JSP HTMLForms 2. the CustomerBean which is an buisiness objekt representing a customer 3. the DynaForm which stores data coming from my JSP HTMLForms. First of all, the CommonValuesBean is initialised. Therefore, i´ve got the sessionListener that puts data in it, anytime a new session is creatd: public void sessionCreated(HttpSessionEvent event) { CommonValuesBean commonValuesBean = new CommonValuesBean(); // create new bean instance HashMap countries = new HashMap(); // Create new map countries.put("countryCode1","country1") countries.put("countryCode2","country2") countries.put("countryCode3","country3") countries.setCountries(countries); // Our example map is now stored HttpSession session = event.getSession(); session.setAttribute("commonValuesBean",CommonValuesBean); } Now we begin to deal with the customers. There is listCustomers Action that shows all of the customers. You can klick one to get more detailed information using the customersDetailsAction: public class customersDetailsAction extends Action { private Customer customer = new Customer(); public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException { customer.setFirstName("Frank"); customer.setLastName("Schaare"); customer.setCountry("country2"); req.setAttribute("customer",customer); // storing customer in request return mapping.findForward("customerShowDetails"); // mapped to customerShowDetails.jsp } } The customerShowDetails.jsp looks like this: . . tons of markup . . . again: tons of markup . The problem is, that the renders a select like this: country1 country2 country3 i desperately NEED to render the select like this: country1 country2 country3 because my customer lives in country2 ! Is there any way to tell Struts to do this ? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to set the selected value in an select rendered by optionsCollection
Hi Hubert, This would only be true if the action that was called specified that form in its mapping. If this is a preprocessing action (that's being called to provide an HTML form with data to show), and there's no "name" attribute to tie a form to it, Struts will not create/populate a form (because it wouldn't know what form to create). Sorry, but i guess you are wrong. The declared formBeans are digested during ActionServlets.init(). If you have a tool that is able to visualize your Java Objects like the 'variables' view in Eclipse, you will see the following right after applications startup, when setting a breakpoint in any action: mapping/moduleConfig/formBeans which is a HashMap. All your declared beans are right there. Does anyone know the right way to access this HashMap ? Anyway, we became very far away from my optionsCollection problem. I´ll try to repost it trying to be a little more specific. CU - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to set the selected value in an select rendered by optionsCollection
--- Wendy Smoak <[EMAIL PROTECTED]> wrote: > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > because of the fact, that i´ve got no access to this bean in my > > preprocessing action. testSelect is a member of the upcoming > > DynaActionValidatorForm with is initiatet during the > > tag of my JSP. > > Nope. It goes request->form creation->action. You are being passed the > form in the signature of ActionForm.execute(), all you have to do is cast > it to the right type: > > DynaActionForm dForm = (DynaActionForm) form; This would only be true if the action that was called specified that form in its mapping. If this is a preprocessing action (that's being called to provide an HTML form with data to show), and there's no "name" attribute to tie a form to it, Struts will not create/populate a form (because it wouldn't know what form to create). You can make the form available to this action if you specify the form you want in the "name" attribute in this action's mapping. However, this would not be good practice since the preprocessing action could itself require a form of a different type. > > Now set whatever properties of dForm you need to, then forward to the JSP. > > > You are right the sbBean and the DynaActionValidatorForm have exactly > > the same members which seems to be a big design failure in my > > application. I should get rid of the sbBean and initiate the > > DynaActionValidatorForm earlier in my preprocessing action. > > Not recommended. They might be the same *now* but if your business object > changes in the future, you don't want that to be tied so closely to your > webapp. Since you're using dyanamic forms, it's not THAT much trouble to > maintain a business object plus some lines of XML. Or you can use a tool > to generate all the get/set methods for a regular ActionForm. > > -- > Wendy Smoak > Application Systems Analyst, Sr. > ASU IA Information Resources Management __ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to set the selected value in an select rendered by optionsCollection
> From: Frank Schaare [mailto:[EMAIL PROTECTED] > this is where i am: there is my business object 'sb' and the upcoming > DynaActionForm. sb extends ActionForm, there should be sb.execute(). No. The execute method is in the Action, not the ActionForm. > Shall i cast my business object 'sb' ? That would look like this: > DynaActionForm dSB = (DynaActionForm) sb You just said 'sb' is an ActionForm, so it cannot (well, should not,) also be a business object. We need to know about your Action class. That's the one with the execute method, which has a signature like this: public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) Inside that method is where you cast 'form' to whatever type of form you have. Then you'll have access to the 'set' methods of your particular type of form bean. If I'm still not understanding properly, please try again to explain what you need. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to set the selected value in an select rendered by optionsCollection
Hi Wendy, thx for your reply, but there are some questions left: this is where i am: there is my business object 'sb' and the upcoming DynaActionForm. sb extends ActionForm, there should be sb.execute(). Nope. It goes request->form creation->action. You are being passed the form in the signature of ActionForm.execute(), all you have to do is cast it to the right type: DynaActionForm dForm = (DynaActionForm) form; Shall i cast my business object 'sb' ? That would look like this: DynaActionForm dSB = (DynaActionForm) sb Or shall i look for the DynaActionForm in sb.execute() which will look like this: sb.execute() { //there must be a way to access Struts DynaForms . DynaActionForm dSB = (DynaActionForm) form } How do i get the form Objekt ? I debugged deep into Struts sources, found a 'mapping' Object with a 'formBeans' Vector but no way to access this mapping. Do you have a suggestion ? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to set the selected value in an select rendered by optionsCollection
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > in your preprocessing action class to set the value of > "testSelect", which will automatically add the SELECTED > attribute on the option tag? > because of the fact, that i´ve got no access to this bean in my > preprocessing action. testSelect is a member of the upcoming > DynaActionValidatorForm with is initiatet during the > tag of my JSP. Nope. It goes request->form creation->action. You are being passed the form in the signature of ActionForm.execute(), all you have to do is cast it to the right type: DynaActionForm dForm = (DynaActionForm) form; Now set whatever properties of dForm you need to, then forward to the JSP. > You are right the sbBean and the DynaActionValidatorForm have exactly > the same members which seems to be a big design failure in my > application. I should get rid of the sbBean and initiate the > DynaActionValidatorForm earlier in my preprocessing action. Not recommended. They might be the same *now* but if your business object changes in the future, you don't want that to be tied so closely to your webapp. Since you're using dyanamic forms, it's not THAT much trouble to maintain a business object plus some lines of XML. Or you can use a tool to generate all the get/set methods for a regular ActionForm. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to set the selected value in an select rendered by optionsCollection
Hi Nagiel, if (sb.getTitle().equals("Mr.")) formularBean.setTestSelect(sb.getTitle()) in your preprocessing action class to set the value of "testSelect", which will automatically add the SELECTED attribute on the option tag? because of the fact, that i´ve got no access to this bean in my preprocessing action. testSelect is a member of the upcoming DynaActionValidatorForm with is initiatet during the tag of my JSP. You are right the sbBean and the DynaActionValidatorForm have exactly the same members which seems to be a big design failure in my application. I should get rid of the sbBean and initiate the DynaActionValidatorForm earlier in my preprocessing action. But how ??? Does anyone have an example how to retrieve a DynaActionValidatorForm from the mapping ? And, if i use the DynaActionValidatorForm earlier in my preprocessing action, store it in requestScope, does the Tag take notice of it, or simply 'overrides' it ? It is my first Struts app and this is quit complex for me, hope Nagiel or someone else will help. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to set the selected value in an select rendered by optionsCollection
I'm not sure if I fully understand, but why not use: if (sb.getTitle().equals("Mr.")) formularBean.setTestSelect(sb.getTitle()) in your preprocessing action class to set the value of "testSelect", which will automatically add the SELECTED attribute on the option tag? Regards, Shahak Nagiel -Original Message- From: Frank Schaare [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 10, 2004 4:31 AM To: [EMAIL PROTECTED] Subject: How to set the selected value in an select rendered by optionsCollection I´ve got this select rendered with data from my applicationwide formularBean: This renders a select like this: Mrs. Mr. Dr. . . The formular fields in my JSP should be prefilled with data from my person bean ("sb") which has a Title property, so sb.getTitle() returns 'Mr.' in this example. Is there any chance to tell the html:select renderer "hey, if sb.getTitle() is = 'Mr.' write Mrs. Mr. Dr. . . " ??? I tried this workaround: but it rendered: Mr. Mrs. Mr. Dr. even if Validator returns to this page because of errors. Do you have any solutions/suggestions/articels for me to solve this problem ? -- +++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz +++ 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz - 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]
How to set the selected value in an select rendered by optionsCollection
I´ve got this select rendered with data from my applicationwide formularBean: This renders a select like this: Mrs. Mr. Dr. . . The formular fields in my JSP should be prefilled with data from my person bean ("sb") which has a Title property, so sb.getTitle() returns 'Mr.' in this example. Is there any chance to tell the html:select renderer "hey, if sb.getTitle() is = 'Mr.' write Mrs. Mr. Dr. . . " ??? I tried this workaround: but it rendered: Mr. Mrs. Mr. Dr. even if Validator returns to this page because of errors. Do you have any solutions/suggestions/articels for me to solve this problem ? -- +++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz +++ 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]