Re: Potential Security Flaw in Struts MVC
Feel free. If you would like to document it, I'd be happy to find a place for it in the users guide. Calvin Yu wrote: I think that this potential exploit should probably be thoroughly documented, along with potential workarounds. Last thing we want is to have Struts being tagged as being unsecure.
Re: Potential Security Flaw in Struts MVC
This is open source. Anyone is welcome to jump in and join the management by submitting code. Jeff Trent wrote: Therefore, if I haven't reached my quota today, I'd like to suggest to management that there is a bean property (or something) that results in form fields being propogated accross multiple pages of my request/form and are managed using hidden variables alone. This would be an alternative to using session scope but would accomplish the same thing. Again, all comments are welcome...
Re: Potential Security Flaw in Struts MVC
Feel free to submit some code. Jeff Trent wrote: I like it! I second this request totally!
Struts in Action!
The Struts application framework is running an annual auction for a public broadcasting station at http://data.wxxi.org/wxxi-gavel/ The auction runs through next week, and the code will be released as open source thereafter. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: still fighting HTTP HTTPS problem
I'm using a standalone container, and I find that everything works transparently (only one session) if I resort to hard coding the scheme. Right now, I'm doing this in the Struts-config. forward name=standard path=http://data.wxxi.org/wxxi-gavel/register/logon.jsp/ forward name=secure path=https://data.wxxi.org/wxxi-gavel/register/logon.jsp/ which are called with code like this in the action String url = null; if (secureMode) { url = mapping.findForward(secure).getPath(); ActionForward actionForward = new ActionForward(url,true); return (actionForward); } else return (mapping.findForward(standard)); where I'm tracking secureMode as a session attribute. If they login or register in secure mode, I end the process with a [[ BIG LINK ]] that routes them back to the http scheme. Messy, but it gets me through the day. I haven't had time to think about it, but it seems to me that we should be able to work this into the custom tags. Struts is very good about automagically converting the links when you switch schemes, so it seems to me we should be able to force the tags to one scheme or the other, when appropriate. Michael Wilimsky wrote: hello everyone... i still couldn´t find a solution on how to switch from let´s say http://localhost:myport/myapp/something.jsp to https://localhost:mysecureport/myapp/somethingelsethatneedstobesecure_oreven thesamepage.jsp while retaining resp. cloning the content of my sessioncontext... i am using the urlrewriting-method to manage my sessions as far as my experience tells me i get two different sessionIDs for http://localhost:myport/myapp/something.jsp and the corresponding https://localhost:mysecureport/myapp/something.jsp how can i copy the sessioncontext to the secure side and vice versa? michy
Re: still fighting HTTP HTTPS problem
ActionForward actionForward = new ActionForward(url,true); The forward here is a bit of a misnomer. Using true forces a redirect. Ian Kallen wrote: Are you saying that an http request can be forwarded to an https request? That doesn't make sense; if the browser doesn't have an https session setup, the server can do whatever it wants to resolve the request translation. You have to redirect to go from an http request to an https request.
Re: textarea and wrap
The Struts Action works through introspection. It doesn't know (or care) whether the value in a form was rendered by a Struts custom tag or not. This means if you use a standard textarea tag in your form, and give it a name that matches a property in your form bean, Struts will use that attribute just as if it had been rendered by a html:textarea tag. After all, this is all the Struts html:textarea tag does. To seed the textarea from the form bean, you could code something like textarea name=article rows=15 cols=60 wrap=softbean:write name=scriptForm property=article//textarea And everything else will be automagical again. What I would like to propose and contribute in the 1.1 timeframe is the addition of a options attribute to all the HTML tags, so we could code something like html:textarea options=wrap=soft rows=15 ... and have Struts add wrap=soft to the tag without interpretation. This would make all the tags extensible for non-standard properties. William Jaynes wrote: I usually need 'wrap=virtual' as an attribute for my textareas. It isn't part of the HTML spec, but it's supported in both Netscape and IE, and it's pretty useful. I wonder how people are dealing with the lack of a wrap attribute in the struts textarea tag.
Re: Determining odd-even table rows
Many people like the pager tag at jsptags.com. http://jsptags.com/tags/navigation/pager/ For more on alternating colors, see http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayQuestionAnswer/action/SetAll/project_id/2/faq_id/36/topic_id/207/question_id/821 though most of these answers resort to scriptlets. Bill Pfeiffer wrote: My goal here is not to do any scriplets. I'm putting together a set of tags to help our web guy build pages using only tags.
Re: REPOST: HOW TO: check for null property value
Try logic:present name=myBean property=item1 Matthew O'Haire wrote: How do I use the logic tags to check for a null property value on a bean and include/exclude HTML segment on that basis? I have a bean in the session that holds references to other beans. If the references are not-null then I need to display some info about them. I've tried using logic:notEqual property=myBean.item1 value=null and logic:present name=myBean.item1 but to no avail. Can anyone help me out here. Thanks. Matthew O'Haire Technical Manager email: [EMAIL PROTECTED] IT Project Services Solutions · Development · Integration · Support · People · 44 Benson Street, Toowong, Queensland, Australia. 4066 ph: +61-7-3870 7070 fx: +61-7-3870 3480 www: http://www.trysoft.com/ e-mail: [EMAIL PROTECTED] Please Note: This document (including attachments) is only intended for the addressee/s and may contain privileged or confidential information. Unauthorised use, copying or distribution of the document or any part of its contents, is prohibited. If you receive this e-mail in error please notify us by return e-mail or telephone. Any views expressed in this Communication are those of the individual sender, except where the sender specifically states them to be the views of Trysoft Corporation Limited. Except as required at law, Trysoft Corporation Limited does not represent, warrant and/or guarantee that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Determining odd-even table rows
I'd be extremely interested in a tag that rolls through a RowSet. The Jakarta DBTags work directly with result sets. I'm not aware of any support for RowSets there. So, you may want to start by contributing it there, perhaps as an addition to the existing DBTags library. Meanwhile, providing direct support in Struts for RowSets would be a Very Good Thing. If we can enhance the HTML tags to work as easily with RowSets as they do with ActionForm beans, we could eliminate a layer of classes in many cases. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Determining odd-even table rows
That sounds cool, Bill. I'm making extensive use of RowSets now myself. Right now, I pump the RowSet into a bean or collection of beans and pass that to iterate or a form. I use a custom constructor for the bean with a parameter for each property so that I can pass everything once. On the 1.1 list now is enhancing iterate to recognize RowSets (and XML) so that these can be used in addition to a collection of beans. In working with RowSets, I keep coming back to the idea that in practice my RowSets and my ActionForm beans share same properties. RowSets can also set and get any column as a String, which is an essential part of being an ActionForm bean. RowSets also have many built-in data conversion methods that most applications need. So it just seems to me that if we are going to extend iterate to support RowSets, why not extend the other custom tags too? Why not an ActionRowSet with a reset and validate method for the action to call? I haven't researched the code yet, but off-hand the real trick would seem to be creating a RowSet from scratch, so that it could be populated outside of the JDBC command. But since Cached RowSets allow you to create and populate columns, we should be able to do that too. The Sun documentation mentions that RowSets are suppose to be JavaBeans, and I did try to feed them to iterate, but it doesn't seem to work. If you would like to send me the source you have so far, perhaps we can work on refactoring it together. Bill Pfeiffer wrote: Ted, So far, my work with setting up a RowSet rather than a ResultSet consists of the following: 1. Reworking the DBTags ResultSetTag (and all nested tags) to use javax.sql.RowSet instead of ResultSet. 2. Reworking the ResultSetTag to grab a RowSet object out of a given context (page, request, session, application), instead of relying on a parent tag generated Statement. The idea here is that some other code (servlet, struts action, etc) will create the result set and shove it into the scoped attribute. This doesn't really constitute much original work on my part. But it does allow me to create the RowSet in the EJB layer. I have created a session bean that will take a sql string, create the RowSet, and pass it back. I can pass this along, however, I think it would be in the best interest of the taglibs community to somehow integrate what I have with the current result set implementation. In all actuality, I don't HAVE to use a RowSet. Since RowSet implements ResultSet, I could have just modified the ResultSet tag to somehow 'know' when to use a parent Statement or get an existing result set from the pageContext (which is what I do now). As far as struts is concerned, I would be curious to know how you would see RowSet tags integrating with it. Is the idea that you would map or bind a struts form field to a RowSet column? I'll get started by joining the taglibs-dev mailing list. I can send you my source set for the RowSet stuff I've done, but it is far from ready for prime time. Let me know, Bill
To SSL and back again
Craig R. McClanahan wrote: You can calculate an absolute URL for this web app, based on things like request.getServerName(), request.getContextPath(), and so on. So, one way to do this would be to have an action that calculated the new absolute URL, wrapped it in a new ActionForward with the redirect property set, and return that to the controller servlet. It looks pretty much like what you quoted in the mail message. I embedded the absolute URL in the config to get started. If seems like the best overall approach right now, I'll work out calculating it at runtime, and smoothing out the procedure, and update the SSL FAQ. NOTE: Because the controller servlet calls encodeRedirectURL() for you on redirections, sessions should survive across this transfer whether or not you are using cookies. Yes, they do, which is very cool. See also http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg07841.html
Re: Struts and Sun's J2EE Patterns
I've started a new piece about building a Strut's application from scratch. I'm now thinking about how to work the J2EE patterns into what I started. The work in progress is at http://husted.com/about/struts under Coming Soon. Any notes or ideas people might have about this would be appreciated. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Production uses of Jakarta STRUTS 1.0
Deadman, Hal wrote: The links below are from http://www.husted.com/about/struts/. Also, http://data.wxxi.org/wxxi-gavel which I just added to the list. We've been running an online auction for several weeks now, and it will continue through the end of June. The source for this project will then be released as open source. We've received 40,000 bids on nearly 5,000 difference auctions. Performance has been excellent. If you're just getting started with Struts, keep an eye out for my new Strut-by-Strut article. There's an early release at http://www.husted.com/about/struts/ under Coming Soon. -Ted.
Re: SV: Any hosting sites that use Struts?
Here are two other Java hosting sites: Imagine Internet Services - www.imagineit.com Web APP Cabaret - www.webappcabaret.com (free, Tripod-style ISP) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
OT: LIKE with PrepareStatement
Not directly Struts related, but anyway, I'm trying to use LIKE '%?%' as part of a prepared statement, but it's coming back invalid array index. Apparently, the symbols are hiding the question mark. Anyone know a way around this, besides doing the substitution and escape-coding the old-fashioned way? -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Using Javascript to cancel submit?
If you want the JavaScript to cancel the submit, you need to return false somewhere. Struts can also watch for these in the Action, either using the isCancel() method, or by looking at the label of the button pressed. Struts doesn't write the HTML for tables, and could not affect the sizes of your table rows, except to the extent that the browser adjusts the row sizes to fit the instant data. The Struts custom tags (like all others) simply substitute standard HTML for the custom tags on their way to the browser, and leaves everything else alone. You can view the source to see what the browser sees. Struts isn't otherwise involved in how your page renders. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Redirecting to secure server (ie from http:// to https://)
This is still a very messy area. I ended hardcoding some strings in a production application, but there solutions that would mitigate this, so you only have to hardcode the scheme in your struts-config file. See To SSL and Back Again http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg01357.html http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg01361.html http://www.mail-archive.com/struts-user@jakarta.apache.org/msg08028.html http://www.mail-archive.com/struts-user@jakarta.apache.org/msg07850.html http://www.mail-archive.com/struts-user@jakarta.apache.org/msg07796.html http://www.mail-archive.com/struts-user@jakarta.apache.org/msg06454.html We definatley need to document the best-practice for doing this, as soon as we figure out what that is ;-) Michael Mok wrote: To those who have done it Can you advice on how you manage to redirect the http request from http to https? I have following scenario (typical of a shopping site). 1) User search and place item into shopping cart (eg calls http://www.acmeshop.com/addtoshoppingcart.do) 2) addtoshoppingcart.do do some processing and redirects user back to shopping search page (eg http://www.acmeshop.com/shoppingsearch.jsp ) 3) User clicks on the check out page URL. (eg calls http://www.acmeshop.com/showshoppingcart.do and return the results to http://www.acmeshop.com/showcartcheckout.jsp). 4) User clicks on make payment. On the shwowcartcheckout.jsp, I need to be able to set the form action attribute to call https://www.acmeshop.com/makepayment.do (where makepayment.do will redirect to the https://www.acmeshop.com/enterpaymentdetail.jsp). The form action attribute on the enterpaymentdetail.jsp will call https://www.acmeshop.com/processpayment.do ) What I am trying to find out is how do I set the https:// in the form action attribute of showcartcheckout.jsp. The form tag does not have any attribute will will create the https://... string. Do I have to hard code the form action in this page? Or am I total off the track? Thanks in advance Michael Mok -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Proposed feature: Bean property transformations
What I'm missing is a comprehensive, general package for converting data types and formatting properties for presentation. Most of this functionality is available somewhere in java and javax space, but it's spread around. What would be most useful, I think, is a single, generic package that provided (1) validation of Strings using regular expressions (a la David Winterfeldt's servlet), with direct support for native and JDBC datatypes, (2) binary to String and String to binary conversions for all native and standard types, and support for adding others, (3) given a formatting specification (00#.##) and data of any supported type, return a formatted presentation String, (4) support for locale-senstive transformations with (3), (5) support for extending the formatting specification for unusual circumstances, and (6) provide simple date-calculation methods and a countdown presentation format (seconds, minutes, hours, or days from now until then). We could then use this helper object during the validation cycle to convert incoming Strings to the other types needed by business-logic objects, AND pass through the functionality from a bean:writeTransform tag, that could pull a property from a given bean, transform it, and return a formatted String for direct use by the view. If there is not something like this already out there, I've very interested in getting started on this package, since I really, really need it for my own projects. Could be a nice addition to the Commons ... I'm cross-posting this to Struts user in case someone can suggest a package that already provides this functionality. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Ron Smith wrote: I've been thinking of implementing this feature lately and I haven't seen it proposed on this list yet. Any comments? Summary: Provide a means to flexibly plug in transformations that could be applied to JavaBean properties for presentation in a JSP page. What transformation to apply to which JavaBean property is specified in the Struts JSP tags (e.g. bean:write). Transformations are Java classes that are responsible for taking a JavaBean property or any other Object, applying whatever transformation, and returning the transformed Object for presentation in a JSP page. Some example transformations are to format a date in a specific format, format decimal numbers, or even to sort a collection in a particular order before iterating over the collection's objects. Motivation: Separating business entity code from presentation-specific code is a good thing. Consider a business entity class called Order. If we want to display the orderPlacedDate attribute in 4 different date formats on a JSP page, we could add 4 different methods to the Order class to support these 4 different formats. But we quickly end up with a very cluttered Order class and the Order class is too coupled to the presentation details. One approach I've used is to create presentation wrapper classes which hold references to the business entity objects and are responsible for all of the presentation specific formatting. The JSP pages access the presentation wrapper classes and not the business entity classes. For sites that access many different business entity classes, this can become very tedious. A better approach would be to be able to plug-in specific types of presentation transformations to be applied to specific JavaBean properties that are to be displayed in a JSP page without having to create unecessary wrapper classes. Details: Transformations are coded in transformation classes, all of which implement a Transformation interface. This interface has one public method: Object transform(Object inObj) This method is responsible for applying whatever transformation is needed to the passed in object and returning a transformed version of the object for presentation in a JSP page. The transformation objects would be created at initialization based on the configuration file, and could be initialized with some parameters from the configuration file (e.g. the date format string to be used for a date transformation). Each transformation has a name associated with it, and is registered in a hash table based on the name. Some of the Struts custom JSP tags would be modified to take an additional transformation parameter which indicates what transformation is to be applied. For example: bean:write name=order property=orderPlacedDate transformation=shortDateFormat/ In the above example, the orderPlacedDate property is retrieved from the order bean, then the Transformation named shortDateFormat is looked up in the transformations registry, and applied to the property. Whatever was returned by the transformation is what gets displayed on the web page. Another benefit is that because
Re: Proposed feature: Bean property transformations
Harris, Andrew S wrote: A component would be able to hold a text value and a data value. The text value could hold the value entered by the user, prior to validation, then this could be played back to the user if validation failed on that component. If validation succeeded, the data value would be updated, then the text value would be replaced by the formatted value, using the data value and the formatter. This is a good design pattern, and one we can use with Struts today. In the ActionForm bean, define two properties, one for the text value and one for the data value. If validation succeeds, convert the text value to the data value, and (optionally) update the text value to match your preferred formatting. Though, with a general conversion/transformation package, we would really only need to store the desired data value since we could transform it again later when the value was accessed for presentation, perhaps via a bean:writeTransform tag. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Strut by Strut
There's a working draft of a new article about building applications with Struts available at http://www.husted.com/about/struts/ under Coming Soon. It's no where near complete, but I would be interested in any feedback on the early release. I'm especially interested in whether the design patterns discussed here would work well with the way people are now using EJBs. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: visual changes based on state
You can either 1. Route users to different pages based on their state, or 2. Deliver the current state to the presentation layer in the form of JavaBeans that the Struts logic tags can test. logic:present name=logon ... -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Jonathan wrote: Just wondering how you all were implementing visual changes based on state. Ex. when a menu button says logon before the person loggs on, and then says logoff after the person has logged on. How are you doing this switching based on state? In the action? in the template? Or are you all usingSCRIPTLETS (Ay!!!)
Re: Problems with struts and resin
I haven't had this problem myself. I've kept busy Struts applications in play for several weeks without any unscheduled downtime under Resin. Matthew Heaton (Software Engineer) wrote: I'm trying to deploy a couple of struts apps on resin which I've deployed successfully on Weblogic and on Tomcat. It appears the server tries to call the init method in the ActionServlet over and over eventially causing the server to run out of memory and crash. I've seen also seen this behavior also using some of the sample struts apps though not to the point of crashing the server. I haven't gotten much help on the Resin side of things, so does anybody on the struts list know a work around.
Re: Newbie to struts - jdbc/dbtags
You can configure Postgresql in the struts-config.xml, and then use the same datasource with the Jakarta Taglibs JDBC. Works like a charm. Struts uses org.apache.struts.action.DATA_SOURCE as the datasource identifier (see Action.java). kuma.cra wrote: Hi, im a newbie to struts basically applying the examples and reading the documentation (mvc). I am about to connect a psql datasource (Postgresql, luinx OS) database to a struts mvc utilizing a database URL . Thus is there a ActionForm example and what level if i have to create a ActionForm class i.e /WEB-INF/classes/custom/ActionForm or can i create a package above WEB-INF as at the moment i am creating/modifying examples from the taglib's and packaging them under mt Struts-bbnpa (my re-named struts app's. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Multipage forms and validation
When the time comes, David's Validation servlet would get my vote. Unfortunately, we need to get 1.0 out the door before voting on anything like this. Beta 3 is counting down now, so we only talking a couple of weeks now. In any event, what features Struts, or any Jakarta product, will offer in any timeframe, will always depend on what people contribute. No one here can say hey you, go implement this feature. What gets implemented depends on what people choose to contribute, and David has stepped forward with a very fine contribution. One of things that make it a fine contribution is that the Validator servlet snaps right into the framework, without altering anything else. So you're free to use it, or not to use it, or to use something else. Which is as Struts-esque as you can get ;-) So I'd say use it .. I do! Niall Pemberton wrote: David, I see your on the 1.1 ToDo list as a volunteer for Standard Validations and Client Side Validations - is it likely your validation framework is going to be adopted for Struts - and if so how close is what you're offering now to what Struts will have in 1.1? I'm just wondering whether to plough on with what we've got or wait for what might be coming in Struts. Niall
Re: Managing resource life cycle during request
Following the rendering? By Struts? None. It's a straight JSP (or other view technology, like a Velocity template). Generally, things go into the request, and are disposed when the request is disposed. There's an enhancement to the iterate tag in the works that uses a RowSet directly. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg07910.html Jeff Trent wrote: That's sounds okay for simple forms, but I'd rather not serialize objects from a multi-row recordset to a collection every time. Too much overhead! Let me put the question another way, in Struts, what method on the form or action class gets called following the rendering of the input page? I'll check source code now for this answer... - jeff
Re: Managing resource life cycle during request
I doubt that overriding ActionServlet.process() would work. The controller sends back the response, and it's done. It's then up to HTTP to deliver the view, usually a JSP. Any clean-up routine would have to be the responsibility of the view, which puts you into the scriplet zone. Jeff Trent wrote: Well, it looks to me that short of overriding ActionServlet.process(), there is no way one can clean-up resources after the page has been rendered...
Re: newbie to struts - confirm hierachy( packages - webapps)!!
Some people like to keep the source Java files at a separate location, and then have Ant copy them over to the classes directory, but mixing the class and java files in the same folder works too. Personally, when using a package hierarchy for my classes, I tend to just name things .\logon\Form.java But, yes you should either put your packages class files below the classes directory, or in a JAR in the lib folder. For development at least, you probably just want to put them under classes. We put these under the WEB-INF folder so that they cannot be directly accessed by a client program (e.g. Web browser), only by the application. Chuck Amadi wrote: Hi, i have constructed a web app within my file system as follows:- C:\jakarta-tomcat-3.2.1\webapps\struts-bbnpa\WEB-INF\classes\logon\LogonForm.java The struts-bbnpa is were im placing all my work. thus the examples custom and logon packages are beneath my classes directory. Thus is this the correct procedure as im about to venture into JDBC Project (Postgresql) and im not sure weather the packages are one level above \WEB-INF dir. Any suggestions and confirmation extremely welcomed. Cheers inadvance. Chuck (Graduate Systems Programmer) --
Re: Newie question
You could take a look at Part 2 of Strut by Strut, under Coming Soon at http://www.husted.com/about/struts/ I'm working on some generic Access, Search, and Result actions there. Though, the usual approach would be that control goes to an action that manages the data retrieval and forwards the result to another JSP for display. [JSP] - [ACTION] - [JSP] ... -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Torsten Terp wrote: Hi, Im I have just started using Struts and the idea of the framework seems great!! I could however use some help getting started the right way!! I want to do as folows: A jsp page with an input fields takes as input a string used to perform a seach in a database. E.g., a substring of the name of some customer. Control is forwarded to another jsp that displays the results, e.g., the customernames containing the substring provided in the input field above. These customernames should be displayed in a html:select Selecting one of the customers will result in another search which retrieves all data for that particular customer and displays it in another frame. Im thinkind this is a pretty generic setup, so my question is if anybody has example code of this. Im using the jBoss application server as the model, so its not the database pooling from struts im after, its the control flow and populating the jsp's It would be greatly apreciated. Thanks in advance... ^torsten
Re: Action before loading a page
Both JSPs and Actions are called by a HTTP request. It can be helpful to think of Actions as invisible pages that respond to a request with a visible page. Any place where you request (or load) a page, you can request an Action instead. So however you load another file in the second frame, you should be able to request an Action instead. Your tag might also include the database ID as part of the request (/Action.do?ID=XXX), so you don't have to bother with the session. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Jack Xu wrote: I have a frameset of 2 frames. The first frame loads a JSP file containing a custom tag. The tag retrieves a list from my database and displays it as a drop down list. The tag then marks the first entry in the list as default and then load another file in the second frame. In stead of having a static welcome page in the second frame, I'm wondering if there's any way to perform this: 1. The custom tag finishes in the first frame. It puts some kind of ID in the session. 2. Before the second frame loads, a struts action is executed. The action retrieves information from my database based on the ID the custom tag put in the session, construct a form containing the information returned from the database and forwards to the JSP page to be loaded to the second frame. The JSP load info from the form so that I have default page with information loaded from the database. Your help is very much appreciated ! -- Jack Xu March Networks (416)977-7007 x 308 Email: [EMAIL PROTECTED] --
Re: Problems with logic:equals tag, session timeouts
There has just been a discussion of adding an additional parameter to logic:present to tell it how to cope with empty Strings. Right now, it expects empty Strings to be represented as null. See http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg01451.html , et seq., for more. The ProcessSession idea is interesting, but any discussion of this should be moved to Struts-Dev. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Andreas Prohaska wrote: Hi, during the development of one project using Struts I experienced some problems with the logic:equals tag. What I want to do is to compare a string in an ActionForm to the empty string. As far as I understand it, I would have to use two nested tags like logic:present name=formBean property=prop logic:equal name=formBean property=prop value= ... code fails here /logic:equal /logic:present It seems as if the servlet API tries to convert the empty string to some datatype but this obviously fails (or better is not possible) and so the null value is still assigned to the value attribute in the CompareTagBase class. And this class throws a NullPointerException when the condition() method tries to convert the value into different types (line 180). Has anyone already thought of a logic:isEmpty tag that looks if a value is null or empty? Is there are public need for this tag? The other problem seems more serious! If the user waits for a long time, the session gets timed-out. When the new request arrives, a new session will be created and, in my case, an ActionForm instance will be put into the session context (since I was in the middle of filling out a form). Now everything looks fine to the application, but it is not since the ActionForm did not contain the values I have entered but the default ones :-( There is no hook into the session management (as I have seen). The first method that accesses and implicitly creates the session is processLocale() in the ActionServlet. Shouldn't we introduce a method like processSession() at the very beginning of the process() method to provide a possibility to intercept session deprecation and creation. In my case it would be sufficient to redirect to user to a special your session has expired page. Any comments are welcome! Andreas Andreas Prohaska Mail: [EMAIL PROTECTED] Apeiron GmbH Tel : +49 (089) 278257-40 Hohenzollernstr. 81 Fax : +49 (089) 278257-49 80796 Muenchen
Re: Please help with logic notPresent
Be sure you've included the logic tld. The I am here would display regardless, since the browsers ignore tags they don't understand. Alex Colic wrote: Hi, I have an object in the session that if it is not there I want to display and error msg to the user. My error code is as follows: logic:notPresent name=VendorResourceList scope=session font color=red bean:message key=error.fatal / /font /logic:notPresent I would think that the above code would show the message if the VendorResourceList object is not found in the session but the error msg is always displayed even though the below code snippet works. TABLE TR TD bean:message key=prompt.vendorNumber/ /TD TD logic:present name=VendorResourceList scope=session I am here /logic:present /TD Amy help in understanding this is appreciated. Alex
Re: How to remove history list?
Alas, it is not permitted. SHROM,BENJAMIN (HP-USA,ex1) wrote: Hello, Does anybody know how to remove history list from browser using JavaScript? Benjamin Shrom.
Re: Proposed feature: Bean property transformations
I agree. The primary fields on an ActionForm must be Strings, ActionForms should not be used to store persistent data, and the beans used to store persistent data should use appropriate types. The peristent data beans should not have to worry about data conversions, and so that task should be performed by a helper object. But encapsulating the helper object within the ActionForm can be a valid approach, since converting the String to a native type may be considered part of the initial validation. Once this is done, the persistent data bean can call a getPropertyInt or getPropertyDate method to retrieve the native Property type (and then perhaps perform any business logic validations). It's just a matter of whether you prefer converting the data in the Action or in the ActionForm validation method. A reuseable helper class could be implemented in either case. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Oleg V Alexeev wrote: What reason to store text values and data values in ActionForm? I think that more flexible approach is to use ActionForm with text only fields and data bean with native types, not String. In this case we can name all corresponded fields in data bean with same names as for ActionForm and use convert methods under it, for example, or use another convert methods. We can convert text values to/from with one of the ways - 1. Perform conversion of all fields in some method in ActionForm, for example import/export. 2. Make it in every setter/getter. 3. Write special helper class to perform conversion - in this case more flexible approach can be used - one helper can handle multiple sources and targets. -- Best regards, Olegmailto:[EMAIL PROTECTED]
Re: input in XML config
Could you create these request scope beans as properties of the ActionForm? David Noll wrote: Max, I don't know if it's the official way to do it, but in my ActionForm's validate() method, I call mapping.setInput() with the full path of the original Action. An important thing to note is that if your Action class pre-populates an ActionForm for the page, you should check for the ActionForm's existence before populating it. All that said, it does seem a bit cumbersome to go through all that merely to return to a dynamically generated input page if there are form errors. Does anyone on the list know of a cleaner way to achieve this? David -- David Noll, Public Digital [EMAIL PROTECTED] -Original Message- From: LORENA MASSIMO [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 05, 2001 6:37 AM To: '[EMAIL PROTECTED]' Subject: input in XML config Hi, in an action mapping i'd like to reexecute the complete action instead of a simple jsp when the validate method of the form fails, because i need to create some beans having request scope So my question is... Is it possible to have an action in the input fiele of a mapping instead of a simple jsp? thanks Max
Scratch RowSets
The documentation for the Early Release of CachedRowSets mentions that Because both a CachedRowSet object and its metadata can be created from scratch, a component that acts as a factory for rowsets can use this capability to create a rowset containing data from non-SQL data sources. has anyone here tried this yet? The idea being I would like to transfer incoming properties from an ActionForm into a scratch RowSet, and use that as the value object. (Perhaps within a wrapper or a facade so business logic methods can be added.) There will be expanded support for RowSets in 1.1, and I wanted to get started on some support utilities / design patterns before looking at what other modifications will be needed. I put together a quick Iterate wrapper that works fine with a returned RowSet, but also need to create a new RowSet from scratch to close the loop. I guess the thing to try is to create a MetaDataRowSet object and pass that to a new RowSet (instead of making the SQL call), and then see if I can insert a row. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: ActionForm/Action with edit mode
If I understand the question, all you have to do is change the form's action to insert or update as the case may be. A good way to do this is to have a task parameter that you would pass to a single action designed to handle both cases. You can do this dymamically using (where key=0 means we're inserting a new record). logic:equal name=myForm property=key value=0 input type=hidden name=task value=insert /logic:equal logic:notEqual name=myForm property=key value=0 input type=hidden name=task value=update /logic:notEqual For an update, visit an Action first, select the record, populate the form, and forward to input. John Hogan wrote: All, I have a situation where it is desirable to use a form/page for both adding new info and editing existing data. The new info scenario is straight forward struts ActionForm/Action classes. What I'm wrestling with a bit is the edit scenario. I'm wondering if I can stay within the struts framework and still do something like entering a page in edit mode and have it displaying existing user data? It seems this should be possible because that's exactly what the page does for error handling. Has anyone else tackled this one yet? TIA. JohnH _ Get your free E-mail at http://www.ireland.com -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Scratch RowSets
Good reference, Steve. So, given a CachedRowSet, it's easy to snag a data set and puruse it at your leisure, since the database connection is automatically closed by the RowSet. I've been using them for retrievals extensively, and they are an absolute pleasure to use. CachedRowSets are also mutable so you can update, deleted, and insert rows rows remotely, and (if your DBMS supports transactions) send the changes back to whence they came. Now, the next step is to create a RowSet from scratch to insert a new record to a new table. Given this, there doesn't seem to be any reason to have a seperate value object bean for a data set that is coming from or going to a persistent store. I'm going to take a whack at this tonite, so anyone who'd done this and has any pointers, please let me know! Steve Salkin wrote: Take a look at sun's CachedRowSet now available in early release. http://www.javaworld.com/javaworld/jw-02-2001/jw-0202-cachedrow.html S-
Re: Problem with nested html:form
Struts doesn't have anything to do with it at this point; it's all up to the client (e.g. browser). The client eventually sends a request to an Action, and then Struts can go to work again. The only option when HTML doesn't meet your needs is to move to an applet. Marc Eckart wrote: I do not believe that you are allowed to have nested forms in html (though correct me if I'm wrong!). Dave But we need something like nested forms, because we have actions for a list of objects and actions for a single one of these objects. Do you have any idea how to realize it in an other way. Marc
Re: Moving from Struts 1.0b1 to Struts 1.0b3
Could you subclass the Actions so that they can reuse the validation code? Be sure to register this at Bugzilla if you believe it is a bug. Graeme Miller wrote: Unfortunately in my case the controller is not reused but the form bean is, meaning if I was to do this validation in the controller I would have to do it for every Action that uses this bean. Thanks for the suggestion but it looks like I will have to stay on b1 until a more stable release of Struts comes out (maybe the 1.0 final release?)
Re: Nested logic:iterate tags ServletExec
Be sure to report this to your vendor; people are starting to use Struts as a compatibility test of their containers with the specifications ;-) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Roman Fail wrote: I can second your problems with nested iterate tags using ServletExec. We are running JDK 1.3, ServletExec 3.1, Win2k/IIS 5.0. I posted something about it a few weeks ago but no one replied. It appeared to me to be some sort of recursion issue, where the body of the inner iterate tag was evaluated and output prior to the outer iterate tag. We ended up just using a scriplet for the outer loop and an iterate tag for the inner loop. I havent' seen any other glaring problems with the custom tags running under ServletExecyet. ServletExec 4.0 is in beta right now, perhaps that will solve the problem? It's supposed to support Servlet API 2.3 and JSP 1.2 (as soon as they are released!). Roman -Original Message- From: Amos Shapira Sent: Wed 6/6/2001 8:58 AM To: '[EMAIL PROTECTED]' Cc: Subject: RE: Nested logic:iterate tags Hi, I just had bad experience with ServletExec 3.0E and nested iterate tags. When I changed the inner iterate tag back to scriptlets things startted working again (the code worked fine under Tomcat 3.2.1). Is anyone aware of problems with NewAtlanta's handling of custom tags in general or Struts in particular? My env: 1. Sun JDK 1.2.2_5/6 2. New Atlanta ServletExec 3.0E 3. Windows 2000 Professional or Sparc Solaris 2.6 4. Jakarta Struts and Jakarta Taglib Thanks, --Amos Name: winmail.dat winmail.datType: application/ms-tnef Encoding: base64
Re: Problems with CSS and TEMPLATE !!
This doesn't seem to match what was given in the other message. I believe the other cited a /tlds/ folder. Chuck Amadi wrote: Hi this is what's in my xml file beaneath /webapps/struts-bbnpa(myapp)/WEB-INF/xml taglib taglib-uri/WEB-INF/struts-template.tld/taglib-uri taglib-location/WEB-INF/struts-template.tld/taglib-location /taglib Jon.Ridgway wrote: Part 1.1Type: Plain Text (text/plain) Encoding: quoted-printable
Re: Scratch RowSets
Ted Husted wrote: Now, the next step is to create a RowSet from scratch to insert a new record to a new table. Given this, there doesn't seem to be any reason to have a seperate value object bean for a data set that is coming from or going to a persistent store. In case anyone is interested, all I did was select a record that wasn't there (primary key=0), and, bingo-bango, CachedRowSet created an empty but valid RowSet, ready to receive new rows. So, now instead of duplicating the data in my own set of properties, I'm using the CachedRowSet's storage locations directly through a thin wrapper with conventional mutators and accessors. This reduces the overhead of redundant storage, retains all the flexibility of a standard value object, is compatible with existing code bases, and can also leverage the type casting built into RowSets. [ DBMS ] - [ RowSet ] - [ ActionForm - RowSet ] - [ DBMS ] - [ RowSet ] - [ JSP or ActionForm ] And, of course, a RowSet can be treated just like a ResultSet in a JSP, but without the overhead of an open connection. A full treatment will follow, but here are some snippets. ResultValue.java // a RowSet Iterator wrapper subclassed as a // value object wrapper around a CachedRowSet (whew!) /** * Return the account */ public String getAccount() { try { return values.getString(account); } catch (SQLException sqle) { return null; } } // .. more property wrappers /** * Bulk mutator for data transfer from another object */ public void set( String bid, String lot, String amount, String account, String precedence, String bidType, String bidFrom, String pickup ) throws SQLException { values.updateString(bid_key,bid); values.updateString(lot,lot); values.updateString(amount,amount); values.updateString(account,account); values.updateString(bidder_key,precedence); values.updateString(bidType,bidType); values.updateString(bidFrom,bidFrom); values.updateString(pickup,pickup); } /** * Convenience constructor to set internal RowSet */ public ResultValue(RowSet values) { super(values); } Result.java // encapsulates instance of ResultValue with other // helper properties and serves as a data access object public int insert() throws SQLException { ResultValue resultValue = (ResultValue) getRows(); // MySQL can't insert via a RowSet, so use a Statement instead return Statements.bidInsert( resultValue.getLot(), resultValue.getAmount(), resultValue.getAccount(), resultValue.getPrecedence(), resultValue.getBidType(), resultValue.getBidFrom(), resultValue.getPickup() ); } Access.java (an Action) // selects appropriate classes and // methods for given request task // -- INSERT -- if (task.equals(insert)) { // Instantiate blank RowSet result = thisResult.select(); // key=0 resultValue = (ResultValue) thisResult.getRows(); // Create new row in empty set resultValue.moveToInsertRow(); // Transfer data resultValue.set( thisForm.getBid(), thisForm.getLot(), thisForm.getAmount(), thisForm.getAccount(), thisForm.getPrecedence(), thisForm.getBidType(), thisForm.getBidFrom(), thisForm.getPickup() ); // Execute insert command for this Result object result = thisResult.insert(); // Analyze outcome if (result==0) { message = error.database.error; } else { message = record.inserted; } } When retrieving multiple rows, the Result object (a proper JavaBean) can be inserted in the request, along with it's RowSet. I wrote a quick Iterator wrapper for RowSets so it could be used by the iterate tag. Front to back This gives you a pattern like: // Search.perform // Select command if (task.equals(lot)) command = Commands.BID_SEARCH_LOT; if (task.equals(account)) command = Commands.BID_SEARCH_ACCOUNT; // Ready result Result thisResult = new Result(key,task,command); // Retrieve data set thisResult.execute(); // Queue for view request.setAttribute(result,thisResult); // Result.execute public void execute() throws SQLException { rows = new
Re: ACtionError Issues
You may need to set up another Action Mapping with validate set to false, but both could point to the same resources. Or, you may be able to just use department.jsp as the input resource. Prabha Desai wrote: i have a page which calls an Action Form based on the action. Within the page, i have logic to view detail or not. I am trying to saveErrors and output them back to the page, but I keep getting an infinite loop. Error: path= :action: Processing a POST for /department path= :action: Looking for ActionForm bean under attribute 'departmentForm' path= :action: Recycling existing ActionForm bean instance of class 'com.netvendor.nvat.struts.forms.DepartmentForm' path= :action: Populating bean properties from this request path= :action: Validating input form properties path= :action: Validation error(s), redirecting to: /department.do my main page is department.jsp The action to view is viewItem on which I need to show the errors.. Input on the struts-config page is department.do. The initial page is department.jsp with action of viewList. This is already within the Action class. if (!errors.empty()) { saveErrors(request, errors); saveToken(request); return (new ActionForward(mapping.getInput())); } I need to write out errors if the user has not filled in all the items. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: problem with invoking struts-template!!
I don't believe that the JSP templates and CSS files are strongly coupled. I believe the browser applies the CSS, not the template. You might just want to move the CSS up to where Tomcat is looking for it. Chuck Amadi wrote: I have created a index.jsp that has the content of our company web-site, thus the index.jsp is located C:\jakarta-tomcat-3.2.1\webapps\struts-bbnpa\index.jsp Thus i have set up the tag libraries in the web.xml file and referenced the taglib at the top of my index.jsp page as below.Nevertheless i recieve a Not Found Error.My struts-template is located C:\jakarta-tomcat-3.2.1\webapps\struts-bbnpa\WEB-INF\struts-template\css\bbnpa.css %@ taglib uri=/WEB-INF/struts-template.tld prefix=template % Not Found (404) Original request: /struts-bbnpa/css/bbnpa.css Not found request: /struts-bbnpa/css/bbnpa.css Any suggestions please . -- The views expressed by the sender of this message don't necessarily represent those of Brecon Beacons National Park Authority. This message is intended for the addressee(s) only and is sent in confidence; if you receive it in error, please can you let us know (at [EMAIL PROTECTED]) and then destroy all copies. Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog. Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn mewn camgymeriad, a fyddech gystal â rhoi gwybod i ni (yn [EMAIL PROTECTED]) ac yna dilëwch bob copi. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: FW: Scope of the form
1. Yes. Using the standard forward or redirect Servlet services. 2. It is forwarded to the JSP or Action specified by the input property. 3. The form is disposed when the request is disposed, which would happen after the JSP was rendered. Joyce Tang wrote: -Original Message- From: Joyce Tang To: '[EMAIL PROTECTED]' Sent: 6/7/01 9:28 AM Subject: Scope of the form I would like to verify my understanding on this thing. Please let me know if it is correct. Thank you very much in advance. 1. Whenever the Action do a forward, the request is being forwarded. 2. When the error happens, the request is forwarded back to the same JSP 3. If I define the scope of the form related to the Action class as request, then before the JSP page is rendered, the form is still in the request, but after the JSP page is rendered,the form is taken out from the request? Thanks a ton. Joyce
Re: Scratch RowSets
I've seen the same problem with updating via the CachedRowSet, but had been blaming MySQL's lack of transaction support (with the default tables at least). As a workaround, I'm using PreparedStatements for update/insert/delete but drawing the data from the RowSets to avoid defining another structure. Have had no problems whatsoever with selects at least. There are plans to increase support within Struts for RowSets in the 1.1. timeframe. (Who knows, maybe we can do a FastCachedRowSet that can cope with inserts!) In the meantime, I'm wrapping the Rowsets in standard beans and Iterators so I can use what we got now with what we got now. Hopefully I can just drop the wrappers later and use the raw Rowsets. Obviously, I'm extremely interested in your work, and would love to see it. Speaking of configuration issues, I've also played with the idea of loading SQL commands from a resource, so they could be changed and reloaded without restarting the application. It would also be easier to optimize command sets for different DBMS packages. Just wondering if anyone else has implemented a SQL command resource. Gogineni, Pratima wrote: Hi Ted, I remember playing with cached rowsets sometime ago. It is probably useful to standardize your tags/code etc. based on the cached rowset rather than create your own data-structure - but I found that particularly the update/delete/insert into the rowset doesnt work properly for all but the simplest tables. I am currently implementing my own web-app(struts-based) that could handle more cases - one thing with this is that the user can specify the update/insert/delete in an xml file to configure my rowset - since I think it is not possible to anticipate in all cases what statements they would want to use. This also allows them to fire off multiple statements (for data-integrity reasons or something else) in a transaction for each of the actions update/insert/delete ... Pratima
Re: Is this possible with Struts?
http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayQuestionAnswer/action/SetAll/project_id/2/faq_id/36/topic_id/207/question_id/821
Re: FW: Scope of the form - TED
I don't believe that there is a reliable way for Struts to determine dynamically where a submit actually started, since things can get passed around. There is history information in the request, but that can be iffy. If you want that behaviour, you should be able to script that through the ActionMappings file by having an entry for each possible input page with its own input property. The action locations are virtual, and you can have as many as you need. Jonathan wrote: Ted, I have been questioning the value of the input property. The input property in Joyce's case is literally the submitting page, which I hardcoded into the struts-config.xml. If I came from another page, however, I will STILL be forwarded to the uri of the input property. I believe this is not the behavior we want. I believe what we want is to simply return where we submitted, right? There was a thread about this before I think. Can you shed some light on this?
Re: Can I have NO action?!
If you truly don't need the Action to do anything, you might be able to specify the JSP as the target for your form's submit Action. If you did use an Action, it would return an ActionForward to the JSP, which is its main purpose. An empty perform() is not permitted since it must return an ActionForward or null. [EMAIL PROTECTED] wrote: Oleg, Hi. Thanks for the post. The current file name is set in my action before the page is called. BUT, I want to give the user the option to change the filename, and forward back to this action to display the filter for the new file. Hence, my action doesn't need to DO anything, which prompted my question (I just need Struts to set the filename property in my form bean). Any ideas whether this is possible, or do I need to have a dummy action for it? Thanks, Dave
Re: error regarding invoking css from struts-template
There is a sample Web app that demonstrates how to use the struts-template tags, but you don't need to deploy that with your applicaton. Struts-template is one of the custom tag libraries, like bean, html, and logic. All you just need is the stuts-template.tld, same as any of the others. The struts-templage tags just run out and assemble your JSP from one or more pieces. If the pieces reference a CSS, then the resulting JSP will too. But it is the browser that applies the CSS, not the tags. The tags just generate HTML, the rest is up to the browser (or other client). Have you tried deploying your CSS without the templates? I believe this is just a CSS path issue, and doesn't have anything to do with the template tags. Chuck Amadi wrote: Hi, am i correct that the struts- template is a webapp and can i physically move it's content to my struts-bbnpa thus move it up to where tomcat is looking.Thus if this correct must i then constantly only refer to content in my web app named struts-bbnpa. Cheers chuck
Re: input in XML config
As it stands, the input property in the Action Mapping is (4) a default page. It is not meant so much to represent where the input came from, but where to go to get more, so the ActionServlet knows where to bounce the user if ActionForm validate fails. For more complex needs, you can reserve validation for the Action itself, where you can choose among multiple forwards. I agree that we need more flow control, especially to do things like let users login in from all over the place and then get them back to whereever they were, or interpose a standard confirmation dialog and then forward on to another action, or go off and look up a related value and then continue adding a new record. But none of these are ActionForm validate issues. I believe the core problem here may be trying to do business logic or other complex validations in the ActionForm rather in than the Action. ActionForm validation is great for simple, domain-type validations. But any validation that causes a problem here should be performed in the Action instead where there is more elbow room. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Jonathan wrote: I for one dont even understand the value in the input value parameter. There could be MANY pages that got you to the page you are on. The input value just makes one possible origin available for you to have as a return target should things go fowl. I had been saying on this discussion that there should be more or less 4 different destinations: 1) where you came from (referrer, or if there is no referrer a default page...see below) 2) where you were originally going when you were interrupted 3) a specific page - (can be success or failure page or could be the first page in a form) 4) a default page
Re: Hidding .jsp files
You might try setting validate=false in the action mapping. Mikkel Bruun wrote: Hi Craig, A blast from the past...I believe this post is a month old... Anyways...I see your point, but consider this... If I only refered to the functionaly (pages, actions whatever), I would have the following problem... myForm.do forwards to myAction which is validated to myForm... So if I linked to myForm.do, my GET would be validated and myForm would return errormessages... So I need an URL that doesn't trigger any logic, but just shows the form to the user...(or have a hidden init field in the form)... Mikkel -Original Message- From: Craig R. McClanahan To: '[EMAIL PROTECTED] ' Sent: 02-06-2001 05:14 Subject: Re: Hidding .jsp files On Tue, 15 May 2001, Mikkel Bruun wrote: Hi Guys, Is it possible to make some sort of virtual path, enabling one to hide the actual .jsp pages??? Example, i want to avoid a link like /logon/logonform.jsp replacing it with perhaps /logon (which in turn will point to /logon/logonform.jsp) I tried looking at the globalforwards, but i find the documentation quite lacking (there's an error in the code, btw)...but is this how its done??? Another solution would be to make empty action classes that just returns the succes mapping, but that would be going over the top imho... Can anybody give an answer??? thanks Mikkel Bruun One thing to keep in mind is that, in a typical Struts application, the names of the JSP pages are obscured anyway -- because the form submits go to the controller servlet. For example, walk your way through the Struts example application, and note how many of the locations actually shown have *.do extensions on them ... As a more radical way to hide things (but more for the purpose of discouraging users from setting bookmarks in the middle of an application), I've also resorted on occasion to more radical approaches: * Open the application in a window that doesn't have a location bar * Create a frameset with only one frame in it (so the location bar never changes at all). Craig McClanahan
Re: Struts Beta 03 Build Problem
Did you build Ant from the source and include the optional package? My recollection is that TraXLiason is not included in the binary distribution. McLure, David wrote: Hello Oleg, I tried this on both linux as well as NT, but unfortunately I still get the same error. I even tried adding the jdbc2_0-stdext.jar to my \jdk1.3.1\jre\lib\ext dir as well, but this didn't help. I am pretty sure my Ant install basically works because I have built other things with it such as PostgreSQL. Any other ideas? Thanks! David McLure DM Any idea why I am consistently getting an org.apache.tools.ant.taskdefs.optional.TraXLiason ClassNotFoundException when trying an ant dist build of jakarta-struts-1.0-b3-src using Ant 1.3 on DM both NT and Linux? I have what seem to be the only required jars in my path: xalan.jar and jaxp.jar from jaxp-1_1.zip, and jdbc2_0-stdext.jar, with jdk1.3.1? OAPlace crimson.jar, jaxp.jar, xalan.jar files from jaxp-1_1.zip to the OAjdk extension dir - x:\jdk1.3.1\jre\lib\ext for example.
Re: Can anyone help with solving the BACK button problem, in the browser?
It's not wrong to have a form in the session context, so long as it is disposed in the normal course; it's just a convenience that you do not want to overuse. Dudley Butt@i-Commerce wrote: yes, but this is a form that is being filled in like a wizard type of thing, i need the form to be session any ideas, for an alternative? -Original Message- From: William Jaynes [mailto:[EMAIL PROTECTED]] Sent: Friday, June 08, 2001 1:40 PM To: [EMAIL PROTECTED] Subject: Re: Can anyone help with solving the BACK button problem, in th e browser? Just a comment... Looks like your method of checking the RefreshOption property will only work if the scope of the ActionForm is session. That's ok if one doesn't mind the use of resources.
Re: Scratch RowSets
Oleg V Alexeev wrote: TH Though, if stay on this road, larger project swill have to start TH assembling their struts-config.xml from smaller files, as some TH people do with their Applicaton Resource now. ;-) My first idea was to split struts-config to 'standart' part and bean-factory part with my definirions. But it is needed to insert references to bean templates into action tags and it was main reason to build all in one. So long as we can still use a package format within struts-config, that shouldn't be a problem, since people could split them up for team development and concaternate them back again as part of the build. (By package format, I mean that we can repeat the struts-config node and all it's children as many times as needed, and still create a single ActionMapping database. I do that now and can also include David's form-validatation nodes in the same file, so that all package's programtic settings are all together.) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: reference input page from inside action?
return (new ActionForward(mapping.getInput())); Seth Ladd wrote: Hello, Is it possible to reference and forward to the input page of an action from within the action? It seems as if I have to make an explicit forward mapping for input for each action. Sometimes, I need to do extra state checking inside action, and if that fails, to forward back to input. The explicit forward mapping is fine, but it would seem more simple if input was a default mapping. Any tips or pointers would be much appreciated! Thanks, Seth -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: reference input page from inside action?
Does that work? getInput() returns a path and findForward() expects a logical name. input isn't an ActionForward, it's a property of the ActionMapping itself (that can be used to construct an ActionForward). Steve Salkin wrote: How is that different from mapping.findForward(mapping.getInput()); We are using mapping.findForward() in all cases (that a struts-config mapping exists). return (new ActionForward(mapping.getInput())); -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: struts-config.xml question
In general, you shouldn't need to specify the form name or type in the JSP at all. The form tag will lookup that up from the struts-config.xml, according to where you are submitting the form (action path = action path). html:form action=/insertQuestion html:text property=questionDesc/ /html:form action path=/insertQuestion type=com.companyname.actionmap.InsertQuestionAction name=questionForm scope=request validate=false forward name=success path=/strutstest.jsp/ /action should be all you need. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Bill Clinton wrote: Hello, I just am starting out with struts, and I have a question. I started with this syntax in my test jsp: html:form name=questionForm action=insertQuestion html:text property=questionDesc/ /html:form and this in my struts-config.xml: form-bean name=questionForm type=com.companyname.actionform.QuestionForm/ but I was getting this error: javax.servlet.jsp.JspException: Must specify type attribute if name is specified # After searching this list's archives, I saw a reply to a similar question from Craig McClanahan that states: If you specify name here, you must also specify type. If you change this to: form:form action=regstep1.do The tag will be smart enough to figure out what form bean name you want, without having to specify it both here and in struts-config.xml. so, to test, I specified the name in my jsp html:form tag so it looked like this: html:form name=questionForm type=com.companyname.actionform.QuestionForm action=insertQuestion and this worked. # But, I don't want to have to list the classnames in the JSPs, so I tried to follow craigs suggestion. I changed the lines in the JSP to: html:form name=questionForm action=insertQuestion and tried this in my struts-config.xml: form-bean name=questionForm type=com.companyname.actionform.QuestionForm/ actionpath=/insertQuestion type=com.companyname.actionmap.InsertQuestionAction name=questionForm scope=request validate=false forward name=success path=/strutstest.jsp/ /action but now I get this error: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection I also searched on this error, but the messages I found did not seem to match my situation. ### Since it works when I specify both the name and type in the html:form tag, I am starting to wonder if my struts-config.xml (in my WEB-INF dir) is being read. Is it enough to put this file in the WEB-INF directory? Also, when I had the name in my html:form tag and the type in the form-bean tag, it seemed obvious how these two things were linked (even thought this was not correct). When I follow Craig's suggestion, I am unsure how The tag will be smart enough to figure out what form bean name you want. Does it use the JSP name to link to the path attribute of the action tag, and link the name attribute of the action tag to the name attribute of the form-bean tag? Sorry about the length of this message, but I wanted to try to be as specific as possible about the problem. Also, if anyone knows of any good documentation links, I am open to suggestions. Other than the docs on the apache site, I have only found www.husted.com , which has lots of useful tips. Any others out there? Thanks, Bill
Re: Scratch RowSets
Oleg V Alexeev wrote: So I can place several struts-config sections to the config file and all stuff will be parsed. Is it right? Yes. Are there any differences between file with one big section and file with several sections in case of whole content of such files is identical? A configuration file using the package format will be longer, but they are functionally equivalent. I'm also doing things like /account/Form.java /account/Insert.java rather than /accountForm.java /accountInsert.java so that the application is divided into coherent sub-packages. So it then becomes natural for me to arrange the configuration files that way. And as mentioned I can also interlace David's Validator nodes in there too. -T.
Re: Scratch RowSets
Just as an aside, Oleg: When I use RowSets as value object beans, the type is determined by the JDBC metadata. I've been putting some wrappers around that so the properties have ordinary getters and setters. I see that BeanFactory includes code to create tables, but what about reading tables to create beans? Oleg V Alexeev wrote: Hello Ted, Thank for good stub. Now I am trying to implement such approach in my extension to struts - BeanFactoryServlet.
Re: ActionForm/Action with edit mode
Hogan, John wrote: Joe, Ted, Your proposed solutions worked well. Thanks. Here's a simple trick for returning a blank ActionForm for new data-entry. Define a generic Input action, that does nothing but return (new ActionForward(mapping.getInput())); Then whenever you need to get a blank ActionForm, of any type, just create a mapping to the generic Action, specifying a different input property: action path=/bid/Input type=org.wxxi.gavel.lib.Input name=bidForm scope=request validate=false input=/WEB-INF/jsp/bid/Form.jsp /action Or, action path=/donor/Input type=org.wxxi.gavel.lib.Input name=donorForm scope=request validate=false input=/WEB-INF/jsp/donor/Form.jsp /action This way you don't have to check for an add request for each form type. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: struts-config.xml question
Now that you mention it, the FAQ-o-Matic is up again. http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayTopics/action/SetAll/project_id/2/faq_id/36 Bill Clinton wrote: Also, if anyone knows of any good documentation links, I am open to suggestions. Other than the docs on the apache site, I have only found www.husted.com , which has lots of useful tips. Any others out there? -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Pre populate
Many times pre-processing and post-processing are related, and it can be convenient to handle both in the same Action class. A good way to implement this is to have a seperate Action Mapping for each task (pre-process and post-process). Both mappings would point to the same Action but use different (virtual) paths. Like say /account/setup/pre and /account/setup/post . These may both use the same Action class, which could be package/account/setup.java . The Struts mappings accept an extra parameter property that you can easily test in the Action to see which mapping has been chosen. Your action can then process each task differently, and even go to separate locations if successfuly. By managing this all in the struts-config.xml, you gain a lot of flexbility. In struts-config: action path=/account/setup/pre type=package.account.Setup.java name=setupForm scope=request validate=false input=/WEB-INF/jsp/account/setup/Form.jsp parameter=pre forward name=success path=/WEB-INF/jsp/account/setup/Form.jsp/ /action action path=/account/setup/post type=package.account.Setup.java name=setupForm scope=request validate=true input=/WEB-INF/jsp/setup/Form.jsp parameter=post forward name=success path=/WEB-INF/jsp/account/setup/View.jsp/ /action In your Action: String task = mapping.getParameter(); // handle task for pre or task for post // ... // ... return (mapping.findForward(success)); -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Kiet Nguyen wrote: I need to pre-populate my form and do some business processes prior to load a page. Where would be the best place for this. I don't want to put it in the peform method of the from page. And doing business process at the form bean does not seen appropriate.
Re: ActionForms for read-only data??
The important thing about ActionForm beans is that they are intended as adapters between HTML forms and the rest of the application. If the property is being used within a HTML form, then it is a valid use of an ActionForm bean, regardless of whether the property is hidden or immutable. It is not expected that there will be a 1:1 relationship between a HTML form and an ActionForm bean. Some ActionForm beans may be used on several forms, and several forms may use the same ActionForm bean. In general, most people would design ActionForm beans to represent a logical view (in the SQL sense) within the application. If the data is being accessed by the same SQL query, then it would make sense to put it all on the same ActionForm bean, regardless of whether it is exposed. The only thing to watch for is Strut's calling reset() as part of the validation. If a property is not present in the form, then it will be reset, and your validation has to cope with that. One caveat: ActionForms are not meant to be a panacea for the presentation layer. There are often other JavaBeans in play on this layer, with ActionForms being specialized for use with HTML forms. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ [EMAIL PROTECTED] wrote: I have a Struts theory question on use of action forms versus java beans for read-only data. We have extended workflow on our website such that the same form can look a bit different depending on where you are in the workflow. For example, the quote request will have limit and retention fields in the business request section. Once you get to quote, those fields are read-only and there's an additional quote amount field. When the client requests binder, all those fields are read-only and there is a checkbox. Once bound, everything is read-only. There is some disagreement on the team as to how to handle this case. We will obviously have four JSPs, one for each of these presentations. The question is the data mapping to beans. Half of the team feels that to use Struts in its purest sense, we need to have java beans that represent the read-only data, and action forms to represent the editable data. That would mean four action forms, one for each JSP. The other half of the team wants to re-use the same action form for all four cases, bean:define it in the session, and use bean:write to print out the data if read-only. The major advantage is simplicity - we have one bean that represents all of the data - there is no need to understand what part of the workflow we are in when translating the data from the data model to the presentation layer beans. It is also easier to understand for an HTML programmer or developer that the same bean is used regardless of whether it is a bean:write or any of the html tags. We certainly don't want to end up in a position where we have broken the framework and hurt our extensibility in future releases. The first scenario would seem to follow the framework more closely, but in this special case, is it a problem to deviate and use the ActionForm for what it is - a bean? We would appreciate any advice and experiences. Thank you. Lisa Stephens GeneralCologne Re Trumbull, CT 203 328 5227
Re: difficulty with logic:forward in template
The template is flushing the write buffer, and you can't redirect once the browser starts writing to the screen. Tom Miller wrote: I'm trying to use logic:forward in a .jsp file that is used in a template (via template:put). Apparently this is problematic, as I get the following exception when ForwardTag.doEndTag tries to execute pageContext.forward(path): java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been obtained Yet the same logic:forward works perfectly when invoked in a plain .jsp rather than in a template. Can anyone suggest a workaround, or even better, something I don't know about that might solve this?
Re: Handling Multipart forms (sort of Wizard)
I haven't tried this yet, but one way might be to setup an ActionMapping for each step in the Wizard, and set the parameter property for each. Struts passes the ActionMapping to validation, so you should be able to use mapping.getParameter() to tell where you are. You can then use this same technique within an Action, if you need to perform any processing between steps (like routing to a different step based on what they selected). action-mappings !-- Entry point -- action parameter=step0 path=/wizard/Start type=package.wizard name=wizardForm scope=session validate=false forward name=success path=/WEB-INF/jsp/wizard/Step1.jsp/ /action action-mappings !-- Step1 submits here -- action parameter=step1 path=/wizard/Step1 type=package.wizard name=wizardForm scope=session validate=true input=/WEB-INF/jsp/wizard/Step1.jsp forward name=success path=WEB-INF/jsp/wizard/Step2.jsp/ /action action-mappings !-- Step2 submits here -- action parameter=step2 path=/wizard/Step2 type=package.wizard name=wizardForm scope=session validate=true input=/WEB-INF/jsp/wizard/Step2.jsp !-- the package.wizard Action would check the form and choose one of these forwards -- forward name=rent path=/wizard/Step3/rent.do/ forward name=own path=/wizard/Step3/own.do/ /action in validate() String step = mapping.getParameter(); // ... handle validation for each step in Action String step = mapping.getParameter(); // .. analyze form, if needed, and route to next step -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ [EMAIL PROTECTED] wrote: Hello All, I am using mulipart forms for adding an employee information. In this I have 3 forms namely, emplEducation, emplExperience, emplGeneral in separate JSPs. In this case, I am using only one form bean for all these JSPs and only one action class. My problem is how to validate the Form bean after each page submission: I know the validation can be done in the form bean using validate() method or in the action class But, if user filled emplEducation form and press Next, to go to emplExperience, how do I validate only those form bean fields related to emplEducation and not the others till they are entered by user?? Is there any straight forward strategy for handling this?? - Sandeep
Re: ActionForms for read-only data??
Struts tries to recycle ActionForm beans between requests. Perhaps Struts is not creating a new bean for the next request, but recycling the old one by calling reset(), and so the nested beans are being set to null. Michael Mok wrote: Hi Ted Since you mentioned about this. I have tried a similar method and I notice while the method works, I have to store the form bean in the session scope instead of the request scope. When I try to store the form (with nested beans) in the request scope, when the form is submitted to the next action, STRUTS does not automatically create the table1 bean nor the table2 bean though it creates the formbean fine. Any comments?
Re: Struts Questions
I tend to use bulk setters on the helper classes to transfer everything from the ActionForm at once, e.g. public void setString( String property0, String property1, String property2, String property3 ) throws SQLException { values.updateString(property0,property0); values.updateString(property1,property1); values.updateString(property2,property2); values.updateString(property3,property3); } The helper class can then expose the properties to the EJB, or other data access object, in their native type. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Assenza, Chris wrote: We are doing so right now - all we had to do was create an additional class that has all the getters/setters of the ActionForm for a particular screen or set of screens. Then call all the sets from the Action and pass the object along to the EJB. That's it. :) No tangible performance loss/gain. (BTW, any better ways of doing this for future reference?) :)
Re: General Struts J2EE question
The best practice is to first validate the incoming data entry using the Strut's ActionForm beans. There is a Validation servlet available that automates much of this using regular expressions, and generates checks using both client-side Javascript and server-side Java code. Then, the Strings from the ActionForms can then be passed to your Enterprise Beans. Depending on how your EB's are setup you can do this with 1. Data conversion methods built into the Action Forms. 2. A generalized helper class. 3. Some other methods already available to you. I'm work with CachedRowSets, which handle most of the data conversions for me. Struts is a very good choice for a data-entry applications, given the limitations of HTML forms generally. I'm rebuilding the data-entry portion of an application now, and should be able to share most of the code next week as open source. It does not use J2EE directly, but does follow the same design patterns. The view portion of this is an online auction for a public broadcasting auction. Most of the items are gone (we started with over 5000), but a few dozen are still available at http://data.wxxi.org/wxxi-gavel/ . This also is a Struts application, though we originally transfered the data from another application. My biggest tip is to use templates to design many common classes at once. With a data-centric application, many operations are repeated for each table, so I'm using a boilerplate form that lets me define several related classes with one sweep with search and replace. (At least until I get around to writing a real code generator!) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Kris Vandenberk wrote: Hi, I work in a company where 90% of all applications being developed are mostly data-entry kinda applications (so a lot of data input, validations on that data ... and readonly views of that data) A lot of our clients 'heard' of J2EE and they insist on using J2EE for their new applications, which isn't a bad thing, although it is quite costly for applications only used by a 100 users. This aside, I have a couple of questions: * what is at this moment the best practice (presentation) to develop data entry applications using J2EE, is struts appropriate, or would you suggest applets, ... ? or a mix, lets say applets for data entry and struts based JSP for read only views ? * does anyone have hands-on experience with data entry kinda applications built on struts ? * metrics available ? time to develop ? compared to applets ? * pitfalls ? tips ? thanks, Kris
Re: General Struts J2EE question
Sorry, the servlet part is really a misnomer, and is only used to load the validation mappings. The requests are all still handled by the ActionServlet. The server-side validation happens within a subclass of ActionForm. The client-side validation is generated by a custom tag. It snaps into the existing flow, and nothing bounces around. Jonathan Asbell wrote: Ted, One thing I am not understanding is why we are bouncing requests all over using various servlets, as in the case of validation. What are the consequences and or benefits of one servlet triggereing another etc. It seems as though this can create confusion because you dont know what is happening. That is, you could end up being bounced all over the place from servlet to servlet beforwe coming to a rest, and you may or may not know what exactlly transpired. Jonathan - Original Message - From: Ted Husted [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 13, 2001 5:39 PM Subject: Re: General Struts J2EE question The best practice is to first validate the incoming data entry using the Strut's ActionForm beans. There is a Validation servlet available that automates much of this using regular expressions, and generates checks using both client-side Javascript and server-side Java code. Then, the Strings from the ActionForms can then be passed to your Enterprise Beans. Depending on how your EB's are setup you can do this with 1. Data conversion methods built into the Action Forms. 2. A generalized helper class. 3. Some other methods already available to you. I'm work with CachedRowSets, which handle most of the data conversions for me. Struts is a very good choice for a data-entry applications, given the limitations of HTML forms generally. I'm rebuilding the data-entry portion of an application now, and should be able to share most of the code next week as open source. It does not use J2EE directly, but does follow the same design patterns. The view portion of this is an online auction for a public broadcasting auction. Most of the items are gone (we started with over 5000), but a few dozen are still available at http://data.wxxi.org/wxxi-gavel/ . This also is a Struts application, though we originally transfered the data from another application. My biggest tip is to use templates to design many common classes at once. With a data-centric application, many operations are repeated for each table, so I'm using a boilerplate form that lets me define several related classes with one sweep with search and replace. (At least until I get around to writing a real code generator!) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Kris Vandenberk wrote: Hi, I work in a company where 90% of all applications being developed are mostly data-entry kinda applications (so a lot of data input, validations on that data ... and readonly views of that data) A lot of our clients 'heard' of J2EE and they insist on using J2EE for their new applications, which isn't a bad thing, although it is quite costly for applications only used by a 100 users. This aside, I have a couple of questions: * what is at this moment the best practice (presentation) to develop data entry applications using J2EE, is struts appropriate, or would you suggest applets, ... ? or a mix, lets say applets for data entry and struts based JSP for read only views ? * does anyone have hands-on experience with data entry kinda applications built on struts ? * metrics available ? time to develop ? compared to applets ? * pitfalls ? tips ? thanks, Kris -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Type conversions - issues on where to do them
The best practice is to perform domain validations in the ActionForm, like those possible with David W's validator. This means confirming that the String could be represented as the desired type. The original String captured by the ActionForm should never be altered (immutable except by the user). The type conversions can be handled by a helper object, which can be embedded in the ActionForm or elsewhere. If the conversions are handled by the ActionForm, the result should always be transfered to another property, leaving the original String intact. A good way to retrieve the data in this case is to have a separate accessor. So an ActionForm may have a getAccount() accessor and a getAccountInt() accessor, with the int property being set as part of the ActionForm validation. If the ActionForm makes it to the Action, the API contract would be that getAccountInt() will return a valid representation of getAccount as an int. Of course, the int returned may not be in a valid range, pursuant to some business logic. This level of validation should be perfomed in the Action, which can easily return the ActionForm to input if there is a problem. Another form of range might be a valid username and password. [ user input ] - [ action form ] - [ validate domain ] - [ action ] - [ validate range ] - [ transfer to persistent storage or business logic beans ] Depending on the resources available, you may also prefer to do the type conversions within the Action. If the ActionForm validator is doing it's job, the conversions should not fail. Personally, I let the RowSets do most of my type conversions for me, which happens within the Action. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Jonathan Asbell wrote: Hello all. I wanted to know where you are doing type conversion. The reason I ask is because to some extent one may choose to do slightly deeper validations in the ActionForm for reasons of expectation. The question remains as to the exact level of light validation we should do in the ActionForm. From reading the list it seems the general consensus is to only do validation of a value's existance. However, where do you do type conversion then? In the ActionForm? In the Action? In the BusinessObject layer? The issues are: 1) If I do it in the ActionForm and there is a problem in the Action, then I have to reconvert back to a String on the way back.; 2) If I do it in the Action, same problem, but also the argument has been brought to my attention that the ActionForm bean (although temporary) does not truly represent the data it contains (like when a value represents a double, money, or a Date) 3) If I do it in the Business Layer than the message has gone deeper into the application than necessary which sacrifices performance and needless use of resources.
Re: Type conversions - issues on where to do them
Jonathan Asbell wrote: Well, just one hitch when doing the business validation in the Action. If you are developing in an enterprise environment, you probably want to do these kind of validations in a business object because, as pointed out in an eariler thread, you may need data from the database to do this validation/evaluation. Better that the validation for this level all be in one place. In an enterprise app the Action would probably be considered part of the web tier. Therfore, it would not be good to mix the two tiers. What do you Think? The Action can be murky ground, but it is often used as the interface between the business tier and the Web tier. After all, they have to meet somewhere, yes? So, if the business object rejected the data, it would return it to the Action, which would hand it back to the ActionForm. You would not so much be doing the validation in the Action form as much as you would be calling the Business Object from the Action to do the validation. [ ActionForm ] - [ Action ] - [ Business Object ] By the way Ted, thank you for being so open and taking the time to offer your perspective. I really appreciate it and I'm sure everyone on the list does as well. It makes this list truly worth while. Ditto to Oleg, Martin, Michael, Johan, Peter, Nanduri, Jon, Jeff, Hal, David, and Craig. I have learned alot in these 3 months. And before much longer I'm sure someone will be adding your name to a list like that, Jonathan ;-) -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: Type conversions - issues on where to do them
Jonathan Asbell wrote: As we are both being nightowls in the same timezone, let me continue with this. We are using a Broker. So, in my case each Action would call the Broker, which is our link to the enterprise layer. Also, if the business object rejected the data, as you said, than it would pass it to the Action but NOT up again to the ActionForm. At that point the Action would choose a forward with errors and data. Yes, I misspoke. The Action would insert an error and choose a forward; the ActionForm would just tag along as part of the pending request/response. The custom tags in the JSP would then find the ActionForm in the request, and redisplay what the user entered, for correction and resubmission. Jonathan Asbell wrote: Are you assuming that I keep the form data as Strings until the business layer? This was my collegue's complaint about the ActionForms because they did not contain the types he was expecting, but rather just Strings. An important thing to remember is that HTTPD doesn't allow us to send anything but Strings. As Craig mentioned, you can do things like add your own accessors to return whatever types you expect (converted from the Strings that the client sent by HTTPD), or use some other utility within your application. For example, someone might already have a Helper object that accepts strings and then transforms them in different ways. The general philosphy, I suppose, is that data conversion is outside the scope of the framework and best left to the developer. In case anyone is interested, here's a nice article about Helper classes: http://developer.java.sun.com/developer/restricted/patterns/ViewHelper.html
Re: Server-side form validation - anything in STRUTS?
More support for implementing validations is on the list for the 1.1 timeframe. The leading contender here is David Winterfeldt's extension. Highly recommended. http://home.earthlink.net/~dwinterfeldt/ The most popular pattern is to perform domain validations in the ActionForm to ensure that the String can be converted to a native type. And then perform range validations in the Action, which may need to reference the business logic tier. The actual data-type conversion can be done anywhere along the way. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Dave Small wrote: It's perfectly clear how a single form can be validated within STRUTS (thanks to Wellington Lacerda for his input and clarification too). However, your article points to implementing the 'validate' method in a very low-level way, coding the validation logic on a per-form basis as required. I guess my real question was whether STRUTS had taken a higher-level abstraction of the validation required, so that form validation can be expressed external to the Java code (eg. in a properties file).
Re: Accessing session attributes
The html tags are designed to display what's in a related ActionForm bean. So the trick would be to get your String into the ActionForm bean. The place to do this would be in an Action that then forwarded to your JSP. So the Action would go something like this: HttpSession session = request.getSession(); YourBean yourBean = (YourBean) session.getAttribute(yourBean); YourForm yourForm = (YourForm) form; yourForm.setWhatever(yourBean.getWhatever()); return (findForward(success)); You could use the same Action to handle the submit from the form, either by keying on a value in the form or by submitting to another Action Mapping with a different parameter property. If you don't need to display them in a HTML form, then you can just use the bean:write tag and specify the property you want to write (assuming it has a getYyyy accessor). -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ James Howe wrote: This is probably a stupid question, but here it goes. I have a handful of string values that I'm storing in the session object. These values aren't associated with any bean (actually, in a sense the session object is the bean). I have a couple of places where I need to display these values in a form. I want to use the html:text tag, but I don't know what I need to specify. Let me give an example. Suppose I have a String value stored in the session by the name of filter. How would I get the filter value to display in a form text field?
Re: Multiple Forwards
You could start by adding a method to a base class for your application that would append a tag according to the browser detected, and then use this scheme: forward name=ie_success path=/ie/test.jsp/ forward name=ns_success path=/ns/test.jsp/ forward name=wap_success path=/wap/test.jsp/ by returning something like return ( findForward( browserTag(success) ) ; where browserTag prepended the ie part. The idea of being to forward to relative directories also came up here the other day: http://www.mail-archive.com/struts-dev%40jakarta.apache.org/msg01779.html Hans Bure wrote: Hi all, I am a relatively new struts user, so if the question I'm asking has been answered before, I appologize ahead of time. What I'm trying to do, is create a framework integrated with struts that, among other things, allows users to set up multiple forwards dependent on the broswer type. This could be Netscape, IE, WAP browser, or others. What I would like to do is something like the following in the struts-config.xml file: ... action name=test ... forward name=success browser=IE path=/ie/test.jsp/ forward name=success browser=NS path=/ns/test.jsp/ forward name=success browser=WAP path=/wap/test.jsp/ ... /action ... The reasoning behind this, would be to create an additional attribute that could be used by my framework internals that determines the browser and calls the correct JSP for the user automatically. Something like: ... return myMapping.findForward(success); ... Which calls into a wrapper class that I create and determines the browser, then calling the appropriate JSP as defined in the config file. This makes it very simple for the user, as he only needs to define a series of 'success's, and the Action code is simple as defined above. Now, obviously, adding an additional attribute to the forward above is not trivial. So my question, is has anyone seen anything like this, and is there a way I haven't thought of to do this within the current struts framework? One thought I've had would be to do the following: forward name=ie_success path=/ie/test.jsp/ forward name=ns_success path=/ns/test.jsp/ forward name=wap_success path=/wap/test.jsp/ This would work and not require many changes to the framework, but I would rather not do this, as it would make things very difficult for my users to create their own actions. Another possibility is the following: forward name=success path=test.jsp / browserforward name=success browser=ie path=/ie/test.jsp / browserforward name=success browser=ns path=/ns/test.jsp / browserforward name=success broswer=wap path=/wap/test.jsp / In this case, I would need to create another XML entry that kept all of the 'success' forwards for each action in its own little HashTable, much like the normal forwards, except keyed by a combination of the name and the browser attributes. I honestly don't know how difficult this would be, but it seems like the best solution I've come up with so far. One obvious drawback to this one is that the struts DTD would need to be altered to include the 'browserforward' element. I am not sure of the implications of this. Any thoughts? Thanks for your time. Hans Bure
Re: Having problems passing more than one parameter with html:link tag
I think you would need to use a map here. http://jakarta.apache.org/struts/struts-html.html#link Normally, the hyperlink you specify with one of the attributes described in the previous paragraph will be left unchanged (other than URL rewriting if necessary). However, there are two ways you can append one or more dynamically defined query parameters to the hyperlink -- specify a single parameter with the paramId attribute (and its associated attributes to select the value), or specify the name (and optional property) attributes to select a java.util.Map bean that contains one or more parameter ids and corresponding values. Shamdasani Nimmi-ANS004 wrote: I am trying to pass 2 parameters with html:link. Since it is not legal to use the same attribute name more than once in the same tag, I created another reference 'tempId' to my 'submitQuotesForm' bean using bean:define tag but I am only getting the last param 'supplier_seq' added to my link.
Re: Other Frameworks?
Have you seen this: http://barracuda.enhydra.org/cvs_source/Barracuda/docs/landscape.html Steven Leija wrote: Hey All, I was asked to evaluate java frameworks that are available such as Struts, Turbine, Barracuda, Smartmode, Velocity, Expresso, Niggle, Tapestry, and Swinglets. Does anyone have any sort of opinion over which frameworks are the best? Which frameworks are not the best or ideal to use? Do any of the frameworks compliment others? Does Struts work well with other frameworks such as Cocoon? I'm in favor of Struts, but I must evaluate other frameworks to come up with a the pro's and con's with each framework and why Struts is more dominate over it's competitor frameworks.
Re: How can I use an Iterator's value twice?
Your html:link needs to specify paramProperty=results. I can't tell what the paramName should be, since that would depend on what the linked page expects. Here's a reference snippet from a working page. The bean result has accessors for donor, sortName, email, and website, where donor is a unique key. Here the key is also used as the link text, but any other value from the bean could have been linked instead. This snippet generates links in the form: /donor/Select.do?key=1234 where result.rows.getDonor() returns 1234 logic:iterate name=result property=rows id=row td align=left html:link page=/donor/Select.do paramName=row paramId=key paramProperty=donor bean:write name=row property=donor filter=true/ /html:link /td td align=left bean:write name=row property=sortName filter=true/ /td td align=left nowrap bean:write name=row property=telephone filter=true/ /td td align=left nowrap font size=1a href=mailto:bean:write name=row property=email/bean:write name=row property=email filter=true//a/font /td td align=left font size=1a href=http://bean:write name=row property=website/ target=_blankbean:write name=row property=website filter=true//a/font /td /tr /logic:iterate -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Digico wrote: This problem loosely related to a couple of others that I've seen recently on this list, and it's a common enough thing to do that there must be a simple solution that I just don't see. I want to produce a list of search results as hyperlinks in which each list value is displayed AND is used in the link, as in: ol lia href=/myapp/fetchItem.do?key=key_1key_1/a lia href=/myapp/fetchItem.do?key=key_2key_2/a lia href=/myapp/fetchItem.do?key=key_3key_3/a ... etc ... /ol I've tried using the iterate tag and a bean that has an Iterator property, along with html:link as in the following sample: logic:iterate id=results name=mainSearchBean property=resultsIterator li html:link page=/bookDetails.do paramId=key paramName=? paramProperty=? bean:write name=results/ /html:link /logic:iterate I've tried setting paramId, paramName, and paramProperty in various ways but nothing gives me the results I want. The best I get is a list of hyperlinks for the results as expected except that the actual links are all the same. I also tried jamming a copy of the bean:write name=results tag in the page attribute of html:link but that caused an exception. Should I just add a Map property to mainSearchBean and, if so, how would I use it to this effect? Thanks. - Mark.
Re: nested logic:present tags do not short-circuit
The first tags says if A.B is not null rather than if A B are not null. You may need to use more nesting, maybe something like logic:present name=A logic:present name=A property=B logic:present name=A property=B.property some jsp/html /logic:present /logic:present /logic:present -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Steve Salkin wrote: Hi- Am I correct to say that in the case of nested logic:present tags, the false evaluation of the first one will not short-circuit, or prevent the evaluation of, the second one? For example, in the case that a Form has a Bean A, which itself has a Bean B, and when B is null, the following: logic:present name=A property=B logic:present name=A property=B.property some jsp/html /logic:present /logic:present will still fail because the second logic tag is evaluated and the null-pointer is dereferenced. If this is correct, is this by design? Is this a bug? Is there a way to accomplish what I am trying to do here? Any thoughts appreciated. Thanks, S-
Re: FormBeans necessary for every form
It would seem to me to be an organizational design decision. If you share the bean, you would also have to share the validate method, but that can be easily managed by checking the Action Mapping to see which form is using the bean in this instance. The easiest way to do that is by using the parameter property to indicate which view of the bean should be validated. You could also use the mapping parameter in an omnibus action to determine what processing needs to be done. So, the trade off is whether you like to maintain fewer classes with more properties or more classes with fewer properties. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Felix von Delius wrote: Is there any disadvantage in *not* having separate (Form-)Beans for every form in an application? -Felix
Re: General DATABASE programming question
Sun's cached rowset has a MaxRows property that you can use to limit the number of rows returned. http://developer.java.sun.com/developer/Books/JDBCTutorial/chapter5.html I'm not aware of a general way to offset a particular number of rows in the a query that will work with everyting, which leaves fetching block 1 and block 2 to get to block 3. (Hoping 1 and 2 haven't changed in the meantime). -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Mindaugas Idzelis wrote: This may be a little off topic, please forgive me. One of my webapplications displays a group of results from a database query. These can be hundreds of rows long. I would like to break these up into smaller sections to fit on a page. My problem is, I don't want to run the entire query at once and save it to memory. PostgreSQL and MySQL have the LIMIT num,offset qualifier which does exactly what I want. The problem is that I'm using MS SQL and it doesn't use the LIMIT keyword. Instead, it uses TOP and you can't supply an offset. My quetion: Is there anyway to specify an offset into a query using MS SQL Server? Thank you. --min
Re: Missing configuration resource for path /WEB-INF/struts-config.xml in Webspere 3.5.2 under not Default server
It's looking for the ApplicationResouces.property file. This can be anywhere on your class path. I like it right under the classes folder. Karmanov, Igor wrote: Hi All, I've got Struts (1.0-b1) Example working under Default Server without any problem using standard instructions. We converted part of our application towards using Struts as well. struts-config.xml was placed under web/WEB-INF directory. The problem starts when I deploy Struts application under manually created another Application Server on the same physical server (box). During web application start I'm getting the following error: [01.06.15 13:25:48:906 EDT] 9cbba84b WebGroup A SRVE0091I: [Servlet LOG]: action: Initializing configuration from resource path /WEB-INF/struts-config.xml [01.06.15 13:25:48:953 EDT] 9cbba84b ServletInstan X Uncaught init() exception thrown by servlet {0}: {1} action javax.servlet.UnavailableException: Missing configuration resource for path /WEB-INF/struts-config.xml I tried all possible suggestions from archive messages like: - put web/ directory in classpath of the webapp; - create /WEB-INF subdirectory in servlets/ with struts-config.xml and web.xml in it. None of them worked out. Does somebody has the same experience? Thanks in advance, Igor Karmanov -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: General DATABASE programming question
If you use a scollable resultset, you will have to keep an open connection to the database. This can be an issue with a Web application. With a Cacheable RowSet you would not need to keep the connection open, but you would need to store the entire set in memory. Either way, you would need a mechanism to change the settings for the interator, which probably means round trips to the server. I know it sounds wasteful, but personally I would think about getting a page at a time. This is more work on the DBMS as they go to later pages, but many times they don't go past the first page. Otherwise you will need to keep the resultset in the session and tie up memory. A lot of people like to use the pager tag from JSP tags for this sort of thing. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Mindaugas Idzelis wrote: Thanks for all your answers. This has been very nerve wrecking. I think I've come up with a solution that may work in a DB independent way. I'll use a scrollable resultset. I won't iterate through all of it, only portions at a time. I think most underlying JDBC drivers use cursors to implement the scrollable resultset. Is this a valid approach? --min
Re: html:checkbox
They are actually cached in the request. It's just that with boolean checkboxes, you should reset them them to false first, or there are side effects. You really, really don't have to do anything else. It's important to remember that there is not a direct connection between the HTML form and Struts. Everything has to go through HTTP. When the form is submitted, all the properties are sent as parameters to the request by HTTP. Struts then catches them and puts them back into the ActionForm. What can happen with checkboxes is that if they get unchecked, the browser won't send them back, and so Struts has no way to set them true or false. By setting them to false when the form is initialized and to false again when the form is reset, you get consistent results. Otherwise, if they unchecked the box, and the browser didn't send it back, the setting on your box may be indeterminate. Mike Thompson wrote: So this means that I have to cache the original state of all my checkbox referenced vars so I can set them back in the reset method? :( --m
[ANNOUNCMENT] Strut by Strut
A new article regarding building Struts applications is available at http://www.husted.com/about/struts/ entitled Strut by Strut. Feedback is welcome. A followup article regarding using a database with Struts (Stepping Out) is nearly complete. Stay tuned. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: [ANNOUNCMENT] Strut by Strut
Sorry for the troubles with the inital WAR. I was experimenting with an alternate configuration, which, as it turns out, is not compatible with all versions of all containers. I've returned to the conventional configuration, and you may wish to download the updated copy. http://www.husted.com/about/struts/struts-stub.zip Ted Husted wrote: A new article regarding building Struts applications is available at http://www.husted.com/about/struts/ entitled Strut by Strut. Feedback is welcome. A followup article regarding using a database with Struts (Stepping Out) is nearly complete. Stay tuned. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: [ANNOUNCMENT] Strut by Strut
If you want to convert an integer to a String on the fly, you can do this: /** * Return the script as int * * @return the script as int */ public int getScriptInt() { return ( Integer.valueOf(this.script).intValue() ); } Assuming the String has been validated first. To move the data from one bean to another, you can either use a bulk setter or constructor myBean.set( getScriptInt(),getTitle(),getCurrentDate() ); // or new myBean( getScriptInt(),getTitle(),getCurrentDate() ); Or, if your internal bean is designed to accept Strings for incoming data (as, say, RowSets are), then you could also have the ActionForm bean generate a hash map that matched your internal bean's mutators with the populate() method of Struts BeanUtil. populate(myInternalBean,myActionForm.toMap()); Ryan Cornia wrote: Great article! I'm fairly new to Struts and am still struggling with ActionForm setters/getters vs. bean setters/getters. In your template file, all properties for both the form and bean are Strings. How would you implement an int property - In the form, it would it be - public String getProperty10() { return(this.property10); } public void setProperty10(String property10) { this.property10 = property10; } public int getProperty10Int() { return this.property10.intValue(); } In the bean, would it be? - int property10Int = 0; public int getProperty10Int() { return(this.property10Int); } public void setProperty10Int(int property10) { this.property10Int = property10; } If this is the case, how do you copy the properties from the FormBean to the Bean when the Action is done and validated? MyForm frm = (MyForm)form; MyBean bean = Should the bean be in the session?; /** What if I have 100 properties, is there a better way to set them all? **/ bean.setProperty0(frm.getProperty0()); . . . bean.setProperty10Int(frm.getProperty10Int()); bean.writeToDatabase(); Is this the best way to mesh all of this together? Thanks for all the hard work. It's a very valuable article. Ryan
Re: ActionForm Bean and Action class relation
It might help to explain the circumstances. I'm not sure why you would start with one ActionForm bean and then switch to another. You may wish to have one larger ActionForm bean that can be used in both places. A popular pattern is to use one Action to handle several related tasks, like all the inserts, selects, updates, and deletes for a given table in your your database. In this case, it is convenient to use several different ActionMappings, but have them all use the same Action class (TYPE=...). An easy way to tell which ActionMapping was used, is to set the parameter property for each. path= /package/myAction/Input.do type = package.myAction parameter = this validate = false and path= /package/myAction/Insert.do type = package.myAction parameter = that validate = true The mappings are passed to validate(), reset(), and perform(), so in each case you can tell which task is in use with String task = mappings.getParameter(); For multipage wizard forms, David W's validator has a page feature that helps with that. http://home.earthlink.net/~dwinterfeldt/ -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Viplava Nekkalapudi wrote: Hi, I have a small problem in handling the Action form beans and Action classes. For every action class, we have a request scope action form bean. My action class executes before the jsp page displays and it is mapped to a form bean. The first time JSP is displayed, my form bean properties are null/blank, and the form bean will be populated when I submit the jsp page. I need to validate form parameters at this time in the second action class which has mapped to different form bean and jsp page. How to use the same bean between requests with request scope? Do I need to use the form bean in session scope? Do I need to use dfferent action classes for different actions on the same page, OR one action class? How to handle form beans and action classes between multiple pages some data with session scope and some with request scope. Thanks in advance. __ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
Re: Subsessions needed?
I would try and put the big form into the session context myself, and then update it from the sub forms as I go. When the workflow is complete, and the record sets are updated, I'd remove the big form from the session context. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Thomas Klute wrote: Hi, I have some problems finding the correct scope for my ActionFormBeans - I've splited one big form.jsp Page to several small pages (formx.jsp, x=1,2,...), each page has a subset of the form-fields of form.jsp. I would like one ActionFormBean to collect the data from these pages and more than one instance of these pages in order to create/modify more than one dataset. The scope request for the actionformbean creates a new bean with every request - impossible to collect the data from more than one page. The scope session creates one actionformbean per session - impossible to have more than one instance of a form-page-set. My indea was to create subsessions, but I think it's impossible without modifying struts code (f.e. processActionForm() in ActionServlet.java). I would like to keep struts code untouched - anybody has any indeas? Thanks and regards, Thomas
Re: creating ActionError inside a jsp page
It should be possible, but you would also have to replicate the Action classes's SaveError method to expose the error collection to the next page in the request. See David Winterfeldt's validation package for tags that seperate errors and other messages. http://www.husted.com/about/struts/ -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Nanduri, Amarnath wrote: Hi All, Is it possible to create an Action Error object inside a jsp page. When i am trying to forward the user from one page to an other page, i need to show a confirmation message to the user (in the new page) and i was thinking of using an Action Error object. thanks. cheers, Amar..
Re: [EJB] Design Patterns (was JavaReport ...)
The ActionForm beans can contain nested references, so you could just set some other bean to it, then refer to myBean.propertyThis and myBean.propertyThat. Of course, the other bean would have to have standard String accessor and mutators, which is where it starts to fall down. The other beans may need to use native types, and would want to reject or transform an incoming String value being set to type. So if you need two storage locations, joining the two classes loses its edge. In general, I would say that ActionForms can be coupled to other beans, but other beans should not be coupled to ActionForm bean (import the Struts class). Because, in another environment, the ActionForm beans might be replaced with another class that hooked up to non-HTTP user interface (say, Swing), and we would want to be able to drop those in. Of course, the other beans could be designed to accept values from any given JavaBean via reflection, which would include an ActionForm bean. It's my feeling that proper MVC/J2EE design implies that we are going to be stuck with a set of ActionForm beans and a set of other beans, and need to find the best way to transfer data between the two. Jonathan Asbell wrote: I was on this track in another thread where I was saying... What if ActionForm was an inner class to a Value object. Or, what if a Value object had a reference to an ActionForm which when filling with parameters we did ActionFormValue.getActionForm(), filled it, complete does it exist checking and non-business object validation checking, and then do a ActionFormValue.setActionForm(ActionForm myform) to set it back, which would fill the ActionFormValue object with the values in the ActionForm. An ActionValue could hold 1 or more ActionsForm(s) , or could take ActionForm as a parameter, with which it would copy and nativeize the data in the ActionForm. In this case an ActionValue would hold specific fileds for the beans it uses. My point here,though I hope it is apparent, is that we need to send value ojects through the system in a way in which it can complement/work with Struts.
Re: [EJB] Design Patterns (was JavaReport ...)
They could. This is especially convenient when your value object bean contains a RowSet, since the *String versions are already built in. So, you end up with something like thisForm.set( thisValue.getItemString(), thisValue.getDonorString(), thisValue.getDonorAnonString(), thisValue.getCategoryString(), thisValue.getPricelessString(), thisValue.getScriptString(), thisValue.getHasImageString(), thisValue.getShippingString(), thisValue.getItemTypeString(), thisValue.getNameString(), thisValue.getMarketString(), thisValue.getMinimumString(), thisValue.getIncrementString(), thisValue.getSaleTypeString(), thisValue.getQtyReceivedString(), thisValue.getShippableString(), thisValue.getWeightString(), thisValue.getLocationString() ); where thisValue.getItemString() does something like /** * Return the item as String * * @return the item as String */ public String getItemString() throws SQLException { return values.getString(item); } // ... and thisValue.setString( thisForm.getItem(), thisForm.getDonor(), thisForm.getDonorAnon(), thisForm.getCategory(), thisForm.getPriceless(), thisForm.getScript(), thisForm.getHasImage(), thisForm.getShipping(), thisForm.getItemType(), thisForm.getName(), thisForm.getMarket(), thisForm.getMinimum(), thisForm.getIncrement(), thisForm.getSaleType(), thisForm.getQtyReceived(), thisForm.getShippable(), thisForm.getWeight(), thisForm.getLocation() ); where setString does something like values.updateString(item,item); I'm just looking for the least intrusive, most flexible pattern. The nice part about a map is that it works well as part of an interface, encapsulates the accessors within a toMap() method, and that mutators can be called through reflection (e.g. BeanUtil.populate()). Jonathan wrote: Why is it that each bean (includeing the containing bean) could not have BOTH String get/set and also native type get/set?
Re: running struts in other application server
There are additional instructions when required for several application servers, but there should not be any general compatibility issues. I have heard that Oracle9IAS is a repackaging of Orion. http://jakarta.apache.org/struts/installation.html Here's a Javascript that I use when submitting my forms, in case it helps you with yours. html:form action=/stub/Insert focus=property0 onsubmit=return submitForm(this); ... script language=javascript !-- function submitForm(form) { if (validateStubForm(form)) { form.submit.value= ...; return true; } else return false; }; // -- ihin wrote: hi all i have trouble in struts implementation if i running my struts with tomcat, it's no error apear but if i tray to running my struts using other application server like Oracle9IAS or J2EE it's not running well. is there any special setting to running struts in other aplication server specially in Oracle9IAS and J2EE ..? what is that...? in other case i have trouble to implement java script in jsp tag that include struts if i using html:form action=/logon focus=userID onsubmit=CheckLogOn(this); return false; and in the CheckLoOn fuction i declare frmxx.submit(); the browser give erorr alert. how can i inplement the javascript in jsp+struts..? thank's in advace for all of response regards gohin -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: html action links
If you just want to use html:link, you don't necessarily have to use an ActionForm class (though you can, if you want). Here's some code for generating a list with links. Result is a bean that exposes a collection named rows. logic:iterate name=result property=rows id=row p html:link forward=donor paramName=row paramId=key paramProperty=donor bean:write name=row property=donor filter=true/ /html:link /p /logic:iterate When the page renders, it generates links like this: a href=http://localhost/struts-stub/donor/View.do?key=123456;123456/a where there is a global forward donor with the path /donor/View.do and row.getDonor() returns 123456 DHarty wrote: This is really a two part question. I have an iterative loop that displays a list users that are stored in Action Forms. The idea is that when the button (or link) next to the item is selected, the user will be allowed to make modifications to the selected form: logic:iterate id=user name=SearchForm property=result tr html:form action=/usermodify td align=center bean:write name=user property=username/ /td td align=center html:submit property=usernameModify /html:submit /td /html:form /tr /logic:iterate Where result is a vector of ActionForms. Currently, when the Modify button is selected, the appropriate action class is called, but the ActionForm is reset. I know I could add a field to the submit button, i.e: html:submit property=usernameModify bean:write property=username//html:submit and then have the action class look up the user in hte database again, but I would rather not. I was considering using an html link instead of a button, but was unsure how to proceed. Ideally, I would like to use an html link, while retaining the existing form (without having to look it up again). Any thoughts or comments would be appreciated. Thnxs David
Re: html action links
In can be used other ways, but Struts is designed to be a Model 2/MVC framework. This means you should avoid linking to JSP's directly. Generally, everything should go through a server-side Action first, where you can collect whatever data you need for the JSP, and then forward it through the request context for the JSP to display. The *.do files are mapped to Struts controller, which calls the server-side Action. The controller consults the Action Mappings, loaded from struts-config.xml, to determine which Action to call. A re-reading of the Users Guide might help you get the big picture. DHarty wrote: Okay, I changed my page to look like this. logic:iterate name=SearchForm property=result id=user tr td align=centerbean:write name=user property=username/nbsp;/td td align=center html:link forward=modifyUser paramName=user paramId=UserForm Modify /html:link /td /tr /logic:iterate this produces a link like :http://.../user_mod.jsp?UserForm=edu.erau...form.UserForm%40ff5bdefc I have a global action modifyUser with a path to /path/user_mod.jsp. I am able to pick up the UserForm parameter in ModifyUser, but I am unable to use it as the UserForm bean. Am I passing a reference to the UserForm Bean, or just a name? how do I reconstruct the UserForm bean in ModifyUser? I experimented with bean:(define,include and parameter)../ with no success. I'm sorry if these questions are simplistic, but I am new to jsp, and especially struts. Also, in the origional example, the global path is to a .do file. I was under the impression that the .do files were generated by the server. Do I need to have a generated page waiting to receive my request? How is this done? thnxs again, David -Original Message- From: Ted Husted [mailto:[EMAIL PROTECTED]] Sent: Friday, June 22, 2001 12:10 PM To: [EMAIL PROTECTED] Subject: Re: html action links If you just want to use html:link, you don't necessarily have to use an ActionForm class (though you can, if you want). Here's some code for generating a list with links. Result is a bean that exposes a collection named rows. logic:iterate name=result property=rows id=row p html:link forward=donor paramName=row paramId=key paramProperty=donor bean:write name=row property=donor filter=true/ /html:link /p /logic:iterate When the page renders, it generates links like this: a href=http://localhost/struts-stub/donor/View.do?key=123456;123456/a where there is a global forward donor with the path /donor/View.do and row.getDonor() returns 123456 DHarty wrote: This is really a two part question. I have an iterative loop that displays a list users that are stored in Action Forms. The idea is that when the button (or link) next to the item is selected, the user will be allowed to make modifications to the selected form: logic:iterate id=user name=SearchForm property=result tr html:form action=/usermodify td align=center bean:write name=user property=username/ /td td align=center html:submit property=usernameModify /html:submit /td /html:form /tr /logic:iterate Where result is a vector of ActionForms. Currently, when the Modify button is selected, the appropriate action class is called, but the ActionForm is reset. I know I could add a field to the submit button, i.e: html:submit property=usernameModify bean:write property=username//html:submit and then have the action class look up the user in hte database again, but I would rather not. I was considering using an html link instead of a button, but was unsure how to proceed. Ideally, I would like to use an html link, while retaining the existing form (without having to look it up again). Any thoughts or comments would be appreciated. Thnxs David -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/
Re: HP Bluestone Struts Trailmap
I believe using request tokens to prevent duplicate submits is not covered by any of the tutorials right now. BONAIUTO,JAMES (HP-NewJersey,ex1) wrote: I will be adding to HP Bluestone's Struts trailmap: http://gallery2.bluestone.com/scripts/SaISAPI.dll/Gallery.class/demos/trailM aps/index.jsp New trails on the trailmap will include Database connections (returning a resultset and connection pooling) and Templates. Does anyone have any other topics that they would like to see added? James Bonaiuto HP Bluestone
Re: Query string in struts-config.xml
Another approach is to pass the query string options using the parameter property of the action mapping, and then looking for them in your action. So, passing a parameter like task=select could also be represented as: action parameter=select path=/lot/Search type=org.wxxi.gavel.lot.http.Access name=lotForm scope=request validate=false input=/do/lot/Done forward name=continue path=/WEB-INF/pages/lot/Result.jsp/ /action and in the Action // -- Acquire other parameters String task mapping.getParameter(); if (task==null) task = request.getParameter(task); Of course, if you need to pass several parameters, the query string approach (using amp; for ) will let the servlet parse them out for you. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Jacob Thomas wrote: Hi Jon, I was trying this out earlier using the Struts beta 1 release and found that query strings with multiple parameters caused the XML parser to give errors when it encountered either the '' or '?' character. forward name=command path=/context/page.jsp?param1=value1param2=value2/ Based on your and Craig's feedback, I take it that this is now supported. -- Thanks Jacob
Re: initial population of html form from database --- ActionForm or ActionClass
The reset() method is called by the Action before populating an ActionForm from the request. Generally, this should set your properties to their initial values. It should have already been called by the time Action.perform() is called. It sounds like you are doing the right thing. You should be able to populate the ActionForm bean in your Action, and then return a forward to your JSP. The only thing I can think of is that it is forwarding to another Action before it gets to the JSP, or that the ActionForm related to the form in your JSP is not the same as the one related to the Action. If the problem persists, you may need to post some code samples. The description sounds correct. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 737-3463. -- http://www.husted.com/about/struts/ Smith Chris wrote: I am trying to setup an html form that needs to be initially populated from a database. Should I do this in the perform() method of the action class (which gets passed the actionform bean), or somewhere in the actionform bean?? I'm assuming it should be done from the action class since the actionform should just be a data repository by my understanding. If so, how do I do this from the action class? I've tried calling my setter methods on the actionform object (after casting to my extended class) from within the action class and the form comes up blank. If the forms are supposed to be populated from the action classes, why is there a reset method in the actionform (which doesn't seem to do anything for me by the way -- it never seems to get called), and why is it suggested to set the default values from there? thank you for any help you can offer.