Re: Struts 2 : application-wide values initialization.
You can do the same with an application scope bean using spring . Create a simple pojo that initializes values on the constructor. Then add an entry to the applicationContext.xml file : beans bean id=myComp class=org.components.MyComponent singleton=true/ /beans Then in your java action file that you wish to have access declare : private MyComponent myComp; and create a setter : public void setMyComp(MyComponent myComp) { this.myComp = myComp; } Now you can get and edit these default values from your action. I do not know if this is the best way to do it and please excuse if i have any typing mistake (it should be fine though...). Regards, Leon Chris Pratt wrote: On 9/7/07, j alex [EMAIL PROTECTED] wrote: How is the ServletContextListener suited for my purpose ? . Can you please elaborate a little more? . What i'm looking for is access to the properties files' values and flags read from DB, not able to relate how this is related to the listener. In Struts 1, we were having an init servlet to load the application-wide properties like dropdown values (from property files) into application context and accessing these within JSP. Is there a better way of doing this in Struts 2, and do we require an initialization servlet at all ? . The ServletContextListener is called when the ServletContext is starting up and shutting down. It's designed to let you do one time configuration and initialization. You have access to the ServletContext so that you can put things in the Application scope. Sorry, I thought that's what you were asking for. (*Chris*) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts 2 : application-wide values initialization.
Another option is to subclass the Struts 2 FilterDispatcher to perform initializations: public class YourAppDispatcher extends FilterDispatcher { public void init(FilterConfig filterConfig) throws ServletException { super.init(filterConfig); // your initialization code here... } } Gabriel 2007/9/8, Leonidas Papadakis [EMAIL PROTECTED]: You can do the same with an application scope bean using spring . Create a simple pojo that initializes values on the constructor. Then add an entry to the applicationContext.xml file : beans bean id=myComp class=org.components.MyComponent singleton=true/ /beans Then in your java action file that you wish to have access declare : private MyComponent myComp; and create a setter : public void setMyComp(MyComponent myComp) { this.myComp = myComp; } Now you can get and edit these default values from your action. I do not know if this is the best way to do it and please excuse if i have any typing mistake (it should be fine though...). Regards, Leon Chris Pratt wrote: On 9/7/07, j alex [EMAIL PROTECTED] wrote: How is the ServletContextListener suited for my purpose ? . Can you please elaborate a little more? . What i'm looking for is access to the properties files' values and flags read from DB, not able to relate how this is related to the listener. In Struts 1, we were having an init servlet to load the application-wide properties like dropdown values (from property files) into application context and accessing these within JSP. Is there a better way of doing this in Struts 2, and do we require an initialization servlet at all ? . The ServletContextListener is called when the ServletContext is starting up and shutting down. It's designed to let you do one time configuration and initialization. You have access to the ServletContext so that you can put things in the Application scope. Sorry, I thought that's what you were asking for. (*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: Simple Question about FreeMarker + Struts 2
Freemarker considers null references errors. When myActionProperty.subProperty is referenced in the Struts tag, it is printed regardless of its value. However, when Freemarker encounters ${myActionProperty.subProperty}, it will give you an error if subProperty is null. When trying to print Freemarker variables using the $ or # syntax, you should probably do an if check like this: # if myActionProperty.subProperty?exists ${myActionProperty.subProperty} /#if I know, it's a bit of a pain. Zarar Siddiqi On 9/6/07, Kenton [EMAIL PROTECTED] wrote: I'm a newbie trying learn how to use FreeMarker for Struts result pages. This code works: @s.property value=myActionProperty.subProperty / This code triggers a FreeMarker error (expression undefined): ${myActionProperty.subProperty} Obviously, I'm missing something very simple. But what is it? Is there any way to dump the tree of EL variables so that I can undertand better? Is there any good documentation on using FreeMarker in Struts? I can find great documentation on FreeMarker by itself and Struts by itself, but I can't find any docs or tutorials on using the two together. Any suggestions? -- View this message in context: http://www.nabble.com/Simple-Question-about-FreeMarker-%2B-Struts-2-tf4394620.html#a12531237 Sent from the Struts - User mailing list archive at Nabble.com. - 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: [S2] struts tags
s:submit theme=simple value=%{getText('category.edit.cancelButton')}/ Zarar On 9/6/07, Adam Hardy [EMAIL PROTECTED] wrote: I am using struts tags for the first time in a JSP with S2 and I haven't found what I'm looking for so I guess it's not available, but could I just check for certain? I want to put a string into a button using an i18n bundle. I tried this: s:submit key=category.edit.cancelButton / and I tried this: s:submit fmt:message key=category.edit.cancelButton/ /s:submit I know I could do this: fmt:message var=label key=category.edit.cancelButton / s:submit key=${label} / but it's not nice. The docs allude to the mechanism but I haven't figured it out. I have the constant struts.custom.i18n.resources set in my struts.xml. Regards Adam PS for the record, I think it's just that I'm not finding the documentation intuitive. For instance I figured out how to prevent the struts form tags from outputting HTML table tags but I had to use a search engine. I tried setting the: struts.ui.theme= but that was obviously not the solution. My problem was that I wanted to turn the 'themes' feature off. But you don't turn it 'off' - you just turn it down. It's: struts.ui.theme=simple Maybe a line in the taglib docs would make it more obvious? - 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: Simple Question about FreeMarker + Struts 2
Some other things you can use: ${myActionProperty.subProperty!} Prints nothing if subProperty doesn't exist or is null ${myActionProperty.subProperty?default(default value) Prints default value if subProperty doesn't exist or is null The first expression (ending with !) is most similar in behavior to the @s.property / tag. On Sep 6, 2007, at 4:55 PM, Kenton wrote: I'm a newbie trying learn how to use FreeMarker for Struts result pages. This code works: @s.property value=myActionProperty.subProperty / This code triggers a FreeMarker error (expression undefined): ${myActionProperty.subProperty} Obviously, I'm missing something very simple. But what is it? Is there any way to dump the tree of EL variables so that I can undertand better? Is there any good documentation on using FreeMarker in Struts? I can find great documentation on FreeMarker by itself and Struts by itself, but I can't find any docs or tutorials on using the two together. Any suggestions? -- View this message in context: http://www.nabble.com/Simple-Question- about-FreeMarker-%2B-Struts-2-tf4394620.html#a12531237 Sent from the Struts - User mailing list archive at Nabble.com. - 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]
Struts2 with AJAX
Hi, I am using a very basic AJAX code snippet with struts. No it's not dojo. req = new XMLHttpRequest(); var url='http://localhost:8084/StrutsAjax/example/SearchAJAX.action'; req.open(POST,url,true); req.onreadystatechange=searchResults; req.send(null); in searchResults() function I just wnt to see req.responseText; If I want to return some response from server side if I use something crude like this response.getOutputStream().print(htmlAnimesh/html); It messes up struts and I get lots of exceptions in responseText. I want to return some string from the server side which is accessible by javascript code. It can be JSON or anything. What should be the code on server side / my action class (execute method) to return something to client side? Any suggestions?? Thanks, Animesh - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] struts tags
Man oh man that is going to fry the algorithms in my poor JSP editor, even if it could cope with the stuff I force-feed it at the moment (which it doesn't). Isn't there a non-OGNL way? thanks Adam Zarar Siddiqi on 08/09/07 18:25, wrote: s:submit theme=simple value=%{getText('category.edit.cancelButton')}/ Zarar On 9/6/07, Adam Hardy [EMAIL PROTECTED] wrote: I am using struts tags for the first time in a JSP with S2 and I haven't found what I'm looking for so I guess it's not available, but could I just check for certain? I want to put a string into a button using an i18n bundle. I tried this: s:submit key=category.edit.cancelButton / and I tried this: s:submit fmt:message key=category.edit.cancelButton/ /s:submit I know I could do this: fmt:message var=label key=category.edit.cancelButton / s:submit key=${label} / but it's not nice. The docs allude to the mechanism but I haven't figured it out. I have the constant struts.custom.i18n.resources set in my struts.xml. Regards Adam PS for the record, I think it's just that I'm not finding the documentation intuitive. For instance I figured out how to prevent the struts form tags from outputting HTML table tags but I had to use a search engine. I tried setting the: struts.ui.theme= but that was obviously not the solution. My problem was that I wanted to turn the 'themes' feature off. But you don't turn it 'off' - you just turn it down. It's: struts.ui.theme=simple Maybe a line in the taglib docs would make it more obvious? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Struts2 with AJAX
Hi, In your action class you have to return null after you write the response for eg:- public String ajax() throws Exception { respone.getWriter().println(hello); respone.getWriter().close(); return null; } and also i dont think you need to specify the full URL when you are doing the ajax call., Thanks, Nuwan animesh saxena wrote: Hi, I am using a very basic AJAX code snippet with struts. No it's not dojo. req = new XMLHttpRequest(); var url='http://localhost:8084/StrutsAjax/example/SearchAJAX.action'; req.open(POST,url,true); req.onreadystatechange=searchResults; req.send(null); in searchResults() function I just wnt to see req.responseText; If I want to return some response from server side if I use something crude like this response.getOutputStream().print(htmlAnimesh/html); It messes up struts and I get lots of exceptions in responseText. I want to return some string from the server side which is accessible by javascript code. It can be JSON or anything. What should be the code on server side / my action class (execute method) to return something to client side? Any suggestions?? Thanks, Animesh - 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]