Re: When Oh When Do We Validate?
Pierre Métras wrote: Hi Craig, Pierre Métras wrote: As my design seems to be the *bad* one, I think I will have to change my code (explode my actions in struts-config.xml to create action /doSomethingInit and /doSomethingValid, and attach an "input" value only to /doSomethingValid, change all my JSP forms with these URL, and in the move suppress the now unused "action" parameter...). And Craig will have to rollback the CVS :,-( I'm not convinced that it would need to be rolled back -- or at least not completely. Independent of the actions versus sub-actions question on application organization, you also pointed out a real problem -- in the Struts 1.0 code as it was before this change, consider the following scenario: * You declare your action to require a form bean * Your form bean wants to do validation * You forget to define an "input" parameter in the action mapping * Struts never calls your validate() method * Your action method gets called, probably assuming that validation was successful, and relies on incorrect assumptions. That's what happened to me. My database was corrupted because I thought that the ActionForms information was valid when I forgot to add the "input" attribute to the action. This seems like a Bad Thing for a framework to allow when the developer simply forgets to update a configuration file :-(. I'm not sure this is so bad. Struts is used here as a part of a full J2EE based application, and J2EE applications are based, in every tier, on configuration files or deployment descriptors. For instance, you define the transactional behavior, the database mappings etc. of EJBs in a deployment descriptor. I thus think that everyone now understands that these deployment descriptors or configuration files are a critical part of the application, and that as much care should be taken in defining these files that in the coding of the classes (if not even more). I'm thus in favor of keeping the current behavior, where the form is not validated if the input element is not defined. It's just a matter of form reusability and declarative programming vs classical programming. Now, I wouldn't be too much against the reverse situation, where you would have to specify something in the config file if you want your form NOT to be validated. The best thing to do, IMHO, is to make the presence of a "validateForm" element (true or false) mandatory as soon as a formAttribute is defined. That way, you have the complete declarative control on the validation, and you can't make errors, since the application won't deploy if you forget to specify the element. Of course, you could still set it to false instead of true, but that would be your entire responsibility, and would have the same consequences as inadvertently returning null in your validate method. What do you think? JB. As the code sits right this minute, processValdiate() performs the following steps, where a "true" return says "go ahead and call the action". (A) If there is no form bean, simply return true (B) If the request was cancelled, simply return true (higher level logic will skip the call to the action) (C) Call the validate() method. If it returns no errors, simply return true -- from here on you know an error occurred -- (D) If this is a multipart request, roll it back (E) Was an input form defined? If not, throw an error 500 (internal server error) to document the mis-configuration problem. (F) Do a RequestDispatcher.forward() to the input form, and return false. From what it sounds like, there are particular concerns about step (C) -- validate() is always called -- and step (E) -- multipart requests are rolled back on validation errors. I don't really have a problem with either one of them, but others might. Can we come to agreement on what the recommended sequence of steps should be? In fact, I would move the question on another view. Should the action tag be a descriptive or behavioral tag? Do we want to put in it information to define the Struts application (which classes are used, where to redirect errors, etc.) or must we tend to put into it relations between application organization? In my opinion, the first situation is encountered presently: we define in the tag the different files/classes related to that action. Tha's no more than grouping. The problem occurs when we decide to deduce a behavior from it: if the "input" attribute is not present, it infers that the programmer doesn't want to have validation... To justify this, I can imagine numerous use cases where one need or not validation, or even partial validation (depending on the mapping). My present conviction is that the validation is context dependant, and that the most flexible place to take the decision to validate or not is in the validate method itself, when the programmer can
book ideas
Hi Everybody, I'm (already) working in a book in JSP and Tag Libraries development for New Riders Publishing. The idea of the book is: - An introduction on Servlets and JSP - Deep in Tag coding - Design and Architectural issues (major challenges when designing web apps with Servlets, JSP, Pet Shop Model 2 approach, Struts Model 2 approach, the role of tags in process encapsulation and reuse, how tags affect system design and how the Servlet/JSP architecture responds to that, etc.). EJBs are treated as subsidiary (calm down!) since it's too broad a subject and very well covered in many other books. - Deep in Struts (a couple of chapters to discuss the model, the usage scenarios and of course the taglibs) - Jakarta Taglibs (a broad coverage) - Commercial taglibs (the commercial case) - Appendixes on TOMCAT (I focus in TOMCAT), MySQL, Caucho Resin and Jrun (examples are provided also on these), jBoss - Many, many, MANY examples on everything. Questions are: 1. What do you think of this coverage ? 2. What would you like to see on paper ? My sources on the design issues are a number of articles (for instance that one from Jason Hunter questioning JSP), some reference books and the lists (not to mention experience, of course). 3. On the side of Struts, what do you like to see there ? What do you think is not yet said or well said about Struts ? 4. And on the design issues on Servlet/JSP architecture(s) ? Thank you all for your attention on this, Wellington Silva UN/FAO
Re: book ideas
This is what I prefer: 1) no reprint of the JSP/servlet JavaDoc to make the book 50% thicker 2) more description on Struts would be very helpful as the current docs are rather outdated, like struts-config.xml 3) the Java Pet Shop developers are considering migration to use Struts too, the current Pet Shop model may be obsolete by the time the book is published 4) include WebLogic and I think there will be many audenice __ Do You Yahoo!? Yahoo! Shopping - Thousands of Stores. Millions of Products. http://shopping.yahoo.com/
Re: book ideas
I'd prefer (and this is personal preference only) more on the development of models and application frameworks then actual introduction code. Coverage of PostgreSQL as well (it has transaction, which are quite crucial to the EJBs, otherwise you get MySQL's serialised table locking which is not great). Use of EJBs through the MVC framework. Where to use session beans (both types) and when to use entity beans (ie. should entity beans be attached to the session object (no, not really) but only accessed through the session beans, and the session beans return ordinary Java Beans to the servlet. Security context in relation to attaching a profile to the whole application. Not a reprint of the documentation that comes with any of the main downloads, as this just duplicates content and kills more trees. Other EJB/J2EE containers (eg. Enhydra/Jonas). Wait till Tomcat 4.0 is stable and Struts 1.0, otherwise you'll have major dead space in the book. (Although a paper book will always be somewhat out of date) If you focus on frameworks/ideas/concepts rather then deep examples you'll find the book lasts a lot longer, which is why Knuth's books are still valid resources today but my Java 1.0 Beta2 books are wasted space. At 10:59 AM 30/11/00 +0100, you wrote: Hi Everybody, I'm (already) working in a book in JSP and Tag Libraries development for New Riders Publishing. The idea of the book is: - An introduction on Servlets and JSP - Deep in Tag coding - Design and Architectural issues (major challenges when designing web apps with Servlets, JSP, Pet Shop Model 2 approach, Struts Model 2 approach, the role of tags in process encapsulation and reuse, how tags affect system design and how the Servlet/JSP architecture responds to that, etc.). EJBs are treated as subsidiary (calm down!) since it's too broad a subject and very well covered in many other books. - Deep in Struts (a couple of chapters to discuss the model, the usage scenarios and of course the taglibs) - Jakarta Taglibs (a broad coverage) - Commercial taglibs (the commercial case) - Appendixes on TOMCAT (I focus in TOMCAT), MySQL, Caucho Resin and Jrun (examples are provided also on these), jBoss - Many, many, MANY examples on everything. Questions are: 1. What do you think of this coverage ? 2. What would you like to see on paper ? My sources on the design issues are a number of articles (for instance that one from Jason Hunter questioning JSP), some reference books and the lists (not to mention experience, of course). 3. On the side of Struts, what do you like to see there ? What do you think is not yet said or well said about Struts ? 4. And on the design issues on Servlet/JSP architecture(s) ? Thank you all for your attention on this, Wellington Silva UN/FAO -- Kumera - a new Open Source Content Management System for small to medium web sites written in Perl and using XML http://www.cyber4.org/kumera/index.html
Q: How to dynamically initialize form:select ?
Hi ! I'm slowly becoming familiar with struts. I'm now faced with the following problem: I have a form in the middle of my application which among other things sports a dynamically populated form:select. From what I've read in the documentation I'm supposed to read the appropriate information upon Logon (or while navigating along the pages) and store in beans added as attributes to the session/request. While this certainly works I'm not yet fully convinced I'll like this for two reasons. 1) While the user moves along the dynamic info might change without it actually being used. This imposes IMO unnecessary load on the underlying DB which could and should be avoided. 2) For convenience and useability reasons the user can navigate the pages through some menus realized in JavaScript. While clicking his way through the decisiontree there is no interaction with the Servlet Engine. Eventually the user will come to a point where a full blown ActionForm/Action part is required which now need initialization according to the navigation done prior. Is there a way to achieve this other than creating some general helper-beans that solve this ? Or in other words: does struts allow for some convenient means to initialize a page upon creation ? Some kind of PreAction ? Thank you, Michael
Re: How to dynamically initialize form:select ?
Hi Michael, Or in other words: does struts allow for some convenient means to initialize a page upon creation ? Some kind of PreAction ? I add a similar problem and requested for such a feature. Now, in Struts 1.0, you can use the ActionForm.reset(mapping, request) to fill your form with some values, before auto-population by Struts. Based on the request parameters or the mapping, you can detect if it's a first time initialization and do what you want. What can be disturbing is that Struts always comes after you and replaces your values with the request parameters values, but you shouldn't be concerned when you want initialization. If you're using version 0.5, bad luck! I did the move to 1.0 for that reason... Pierre Métras
AW: Preprocessing for a jsp
-Ursprüngliche Nachricht- Von: Pierre Métras [SMTP:[EMAIL PROTECTED]] Gesendet am: Donnerstag, 30. November 2000 17:51 An: [EMAIL PROTECTED] Betreff: Re: Preprocessing for a jsp Hi Andre, Looks like i made some wrong configuration in the xml-files, because i get a java.lang.ClassCastException when the servlet is called. We need a little more information to help, because a Cast exception can occurs almost everywhere... Which version of Struts are you using? And give us an extract of your configuration file, with the stack dump. Pierre Métras [Andre Wittenburg] First of all, thanks for the quick reply. By the time I use the nightly build from 2000-11-26. The extract from struts-config.xml and web.xml follows. Andre struts-config.xml: action input="/dummy/index.jsp" name="fooForm" path="/dummy/First" scope="session" type="com.foo.MyAction" forward name="success" path="/dummy/Second.jsp"/ forward name="failure" path="/dummy/index.jsp"/ /action web.xml: servlet servlet-namemyAction/servlet-name servlet-classcom.foo.MyAction/servlet-class init-param param-nameapplication/param-name param-valuecom.foo.ApplicationResources/param-value /init-param /servlet servlet-mapping servlet-namemyAction/servlet-name url-pattern*.ma/url-pattern /servlet-mapping
Re: does struts examples work on NT platform?
Cherie Yoon wrote: Hi, My apology if there was same question on the list, but I couldn't find archive from the struts home page. I got the examples working on Linux platform, but I can't on NT. I tried both struts-examples.war and struts-test.war, but they are not working. (i tested with both Struts0.5 and 10/20/2000 build with Tomcat 3.1) When I click any link on struts-test/index.jsp or try any JSP page under struts-examples, it give me same error msg Tomcat 3.1 has a very large number of bugs -- update to Tomcat 3.2 (final release occurred last night). Craig McClanahan
Stable 1.0 and deployment ....
Sorry to bug, but is there a planned release date for a milestone 1.0 release? Just made the decision to go with Struts and I've been playing with v0.5. I'm looking to use it in a production environment so I'm not keen on using unstable releases ... but I also dont want to use 0.5 if there are going to be major changes In a nutshell should I deploy with 0.5 now, or is 1.0 immenient? Finally, currently it seems that for each deployed application you need to have struts.jar and all the taglibraries, is it possible to have one instance of for container. Presumably the .jar can just be added to the classpath, but how do I share the taglib's (I'm using Tomcat) Cheers ... p. The information in this email is confidential and is intended solely for the addressee(s). Access to this email by anyone else is unauthorised. If you are not an intended recipient, you must not read, use or disseminate the information contained in the email. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of The Capital Markets Company. http://www.capco.com ***
Re: Stable 1.0 and deployment ....
Allton Paul wrote: Sorry to bug, but is there a planned release date for a milestone 1.0 release? Just made the decision to go with Struts and I've been playing with v0.5. I'm looking to use it in a production environment so I'm not keen on using unstable releases ... but I also dont want to use 0.5 if there are going to be major changes In a nutshell should I deploy with 0.5 now, or is 1.0 immenient? It is relatively imminent ... but I had to spend a very large amount of November picking up the pieces and getting Tomcat 3.2 out the door (final release was last night). :-( There have been very substantial changes between 0.5 and the current code base. I would expect relatively few incompatible changes from the current code to final release, although there will probably need to be some as we implement the remaining suggestions and features. Personally, I would base new development on the current code. Finally, currently it seems that for each deployed application you need to have struts.jar and all the taglibraries, is it possible to have one instance of for container. Presumably the .jar can just be added to the classpath, but how do I share the taglib's (I'm using Tomcat) Yes, you need struts.jar and the tag library descriptors in each web app. It would be technically feasible to share the struts.jar file by putting it on the classpath, but that would break the Digester module -- it would no longer be able to see user classes that really were in WEB-INF/clasess or WEB-INF/lib. There is no mechanism to share TLDs across web apps. The whole idea is that a web app should be a self-contained component that can be installed on any servlet container, and it will "just work". Although this ideal is not completely met yet (primarily due to buggy servlet containers), it is pretty close to the case. Cheers ... p. Craig McClanahan
Re: Preprocessing for a jsp
Hi Andre, It seems there's no problem with your configuration files. Could you post the top of your exception trace? Pierre Métras
RE: struts in weblogic?
Thanks to all who replied. After much toiling, I got the example working under weblogic. As Anshum indicated, SP6 was necessary. However, SP5 may have worked as well, according to an article that I read. I also used the weblogic classloader "hack" descibed at: http://archive.covalent.net/jakarta/struts-user/2000/10/0009.xml Thanks again, Jeff -Original Message- From: Sharda, Anshum [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 29, 2000 5:39 PM To: [EMAIL PROTECTED] Subject: RE: struts in weblogic? Download and install Service Pack for WL5.1. That should get rid of this problem. - Anshum -Original Message- From: Jeff Klein [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 29, 2000 2:24 PM To: '[EMAIL PROTECTED]' Subject: struts in weblogic? Hi All, I am trying to get Struts up and running inside of a version 5.1 weblogic container. It seems that I am close, because some of the tags work (like the link tag). However, any tag that depends on the presence of a resource bundle (such as the message tag) fails with the following stack trace: Wed Nov 29 10:54:07 PST 2000:E ServletContext-struts-example Servlet failed with Exception javax.servlet.ServletException: runtime failure in custom tag 'message' at jsp_servlet._index._jspService(_index.java:89) at weblogic.servlet.jsp.JspBase.service(JspBase.java:27) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Servle tStubImpl.java :105) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Servle tStubImpl.java :123) at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Ser vletContextImp l.java:742) at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Ser vletContextImp l.java:686) at weblogic.servlet.internal.ServletContextManager.invokeServlet( ServletContext Manager.java:247) at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketH TTP.java:361) at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code) Wed Nov 29 10:54:08 PST 2000:E ServletContext-struts-example root cause of ServletException java.lang.NullPointerException: at weblogic.servlet.jsp.PageContextImpl.getAttribute(PageContextI mpl.java:156) at org.apache.struts.taglib.MessageTag.doStartTag(MessageTag.java:358) at jsp_servlet._index._jspService(_index.java:81) at weblogic.servlet.jsp.JspBase.service(JspBase.java:27) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Servle tStubImpl.java :105) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Servle tStubImpl.java :123) at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Ser vletContextImp l.java:742) at weblogic.servlet.internal.ServletContextImpl.invokeServlet(Ser vletContextImp l.java:686) at weblogic.servlet.internal.ServletContextManager.invokeServlet( ServletContext Manager.java:247) at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketH TTP.java:361) at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code) I looked at the source code for MessageTag.java and it fails at the point where it is trying to get a "bundle" object (instance of MessageResources) out of the PageContext application scope. // Acquire the resources object containing our messages MessageResources resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE); If I'm not mistaken, the MessageResources object should contain name/value pairs from ApplicationResources.properties. I have that file in its default location (/WEB-INF/classes/org/apache/struts/example/ApplicationResourc es.properties) . I have not seen any FileNotFoundException's so I think it is finding it OK. However, the MessageResources object is either not getting created, or is not making it into the application scope. Is there something I need to configure in weblogic.properties to insure that the application is initializing properly? By the way, this is the "struts-example" application that came with the struts binary distribution. It works fine under my tomcat installation but we use weblogic in production. Any suggestions would be helpful. Thanks, Jeff PS does anyone know if there are any other lists/websites that may have searchable FAQ's about struts?
Struts+Weblogic=Problems but this time it looks like it's Struts
I've been trying to get Struts to work on weblogic for many days with little success because of the failures of Weblogic's part. Finally tried to deploy and use it on Weblogic 6.0 Beta 2 and noticed some interesting behavior. It deployed fine but when I tried to run the example application I started getting errors saying that Weblogic could not deserialize the context attribute (see exact errors at end of mail) It appears that Weblogic requires any object that you use as a context attribute on a JSP page must be serializable. I went through some of the Struts source and it's trying to use objects which aren't serializable as JSP page context attributes. This looks like it may be a shortcoming in the JSP spec because it makes sense that to support to failover of sessions you would need to be able to serialize the attributes since the attributes of a PageContext may have the scope of an entire session. This is a bug that probably will show up on many different App Servers that support the failover of Sessions not just Weblogic and should probably be addressed in Struts even though it hasn't been directly addressed by the JSP 1.1 or 1.2 specs Nov 30, 2000 1:19:37 PM PST Error HTTP [WebAppServletContext(6802820,struts-example)] Could not deserialize context attribute ava.io.NotSerializableException: org.apache.struts.util.MessageResources at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366) at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:480) at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366) at weblogic.servlet.internal.AttributeWrapper.getObject(AttributeWrapper.java:7 1) at weblogic.servlet.internal.WebAppServletContext.getAttribute(WebAppServletCon text.java :207) at weblogic.servlet.jsp.PageContextImpl.getAttribute(PageContextImpl.java:164) at org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:230) at jsp_servlet._index._jspService(_index.java:105) at weblogic.servlet.jsp.JspBase.service(JspBase.java:27) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java :208) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java :244) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo ntext.jav a:1107) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java :1482) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120) -Matt
Re: Struts+Weblogic=Problems but this time it looks like it's Struts
Matthew Heaton wrote: The example application itself doesn't put non Serializable objects into the Http session but all throughout the struts code non Serializable objects are placed in the PageContext with a scopes of Application, Page, or Request. It appears that Weblogic 6.0 beta may be handling these as if they were placed with a Session context and disallowing non serializable objects. Whatever is going on it also appears WL is enforcing this rule in non when distributable is not set. Yep. Looking more closely at the error message, it is complaining about a non-Serializable *context* attribute, not a *session* attribute. I, like others, jumped to the wrong conclusion there. The spec provides no prohibitions on this -- only a warning that you cannot use a context attribute to share information globally in your application (the way that the example app does with its pseudo-database) in a distributed environment. Is there by chance some WebLogic specific configuration property you have set that makes it think this (or maybe all) applications should be treated as distributable? -Matt Craig
using tags within tag parameter field ?
I apologize as this is a generic jsp question and not specific to struts, but hopefully this is a simple one (at least, I give a struts example below). Is it possible to use a tag as an rtexprvalue within another tag's parameter field? For example (assuming 'mytag' can take a rtexprvalue for parameter 'param'): tag:mytag param="tag:anothertag param=\"hello\"/"/ As a struts example, here are two versions to show a dynamic list of simple menu items (there's a java.util.Collection attribute named "menu" attached to the request; it's a collection of beans with properties 'href' and 'text'), which differ only on the second line. The first version is quite ugly but works. The second version is what I'd like to use, but this doesn't work -- causes a compile exception. I'm assuming the answer to my question is "no", but does this mean I'm stuck with version 1, or is there a better way? ver 1: logic:iterate id="menuitem" collection="%=request.getAttribute(\"menu\")%" form:link href="%=((com.hotu.intra.MenuItem) pageContext.getAttribute(\"menuitem\")).getHref()%" bean:write name="menuitem" property="text"/ /form:link br /logic:iterate ver 2: logic:iterate id="menuitem" collection="%=request.getAttribute(\"menu\")%" form:link href="bean:write name=\"menuitem\" property=\"href\"/" bean:write name="menuitem" property="text"/ /form:link br /logic:iterate compile exception: /home/newsham/work/intranet/main.jsp:30: ')' expected. _jspTag3.setHref("bean:write name="menuitem" property="href"/"); ^ 1 error com.caucho.java.JavaCompileException: /home/newsham/work/intranet/main.jsp:30: ')' expected. _jspTag3.setHref("bean:write name="menuitem" property="href"/"); ^ 1 error Thanks, Jim Newsham
Re: using tags within tag parameter field ?
Hi Jim, I apologize as this is a generic jsp question and not specific to struts, but hopefully this is a simple one (at least, I give a struts example below). Is it possible to use a tag as an rtexprvalue within another tag's parameter field? For example (assuming 'mytag' can take a rtexprvalue for parameter 'param'): tag:mytag param="tag:anothertag param=\"hello\"/"/ No. You can't use tags into tag attributes. But with a little effort, you can rewrite your tag to support a syntax like: tag:mytag tag:param tag:anothertag param="hello"/ /tag:param /tag:mytag Else, you're stuck with ver.1 for now. Pierre Métras