[s2] accessing servlet context from an action
Hi, I'm familiar with Struts 1, looking at Struts 2. The web app I am working on needs to use data sources that are controlled by tomcat connection pooling and accessed through JNDI. For this I need access to the servlet context that the action is running under. Previously I had a base action class that all actions extended and provided a method : protected Connection getConnection() { Connection conn = null; try { String datasourceName = jdbc/ + getServlet().getServletContext().getInitParameter(database); Context initCtx = new InitialContext(); Context envCtx = (Context)initCtx.lookup(java:comp/env); DataSource ds = (DataSource)envCtx.lookup(datasourceName); log.debug(retrieving database connection for + datasourceName); conn = ds.getConnection(); log.debug(done); conn.setAutoCommit(false); return conn; } catch (SQLException ex) { log.error(error getting a connection, ex); return null; } catch (NamingException ex) { log.error(error finding the datasource, ex); return null; } } However, I am completely lost with Struts 2. Everything servlet dependent is abstracted away somewhere. I've been looking at the tutorials and they don't cover this kind of thing at all. How do I go about putting the equivalent in an action with Struts 2? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [s2] accessing servlet context from an action
On 3/23/07, Piero Sartini [EMAIL PROTECTED] wrote: However, I am completely lost with Struts 2. Everything servlet dependent is abstracted away somewhere. I've been looking at the tutorials and they don't cover this kind of thing at all. How do I go about putting the equivalent in an action with Struts 2? An action class can implement ServletContextAware - you have to implement a method setServletContext(ServletContext servletContext) then. Another way is to use ServletActionContext.getServletContext(); Piero Thanks Piero, I'm looking at the javadoc for this, it doesn't say much. Do I just create a class scope variable for the session context and then set that from the argument in the set method? Is this set method called automagically by the framework when the action is first accessed or when the web app is deployed? If I put this in the base action class and extend that for my other actions, will this cause problems, or does each final action class need to implement this? Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [s2] accessing servlet context from an action
Thank you muchly! On 3/23/07, Dave Newton [EMAIL PROTECTED] wrote: --- Chris Cheshire [EMAIL PROTECTED] wrote: I'm looking at the javadoc for this, it doesn't say much. Do I just create a class scope variable for the session context and then set that from the argument in the set method? Yep. Is this set method called automagically by the framework when the action is first accessed or when the web app is deployed? If I put this in the base action class and extend that for my other actions, will this cause problems, or does each final action class need to implement this? Actions are instantiated per-request. d. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT-Friday]What's the best way to search through Struts user list ...
Robin, I use http://marc.theaimsgroup.com/?l=struts-user for my mailing list archive searching. Drop back to their main page, and you will see there is a vast number of tech mailing lists archived there. Google can also prove fruitful too, there are probably other places that archive the mailing list and provide good search features too. HTH Chris On 11/10/06, robin bajaj [EMAIL PROTECTED] wrote: Hi Guys, What's the best way to search through Struts user mailing list archives ...for already known issues . Just Google or do we have some search functionality on the site that I didnt notice during a quick glance thanks, robin - 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]
problem with html:link tag
I am trying to use html:link to fix a URL so that it has the context path on it, but when the value of the page parameter requires quotes inside it (to specify a string value to a function) then the page won't compile. I have this link in td in the page : html:link page=${bgdlr:loadPendingOrdersLink(sortOrders[DAYS_UNTIL_CONFIRMED], 0, (sessionInfo.pendingOrdersSortOrder eq sortOrders[DAYS_UNTIL_CONFIRMED] ? not sessionInfo.pendingOrdersSortedAscending : true))} styleClass=copywhiteremaining/html:link If it is just a straight a href= tag it works fine, but when it is like this I get the following compilation error : org.apache.jasper.JasperException: equal symbol expected /WEB-INF/jspf/orderStackPanel.jspf(21,197) (The line above is line 21, character 197 is the D in the end of the first instance of DAYS_UNTIL_CONFIRMED. sortOrders is an application scope map of SortOrder objects (my class) keyed by String. sessionInfo is my own class. bgdlr:loadPendingOrders is a function I have in a tag library that builds the appropriate URL (without the context path where the web app might be installed). I have a lot of instances of this type of URL building, which is why I have put them in a custom tag library. I am using Netbeans 5.5 to develop the web-app, and it is being deployed on Sun Java Application Server 9, and both give that error. I initially had the web-app deployed with an empty context path, but now I need to change that, so I am building the hrefs now using the html:link tag instead of specifying an href directly. Any ideas? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: problem with html:link tag
Doh. I also discovered using single quotes around the page= value works too (not to mention the Netbeans editor correctly syntax-highlights the line properly this way). Thanks Michael :) On 8/28/06, Michael Jouravlev [EMAIL PROTECTED] wrote: Escaping the quotation symbols inside the string usually helps. On 8/28/06, Chris Cheshire [EMAIL PROTECTED] wrote: I am trying to use html:link to fix a URL so that it has the context path on it, but when the value of the page parameter requires quotes inside it (to specify a string value to a function) then the page won't compile. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [JAVA]Converting a string to date
try { java.sql.Date d = new java.sql.Date(new SimpleDateFormat(dd-MMM-yy).parse(06-apr-07).getTime()); } catch (ParseException ex) { } Chris On 6/22/06, temp temp [EMAIL PROTECTED] wrote: I have a string which I want to convert into a date . The string 06-APR-07 How can I convert this date into sql date ? Thanks - Yahoo! Groups gets better. Check out the new email design. Plus there's much more to come. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
displaying ActionMessages.GLOBAL_MESSAGE messages only
In my actions I have messages stored in the session either under ActionMessages.GLOBAL_MESSAGE, or my own key (eg 'search'). In my jsp I have a section to display the search specific messages. logic:messagesPresent message=true property=search /logic:messagesPresent I also need to display the global messages at the top of the page, however this displays everything, including the search messages: logic:messagesPresent message=true ... /logic:messagesPresent What do I set for the property to ONLY display the messages keyed by ActionMessages.GLOBAL_MESSAGE? Thanks, Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: displaying ActionMessages.GLOBAL_MESSAGE messages only
Yes, but I do not want to use a scriptlet. This value needs to be available outside of using a scriptlet (without having to write a JSP function to return that value). Which comes back to what Joe suggested. Unfortunately it looks like I'll be taking the cumbersome approach. Chris On 6/7/06, Samere, Adam J [EMAIL PROTECTED] wrote: How about just: logic:messagesPresent message=true property=%= ActionMessages.GLOBAL_MESSAGE % . /logic:messagesPresent You don't want to tie your code to the actual key since that is an implementation detail, that's what the public constant is for. -Original Message- From: Joe Germuska [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 07, 2006 3:55 PM To: Chris Cheshire; Struts Users Mailing List Subject: Re: displaying ActionMessages.GLOBAL_MESSAGE messages only At 12:47 PM -0700 6/7/06, Chris Cheshire wrote: In my actions I have messages stored in the session either under ActionMessages.GLOBAL_MESSAGE, or my own key (eg 'search'). In my jsp I have a section to display the search specific messages. logic:messagesPresent message=true property=search /logic:messagesPresent I also need to display the global messages at the top of the page, however this displays everything, including the search messages: logic:messagesPresent message=true ... /logic:messagesPresent What do I set for the property to ONLY display the messages keyed by ActionMessages.GLOBAL_MESSAGE? technically, you would use logic:messagesPresent message=true property=org.apache.struts.action.GLOBAL_MESSAGE . /logic:messagesPresent It has been observed that this is kind of cumbersome. A nice enhancement (that just about any willing volunteer could do, hint hint :-) ) would be to enhance the logic:messagesPresent, logic:messagesNotPresent, and html:messages and html:errors tags to have another attribute, global which if it had the valuetrue would save you from needing to know that verbose property name. Joe -- Joe Germuska [EMAIL PROTECTED] * http://blog.germuska.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: displaying ActionMessages.GLOBAL_MESSAGE messages only
I like the second approach better as it means I only have to keep track of one message collection in each individual action. It just means that I don't use the GLOBAL_MESSAGE constant, but I think I can live with that. Thanks Niall :) Chris On 6/7/06, Niall Pemberton [EMAIL PROTECTED] wrote: You can do this in different ways: 1) Store the two different sets of messages in different ActionMessages objects under different keys in the request or session. So for example in your action you could store the search messages using a session attribute key of search-messages - in your Action you might have: ActionMessages searchMsgs = new ActionMessages(); searchMsgs.add(fooSearch, new ActionMessage(foo.search.key)); searchMsgs.add(barSearch, new ActionMessage(bar.search.key)); session.setAttribute(search-messages, searchMsgs); Then to display these messages, you use the name attribute logic:messagesPresent name=search-messages html:messages name=search-messages id=... /html:messages /logic:messagesPresent You could then store your global messages under the default Struts messages key - so in your Action you might have ActionMessages globalMsgs = new ActionMessages(); globalMsgs.add(fooGlobal, new ActionMessage(foo.global.key)); globalMsgs.add(barGlobal, new ActionMessage(bar.global.key)); saveMessages(session, globalMsgs); Then to display these messages, you use the message=true attribute logic:messagesPresent message=true html:messages message=true id=... /html:messages /logic:messagesPresent This saveMesages() method and message=true attribute are just a convenience feature so that you don't have to specify a key in the request/session to save them under and to display them. 2) The second option is to save both sets of messages in one ActionMessages object and use the property attribute to filter the two different types. So add search messages with a property of search and global messages with a property of global: ActionMessages msgs = new ActionMessages(); msgs.add(search, new ActionMessage(foo.search.key)); msgs.add(search, new ActionMessage(bar.search.key)); msgs.add(global, new ActionMessage(foo.global.key)); msgs.add(global, new ActionMessage(bar.global.key)); saveMessages(session, msgs); To Show the global messages: logic:messagesPresent message=true property=global html:messages message=true property=global id=... /html:messages /logic:messagesPresent To Show the search messages: logic:messagesPresent message=true property=search html:messages message=true property=search id=... /html:messages /logic:messagesPresent The limitation on this approach is that you need to use the same property name for the messages of a specified type. I put up some notes on messages a while back here: http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html Niall Thanks, Chris - 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]
Re: displaying ActionMessages.GLOBAL_MESSAGE messages only
On 6/7/06, Michael Jouravlev [EMAIL PROTECTED] wrote: The first approach seems more logical to me. After all, the first parameter in ActionMessages.add() is supposed to be a property name. Hmmm that changes my perspective a little. Thanks for the comments Michael. Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
forwarding vs redirecting issue
Hi, I have a design issue based around form submission, protecting against resubmission etc. I have seen a couple of design guidelines that seem to conflict. 1) Use the session as little as possible (memory issues etc) 2) Use forwards where possible as requests can be passed along, with original information preserved, as well as speeding up communication. Now the only problem I face is after an action is complete, if I forward to a JSP, that action is open to resubmission when the user starts playing with the reload and back buttons on their browser. Redirects, because of the URL changing, can help protect against this. So the solution seems to be to place the beans required by the JSP page in displaying the result of the action in the session instead. So now there is an issue of when do the objects for the action that was just performed get removed from the session? Do I just put something in the start of each action to remove from the session all objects not associated with that action? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
using the indexId value of iterate in a radio button
I have a collection of PaymentSource objects (credit cards, debit accounts) stored in an object in the session. I want to iterate through these, presenting a radio button and the masked version of the account number on the page. I want to have the value of the radio button the index in the collection, not the value of the account number itself (which is the unique identifier of the objects) for data security reasons. Unfortunately the value tag of html:radio wants a bean property of the payment source. How can I get it to use the exposed indexId bean from the logic:iterate tag? I have logic:iterate id=paymentSource indexId=idx name=sessionInfo property=paymentSources scope=session tr td class=grey width=10 nowraphtml:radio idName=paymentSource property=paymentSourceId value=idx //td /tr /logic:iterate But it is looking for the property idx under paymentSource. Is there any way to do this? The properties of PaymentSource don't include anything that is unique and not sensitive. Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using the indexId value of iterate in a radio button (SOLVED)
OK I was making this to be way harder than it needed to be. logic:iterate id=paymentSource indexId=idx name=sessionInfo property=paymentSources scope=session tr td class=grey width=10 nowraphtml:radio property=paymentSourceId value=${idx} //td /tr /logic:iterate Was all I needed. Chris On 3/14/06, Chris Cheshire [EMAIL PROTECTED] wrote: I have a collection of PaymentSource objects (credit cards, debit accounts) stored in an object in the session. I want to iterate through these, presenting a radio button and the masked version of the account number on the page. I want to have the value of the radio button the index in the collection, not the value of the account number itself (which is the unique identifier of the objects) for data security reasons. Unfortunately the value tag of html:radio wants a bean property of the payment source. How can I get it to use the exposed indexId bean from the logic:iterate tag? I have logic:iterate id=paymentSource indexId=idx name=sessionInfo property=paymentSources scope=session tr td class=grey width=10 nowraphtml:radio idName=paymentSource property=paymentSourceId value=idx //td /tr /logic:iterate But it is looking for the property idx under paymentSource. Is there any way to do this? The properties of PaymentSource don't include anything that is unique and not sensitive. Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multiple-step form processing
Thanks Laurie, I didn't even think of that. I am going to explore what Michael posted, because I like the tidiness of that solution. Chris On 3/3/06, Laurie Harper [EMAIL PROTECTED] wrote: Just for balance ;-) I'll also point out that you don't *have* to disable automatic validation to achieve your goal; there are approaches that will allow you to retain that functionality, too. One possibility is to point the 'input' attribute to the same DispatchAction and have one of the methods in that determine which JSP to forward to. L. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multiple-step form processing
I want to set up a form that is entered over 3 successive pages. I have a single form bean for all of them that includes all of the fields, and the validate method only validates the fields that were implemented on each particular step. Step 2 will present 1 of 2 sub-forms, depending on an option selected on the bottom of form 1 (ie, either enter credit card info, or bank account info). I was thinking of using a DispatchAction to process each step and move to the next part of the form sequence, but my problem is with automatic validation and the struts-config declarations. I can only declare one input per action, so if validation fails on any step the controller would always redirect back to that specified input page - which might not be the one the user was on. Do I actually need to set up multiple actions each with their own input and process the steps through there or is there a way I can do this with a single DispatchAction? Or better yet, can I set validation to false in struts-config and then call the validation routine myself inside the action and then forward back to the correct input page if it fails? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multiple-step form processing
Thanks Michael, both of those are helpful. I have a few extra questions though: Regarding ActionDispatcher - * The ParameterListActionDispatcher class isn't in the 1.2.8 struts distribution that I downloaded, and is linked as a bugfix. Do I need to download the entire struts source, add this in and recompile, or is there an easier way? Regarding DataEntryForm - * In sections 6 7 it describes a class ParameterMappingDispatchAction that I also don't see in the distribution (nor in the javadocs online). Is this referring to the ParameterListActionDispatcher class or something else? Conceptually it seems to be describing the same thing. If not is there an example of what step 7 is describing? All that aside, when I turn off automatic validation, can I still call the validation manually in my action code? ie. Something like : ActionErrors errors = form.validate(mapping, request); if (!errors.isEmpty()) { // determine which forward key to use based upon which step I am in the process forward = mapping.findForward(forwardKey); saveErrors(request, errors); return forward; } Is there anything else I need to do to validate the form manually? Thanks Chris On 3/2/06, Michael Jouravlev [EMAIL PROTECTED] wrote: On 3/2/06, Chris Cheshire [EMAIL PROTECTED] wrote: I want to set up a form that is entered over 3 successive pages. I have a single form bean for all of them that includes all of the fields, and the validate method only validates the fields that were implemented on each particular step. Step 2 will present 1 of 2 sub-forms, depending on an option selected on the bottom of form 1 (ie, either enter credit card info, or bank account info). I was thinking of using a DispatchAction to process each step and move to the next part of the form sequence, but my problem is with automatic validation and the struts-config declarations. I can only declare one input per action, so if validation fails on any step the controller would always redirect back to that specified input page - which might not be the one the user was on. Do I actually need to set up multiple actions each with their own input and process the steps through there or is there a way I can do this with a single DispatchAction? Or better yet, can I set validation to false in struts-config and then call the validation routine myself inside the action and then forward back to the correct input page if it fails? Do not use automatic validation, it prevents your action class from being called if validation fails. See these pages for a start: http://wiki.apache.org/struts/ActionDispatcher http://wiki.apache.org/struts/DataEntryForm Michael. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multiple-step form processing
Thank you for your help, I'll give all this a try :) Chris On 3/2/06, Michael Jouravlev [EMAIL PROTECTED] wrote: On 3/2/06, Chris Cheshire [EMAIL PROTECTED] wrote: Thanks Michael, both of those are helpful. I have a few extra questions though: Regarding ActionDispatcher - * The ParameterListActionDispatcher class isn't in the 1.2.8 struts distribution that I downloaded, and is linked as a bugfix. Do I need to download the entire struts source, add this in and recompile, or is there an easier way? ParameterListActionDispatcher is a proposal for upcoming Struts release. The more people use it and find it useful, the more chances that it will be included. So, try it and vote for it if you like it: http://issues.apache.org/bugzilla/show_bug.cgi?id=38343 I hope you will like it, I think it is the best known solution for event dispatch in Struts. If you use Struts 1.2.7+, all you need is only ParameterListActionDispatcher class. Download it and compile it along with your project. If you use older Struts version than you will need base ActionDispatcher as well, but nothing more. Regarding DataEntryForm - * In sections 6 7 it describes a class ParameterMappingDispatchAction that I also don't see in the distribution (nor in the javadocs online). Is this referring to the ParameterListActionDispatcher class or something else? Conceptually it seems to be describing the same thing. If not is there an example of what step 7 is describing? Right, I have to fix that. ParameterMappingDispatchAction was an initial patch, then Paul went with ParameterListActionDispatcher which is better because you can use any Action class, you do not have to derive your Action from some other dispatch class anymore. So disregard ParameterMappingDispatchAction, I will fix the wiki page later. All that aside, when I turn off automatic validation, can I still call the validation manually in my action code? ie. Something like : ActionErrors errors = form.validate(mapping, request); if (!errors.isEmpty()) { // determine which forward key to use based upon which step I am in the process forward = mapping.findForward(forwardKey); saveErrors(request, errors); return forward; } Of course. This is exactly how you do it, perfect. Is there anything else I need to do to validate the form manually? No. You may want to check errors for null, but it depends on how you implemented validate() method. Michael. - 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]
collection for html:optionsCollection in servlet context
I am building a select list to select a state for an address and since it will be used in a few forms throughout the application I want to make this as centralised as possible. I have built a bean with getValue(), getLabel() attributes and created a collection of them and placed as an attribute in the servlet context via a servlet that is loaded on startup. How do I retrieve this for use in the html:optionsCollection tag? I know the servlet context is accessible via the implicit 'application' variable in the jsp, but how do I access values from application.getAttribute(attrName) without using a scriptlet? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection for html:optionsCollection in servlet context
Michael, Thanks for the reference, but it doesn't explain very much. Yes the widget looks like what I want, but is it something I download? Is it something that exists in the struts tag libraries? Does the states collection exist there? What happens if I wanted to do states for Australia for instance, where would I obtain those? I understand how to write the struts tags to build the list, I don't quite know how to obtain a reference to a collection I have built and stored in the servlet context. Chris On 3/1/06, Michael Jouravlev [EMAIL PROTECTED] wrote: On 3/1/06, Chris Cheshire [EMAIL PROTECTED] wrote: I am building a select list to select a state for an address and since it will be used in a few forms throughout the application I want to make this as centralised as possible. I have built a bean with getValue(), getLabel() attributes and created a collection of them and placed as an attribute in the servlet context via a servlet that is loaded on startup. How do I retrieve this for use in the html:optionsCollection tag? http://wiki.apache.org/struts/StrutsWidgets - 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]
Re: collection for html:optionsCollection in servlet context
You lost me with that page too. The use of the word widget threw me completely because I am used to seeing it reference to a concrete component :) I understand how to write the struts tag. Let's step back a bit. I'll see if I can explain this better. My question is how do I reference the collection for use in the when it is stored via an attribute in the servlet context - ie the ServletContext.setAttribute(attributeName, attributeValue) method without using a scriptlet. I have a servlet, loaded on startup, that in the init(ServletConfig) method, creates a List of beans containing state information - name and abbreviation. I have added this to the servlet context under the attribute name of states. The value for the name attribute in the html:optionsCollection tag would be application - the implicit JSP variable that refers to the servlet context that the page is in. Now the problem lies in the value for the property attribute of the html:optionsCollection. It is supposed to be a property of name such that is just a getBlah() method. However this is impossible on the servlet context, because the collection resides as part of the attribute map within the session context. The attribute name in the map is states, but I can't use states as the property value because there is no getStates() method under ServletContext. How do I retrieve this collection out of the servlet context attribute map for use in the html:optionsCollection tag WITHOUT using a scriptlet to make the collection available as some page scoped collection? Is this possible? I don't want scriptlets exposed in the JSP page itself. If I have to use one I will just write a tag to do it. Chris On 3/1/06, Michael Jouravlev [EMAIL PROTECTED] wrote: On 3/1/06, Chris Cheshire [EMAIL PROTECTED] wrote: Michael, Thanks for the reference, but it doesn't explain very much. Yes the widget looks like what I want, but is it something I download? You lost me. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: collection for html:optionsCollection in servlet context
On 3/1/06, Craig McClanahan [EMAIL PROTECTED] wrote: If the thing stored under attribute states in application scope is, in fact, a List of beans, you won't need the property attribute at all. Specifying a name but not a property tells the tag to use the attribute value itself. Ahhh this is what I was missing! The reference I looked at said that property was actually required (Jakarta Struts Pocket Reference - Cavaness Keaton). You might then use it in a page like this: html:select ... html:optionsCollection name=states value=abbreviation label=name/ /html:select Thanks Craig, this works :) Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
passing objects from one request to another
I have the following chain of events in an app ActionA - PageA - ActionB - ActionC All transitions are forward requests (not redirects) and PageA - ActionB is a POST. In ActionA I have a form bean prepopulated with a collection to display and choose one of in PageA. ActionB then needs to get this info back out of the form. The problem is, since everything is in request scope, once the ActionA - PageA forward is completed, the bean is no longer valid. Is there any way to get the bean to transfer to the next request, or do I need to use a session bean instead (definitely not ideal as then I have to put the cleanup for it in numerous places). Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing objects from one request to another
The problem is there is other information in the form bean that is not in the page, therefore it is not getting initialised properly. I am going with the hidden variable approach as suggested. On 2/24/06, Michael Jouravlev [EMAIL PROTECTED] wrote: On 2/24/06, Chris Cheshire [EMAIL PROTECTED] wrote: I have the following chain of events in an app ActionA - PageA - ActionB - ActionC All transitions are forward requests (not redirects) and PageA - ActionB is a POST. In ActionA I have a form bean prepopulated with a collection to display and choose one of in PageA. ActionB then needs to get this info back out of the form. The problem is, since everything is in request scope, once the ActionA - PageA forward is completed, the bean is no longer valid. Is there any way to get the bean to transfer to the next request, or do I need to use a session bean instead (definitely not ideal as then I have to put the cleanup for it in numerous places). Since you submit pageA to actionB, the form associated with actionB will be filled out with data from pageA. I don't see what the problem is. Yes, ActionForm will be created again. - 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]
init-param equivalent for action configuration?
If I am reading the docs right, the parameter attribute of the action element only allows you to define 1 generic parameter for the action. I need to be able to specify a few different parameters and their values. Prior to converting to struts I would put these as init-params in web.xml under each servlet declaration. Is there a way to do this in the struts config without using global context params in web.xml? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: init-param equivalent for action configuration?
Thanks Laurie On 2/20/06, Laurie Harper [EMAIL PROTECTED] wrote: Chris Cheshire wrote: If I am reading the docs right, the parameter attribute of the action element only allows you to define 1 generic parameter for the action. I need to be able to specify a few different parameters and their values. Prior to converting to struts I would put these as init-params in web.xml under each servlet declaration. Is there a way to do this in the struts config without using global context params in web.xml? Thanks Chris Is the set-property element what you're looking for? action ... set-property property=myProperty value=.../ /action L. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: init-param equivalent for action configuration?
OK I am still lost. I found reference to this in the DTD, so that covers the config file. However, I cannot find any mention of how to retrieve these properties in the Action subclass. I took a look at the javadocs for Action, ActionConfig, ActionMapping and I do not see anything relating to the set-property element of the configuration file. Are these translated by the struts framework into servlet context parameters? Is there anything in the struts documentation that describes this? Chris On 2/20/06, Laurie Harper [EMAIL PROTECTED] wrote: Chris Cheshire wrote: If I am reading the docs right, the parameter attribute of the action element only allows you to define 1 generic parameter for the action. I need to be able to specify a few different parameters and their values. Prior to converting to struts I would put these as init-params in web.xml under each servlet declaration. Is there a way to do this in the struts config without using global context params in web.xml? Thanks Chris Is the set-property element what you're looking for? action ... set-property property=myProperty value=.../ /action L. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: init-param equivalent for action configuration?
After a lot of browsing javadocs and scratching my head in confusion, I have something that appears to be working. In struts-config.xml I have a few set-property ... elements for an action. For the action mapping element of that action I have className=my mapping class. I have created a class that extends ActionMapping that provides get and set methods for these properties. These are then accessible inside the action by casting the provided action to the right class. Now that I have spent 2 hours looking at javadocs, I understand what is going on (I hope!) but this could REALLY do with an entry in the descriptive documentation. The javadocs only provide subtle hints about what is going on with that particular class and nothing ties any of it together. Have I missed something? Do I need to do anything else? Chris On 2/20/06, Laurie Harper [EMAIL PROTECTED] wrote: Chris Cheshire wrote: If I am reading the docs right, the parameter attribute of the action element only allows you to define 1 generic parameter for the action. I need to be able to specify a few different parameters and their values. Prior to converting to struts I would put these as init-params in web.xml under each servlet declaration. Is there a way to do this in the struts config without using global context params in web.xml? Thanks Chris Is the set-property element what you're looking for? action ... set-property property=myProperty value=.../ /action L. - 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]
Re: using a resource key to extra validation errors
Internationalisation. Resource bundle contains (among other things): label.password=password The label of the field is looked up from the resource bundle: tdbbean:message key=label.password //b/td The validation error in the form is keyed on that same value, looked up from the resource bundle: String label = resources.getMessage(label.password); ActionMessage message = new ActionMessage(validation.error.requiredfield, label); errors.add(label, message); So far, nowhere has the value 'password' been coded directly in. So how do I extract the error in the jsp *by using a resource key lookup*, not using the value 'password' directly? This: html:messages id=message message=false property=password breaks internationalisation. What happens when a resource bundle in another language is used. It is no longer keyed on 'password', because the other places have used a resource lookup to get the new value. How do I do it so that the value of property in html:messages is extracted from a resource bundle lookup like the bean:message is, like the creation of the ActionError is? On 2/17/06, Niall Pemberton [EMAIL PROTECTED] wrote: So what are you after? Why do you need to use a value from the resources as the message property? Niall - Original Message - From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 7:09 AM Yes what I have in my code is exactly what is in the example. It is not however what I am after. What is the point of using things from the resource bundle if it only works through 3/4 of the application? I have the error message next to the input field, by hardcoding the result of what would be a lookup to the resource bundle, as in that example. I don't want that. I want to be able to look up the value just like the bean:message tag does. On 2/16/06, Niall Pemberton [EMAIL PROTECTED] wrote: Did you try my suggestion - I believe that will do exactly what you want - you seem to be getting confused between the key used to store the ActionErrors in the request (global error key) and the property under which a message is stored in the ActionErrors. The validwhen example in the struts-examples does exactly what you say (show error messages next to their respective form fields) - so you could take a look at that (struts-examples.war in the binary distro): http://tinyurl.com/c2emd I think if you make the change I suggested it will do what you want - maybe its worth a try? Niall From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 3:36 AM That's not the issue, it is actually doing that, via a resource bundle lookup (I only have one configured). I want to be able to retrieve the error on the jsp side by getting the key via the resource bundle similar to the way it is being added, instead of just using the value that is referenced in the resource bundle. The field label is being printed via a message bundle lookup (using bean:message tag), and the error for that field is stored using that same key. I want to retrieve the error not by the discrete value password, but by a key lookup to the message bundle that produces the value password. Chris On 2/16/06, Niall Pemberton [EMAIL PROTECTED] wrote: Modify your code to do this: errors.add(password, message); http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5 Niall - Original Message - From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 1:50 AM I have an ActionForm with its own validate method that adds errors keyed upon entries in a resource bundle, so that the errors can be linked back to the field they are pertinent to, not just as a global error. String label = resources.getMessage(label.password); ActionMessage message = new ActionMessage(validation.error.requiredfield, label); errors.add(label, message); I have the error displaying next to the input field in the jsp page via : tdbbean:message key=label.password //b/td tdhtml:password property=password size=20 maxlength=20 //td td html:messages id=message message=false property=password bean:write name=message /br /html:messages /td Unfortunately the value of property is hardcoded in the html:messages tag. What I have there is the value stored in the resource bundle under label.password, as is used to display next to the input field in the bean:message tag. How can I extract the value from the resource bundle when using it as a value for the property field, instead of hard coding it in, which defeats the purpose of the resource bundle. Thanks Chris - To unsubscribe, e
Re: using a resource key to extra validation errors
Doh. Thanks Niall. I see now. Thanks for perservering Chris On 2/17/06, Niall Pemberton [EMAIL PROTECTED] wrote: You want to inernationalize your labels/messages/text - but not the names of your properties on your form bean [snip] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
font classes in html:link
I am new to using Struts and I can't see how to specify the font class and styles for an html:link tag. Previously I would have something like a href=some url class=font class from a style sheet style=text-decoration: nonelink body/a I don't see any equivalent thing to use in the html:link tag. How do I go about this? Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: font classes in html:link
Thanks, I wasn't looking deep enough on the struts site - I didn't even see that section. I was looking for documentation links at the top level. On 2/16/06, Dave Newton [EMAIL PROTECTED] wrote: Chris Cheshire wrote: I am new to using Struts and I can't see how to specify the font class and styles for an html:link tag. Previously I would have something like a href=some url class=font class from a style sheet style=text-decoration: nonelink body/a I don't see any equivalent thing to use in the html:link tag. http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-html.html#link Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
using a resource key to extra validation errors
I have an ActionForm with its own validate method that adds errors keyed upon entries in a resource bundle, so that the errors can be linked back to the field they are pertinent to, not just as a global error. String label = resources.getMessage(label.password); ActionMessage message = new ActionMessage(validation.error.requiredfield, label); errors.add(label, message); I have the error displaying next to the input field in the jsp page via : tdbbean:message key=label.password //b/td tdhtml:password property=password size=20 maxlength=20 //td td html:messages id=message message=false property=password bean:write name=message /br /html:messages /td Unfortunately the value of property is hardcoded in the html:messages tag. What I have there is the value stored in the resource bundle under label.password, as is used to display next to the input field in the bean:message tag. How can I extract the value from the resource bundle when using it as a value for the property field, instead of hard coding it in, which defeats the purpose of the resource bundle. Thanks Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using a resource key to extra validation errors
That's not the issue, it is actually doing that, via a resource bundle lookup (I only have one configured). I want to be able to retrieve the error on the jsp side by getting the key via the resource bundle similar to the way it is being added, instead of just using the value that is referenced in the resource bundle. The field label is being printed via a message bundle lookup (using bean:message tag), and the error for that field is stored using that same key. I want to retrieve the error not by the discrete value password, but by a key lookup to the message bundle that produces the value password. Chris On 2/16/06, Niall Pemberton [EMAIL PROTECTED] wrote: Modify your code to do this: errors.add(password, message); http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5 Niall - Original Message - From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 1:50 AM I have an ActionForm with its own validate method that adds errors keyed upon entries in a resource bundle, so that the errors can be linked back to the field they are pertinent to, not just as a global error. String label = resources.getMessage(label.password); ActionMessage message = new ActionMessage(validation.error.requiredfield, label); errors.add(label, message); I have the error displaying next to the input field in the jsp page via : tdbbean:message key=label.password //b/td tdhtml:password property=password size=20 maxlength=20 //td td html:messages id=message message=false property=password bean:write name=message /br /html:messages /td Unfortunately the value of property is hardcoded in the html:messages tag. What I have there is the value stored in the resource bundle under label.password, as is used to display next to the input field in the bean:message tag. How can I extract the value from the resource bundle when using it as a value for the property field, instead of hard coding it in, which defeats the purpose of the resource bundle. Thanks Chris - 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]
Re: using a resource key to extra validation errors
Yes what I have in my code is exactly what is in the example. It is not however what I am after. What is the point of using things from the resource bundle if it only works through 3/4 of the application? I have the error message next to the input field, by hardcoding the result of what would be a lookup to the resource bundle, as in that example. I don't want that. I want to be able to look up the value just like the bean:message tag does. On 2/16/06, Niall Pemberton [EMAIL PROTECTED] wrote: Did you try my suggestion - I believe that will do exactly what you want - you seem to be getting confused between the key used to store the ActionErrors in the request (global error key) and the property under which a message is stored in the ActionErrors. The validwhen example in the struts-examples does exactly what you say (show error messages next to their respective form fields) - so you could take a look at that (struts-examples.war in the binary distro): http://tinyurl.com/c2emd I think if you make the change I suggested it will do what you want - maybe its worth a try? Niall From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 3:36 AM That's not the issue, it is actually doing that, via a resource bundle lookup (I only have one configured). I want to be able to retrieve the error on the jsp side by getting the key via the resource bundle similar to the way it is being added, instead of just using the value that is referenced in the resource bundle. The field label is being printed via a message bundle lookup (using bean:message tag), and the error for that field is stored using that same key. I want to retrieve the error not by the discrete value password, but by a key lookup to the message bundle that produces the value password. Chris On 2/16/06, Niall Pemberton [EMAIL PROTECTED] wrote: Modify your code to do this: errors.add(password, message); http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5 Niall - Original Message - From: Chris Cheshire [EMAIL PROTECTED] Sent: Friday, February 17, 2006 1:50 AM I have an ActionForm with its own validate method that adds errors keyed upon entries in a resource bundle, so that the errors can be linked back to the field they are pertinent to, not just as a global error. String label = resources.getMessage(label.password); ActionMessage message = new ActionMessage(validation.error.requiredfield, label); errors.add(label, message); I have the error displaying next to the input field in the jsp page via : tdbbean:message key=label.password //b/td tdhtml:password property=password size=20 maxlength=20 //td td html:messages id=message message=false property=password bean:write name=message /br /html:messages /td Unfortunately the value of property is hardcoded in the html:messages tag. What I have there is the value stored in the resource bundle under label.password, as is used to display next to the input field in the bean:message tag. How can I extract the value from the resource bundle when using it as a value for the property field, instead of hard coding it in, which defeats the purpose of the resource bundle. Thanks Chris - 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]