Re: Newbie - DataBase
I think why you would want to do it is pretty obvious, you need to get data from the database to display on your page, such as a list of items. A better question is why would you not want to. That answer to that question is that it would be better to encapsulate your database query in a Data Access Object(DAO) and have your action call the DAO. Here is a sample of the execute method for doing it with the DAO: private ItemDAO dao = DAOFactory.getItemDAO(); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute(items,dao.getItems()); return mapping.findForward(list); } The idea would be that ItemDAO is an interface and the getItems method returns a collection of items. You would write an implementation of the ItemDAO where the getItems method does the database query. DAOFactory.getItemDAO() is a static method that returns an instance of an object that implements the ItemDAO interface. As your application gets more complicated, you may want to have the action call a service, which in turn calls the dao, but if your page is pretty simple, that step probably won't be needed. Peng Tuck Kwok wrote: On Fri, 30 Jul 2004 09:07:36 -0400, Bussie, Andre D [EMAIL PROTECTED] wrote: Is there a way in the Jakarta Struts framework to perform a database query in an Action class w/o using a Action Form Class? It sure is. The next question would be: why would you want to do that in the action ? :D - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DAO Resource Suggestions
Here is another one: http://www.javapractices.com/Topic66.cjp Bussie, Andre D wrote: Does anyone know of good resources on implementing a DAO and service within a struts application Andre' D. Bussie Sourcing Rotational Program MAC-MAR 532 Fellowship Rd Moorestown, NJ 08057 856.787.3273 856.952.7325 - Cell [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Session size
Sounds like a good idea. I suggest that you look into using something like ibatis to handle the caching for you, and it definately won't take you a week to implement, even with the learning curve of ibatis. Riyad Kalla wrote: Mike, Good suggestions. I was dealing with something like this recently and decided that for me, adding caching at the DAO level: e.g. List userList = UserDAO.getAllUsers(); would offer the biggest performance benefit since it would be: (a) application wide, instead of per session (b) returned Lists are 4-byte pointers to the actual list object cached in the DAO (c) The DAO itself handles all manipulation of those types, so it knows when to invalid its own cache (on inserts/updates/removes) What do people think about this strategy? (Before I spend a week implementing it :) Best, Riyad On Thursday 27 May 2004 08:49 am, Mike Zatko wrote: I personally think its too big. Large amounts of data like that should be put in request scope so that it gets flushed out of memory right away. If you need the data to be persistent through the user's session lifetime, mabye try serializing it to a database. Of course, different situations call for different solutions. Also, I would try and replace your Vector with a non-synchronized Collection like an ArrayList or LinkedList unless you have some sort of mutlithreaded access to this collection. Riyad Kalla wrote: Larry, Good question. I am curious what others think about this situation as well. On Thursday 27 May 2004 08:24 am, Zhang, Larry (L.) wrote: It is apparent true that if the session size is big, the performance will be negatively affected. The question is that how to actively control the size of session. Let's discuss this question: I have a page which displays all the subordinates of a manager, for some reasons I want to create a List or a Vector containing all the subordinates and put this List or Vector to the session. Each element in the List or Vector is a Java object, Employee( each Employee object has 200 String attributes, among which 5 are needed to be displayed on the screen) A picture of this situation is: Vector allSubordinates = new Vector(); allSubordinates.add(Employee1); allSubordinates.add(Employee2); ... allSubordinates.add(Employee1000); session.setAttribute(allSubordinates,allSubordinates); Do you think this actually makes the session very big? Then what will be the improvement of the following? Instead of add all the employee objects, we create a very small object called DisplayObject, which just contains the 5 attributes required on the screen. Vector allSubordinates = new Vector(); allSubordinates.add(DisplayObject1); allSubordinates.add(DisplayObject2); ... allSubordinates.add(DisplayObject1000); session.setAttribute(allSubordinates,allSubordinates); Your sharing of opinion is appreciated! Thanks. Larry - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: nl2br equivalent?
Another way to do it is to create a wrapper method in your form that does the replacing. So if you have a text property in the form, create a textAsHTML method that return the test property with the line breaks replaced. That could get ugly if you have lots of fields like that, so I would then suggest using a taglib. What's the downfall in adding another taglib? I think it is certainly cleaner than the scriplet method you have below. Daniel Perry wrote: usefull... though it adds yet another tag library to my pages! best i came up with is: % pageContext.setAttribute(lf, \n); % c:out value=${fn:replace(employee.contactAddress,lf, 'br')} escapeXml=false/ is there really no escape sequence for new line in el? Would seem like a rather big shortfall to me! Daniel. -Original Message- From: Niall Pemberton [mailto:[EMAIL PROTECTED] Sent: 25 May 2004 18:17 To: Struts Users Mailing List Subject: Re: nl2br equivalent? http://jakarta.apache.org/taglibs/doc/string-doc/index.html#replace - Original Message - From: Daniel Perry [EMAIL PROTECTED] To: Struts User List [EMAIL PROTECTED] Sent: Tuesday, May 25, 2004 5:50 PM Subject: nl2br equivalent? I am a bit surprised, but there doesn't seem to be an equivalent to php's incredibly useful nl2br in jstl... Is there an easy method I'm missing that will output a string after converting line breaks to br tags? Daniel. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: indexed=true is only valid within an enclosing iterate tag
Sorry if this is confusing, I'll explain what I am trying to do. I want to give the use a form with a number of interests and I want to track which ones they check off. The way I thought to do it is have a form with a List property called interests. I would have an action prepopulate the interests property with Interest objects. I guess the Interest object would have to have a boolean selected property that is initially set to false, which would make all the options appear unchecked, and then when the user submits the form to a different action, I would store the interests in the database where selected is true. Is that how you normally handle an indexed property like this? I haven't really gotten very far in figuring this out yet because of the problem with the indexed attribute. I just made up this JSP example because it illustrates the point that no matter what I do, I seem to get the must be in an interate tag exception. I put your code into my jsp page: %@ taglib uri=http://jakarta.apache.org/struts/tags-html; prefix=html % %@ taglib uri=http://java.sun.com/jstl/core; prefix=c % html:html body % java.util.ArrayList interests = new java.util.ArrayList(); java.util.HashMap map = new java.util.HashMap(); map.put(code,ABC); interests.add(map); request.setAttribute(interests,interests); % c:forEach var=interest items=${interests} pInterest: html:text indexed=true name=interest property=code//p /c:forEach /body /html:html Still get the same exception. Niall Pemberton wrote: No worries. Your stuff's a bit confusing. On your html:form you have an action named interest and you don't specify a name attribute on your html:checkbox. That means the checkbox tag is going to try and get the form associated with your interest action (if it doesn't exist, it'll try and create it) and then try to retrieve the property you named which is ${interest.code}, plus the fact you are storing a interests object in request scope. I changed your code and the following worked for me, the only difference is I don't use the el versions of the struts tags - just the standard ones: % java.util.ArrayList interests = new java.util.ArrayList(); java.util.HashMap map = new java.util.HashMap(); map.put(code,ABC); interests.add(map); request.setAttribute(interests,interests); % c:forEach var=interest items=${interests} pInterest: html:text indexed=true name=interest property=code//p /c:forEach ... and it produced: pInterest: input type=text name=interest[0].code value=ABC/p Niall - Original Message - From: Paul Barry [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, May 06, 2004 8:55 PM Subject: Re: indexed=true is only valid within an enclosing iterate tag Sorry for replying directly to you Niall. I meant to reply to the whole list. I think when you reply to a message you are replying to the user list and me individually, because I get two copies of each message that you post. The reply-to on one of them it set to the struts user list, and the reply-to on the other is set to your address, so I guess I replied to the wrong one. Anyway, here is the full code: %@ taglib uri=http://jakarta.apache.org/struts/tags-html-el; prefix=html % %@ taglib uri=http://jakarta.apache.org/struts/tags-logic-el; prefix=logic % %@ taglib uri=http://java.sun.com/jstl/core; prefix=c % html:html body % java.util.ArrayList interests = new java.util.ArrayList(); java.util.HashMap map = new java.util.HashMap(); map.put(code,ABC); interests.add(map); request.setAttribute(interests,interests); % html:form action=interest c:forEach var=interest varStatus=loop items=${interests} html:checkbox indexed=true property=${interest.code}/ /c:forEach /html:form /body /html:html The JSP scriplet fakes what normally happens in a action before getting to the JSP. Here is the exceptioin I get: javax.servlet.jsp.JspException: indexed=true is only valid within an enclosing iterate tag at org.apache.struts.taglib.html.BaseHandlerTag.prepareIndex(BaseHandlerTag.jav a:663) at org.apache.struts.taglib.html.CheckboxTag.doStartTag(CheckboxTag.java:188) at org.apache.strutsel.taglib.html.ELCheckboxTag.doStartTag(ELCheckboxTag.java: 531) at _test__jsp._jspService(/test.jsp:14) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:536) Is it possible that this problem has
Re: indexed=true is only valid within an enclosing iterate tag
Sorry for replying directly to you Niall. I meant to reply to the whole list. I think when you reply to a message you are replying to the user list and me individually, because I get two copies of each message that you post. The reply-to on one of them it set to the struts user list, and the reply-to on the other is set to your address, so I guess I replied to the wrong one. Anyway, here is the full code: %@ taglib uri=http://jakarta.apache.org/struts/tags-html-el; prefix=html % %@ taglib uri=http://jakarta.apache.org/struts/tags-logic-el; prefix=logic % %@ taglib uri=http://java.sun.com/jstl/core; prefix=c % html:html body % java.util.ArrayList interests = new java.util.ArrayList(); java.util.HashMap map = new java.util.HashMap(); map.put(code,ABC); interests.add(map); request.setAttribute(interests,interests); % html:form action=interest c:forEach var=interest varStatus=loop items=${interests} html:checkbox indexed=true property=${interest.code}/ /c:forEach /html:form /body /html:html The JSP scriplet fakes what normally happens in a action before getting to the JSP. Here is the exceptioin I get: javax.servlet.jsp.JspException: indexed=true is only valid within an enclosing iterate tag at org.apache.struts.taglib.html.BaseHandlerTag.prepareIndex(BaseHandlerTag.java:663) at org.apache.struts.taglib.html.CheckboxTag.doStartTag(CheckboxTag.java:188) at org.apache.strutsel.taglib.html.ELCheckboxTag.doStartTag(ELCheckboxTag.java:531) at _test__jsp._jspService(/test.jsp:14) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:536) Is it possible that this problem has something to do with me using resin? Guess I could download and setup tomcat to test... Niall Pemberton wrote: Well it works fine for me - so I'm at a loss to explain. Maybe you should post the actual jsp code you are using - you said the jsp code looked like this: c:forEach var=item items=${items} html:text name=item property=code/ /c:forEach but the exception you show is for the EL version of the checkbox tag. Also its better if you post to the struts user list rather than directly to me - someone who knows more than me or has experienced your problem may jump in if you post to the list. Niall - Original Message - From: Paul Barry [EMAIL PROTECTED] To: Niall Pemberton [EMAIL PROTECTED] Sent: Thursday, May 06, 2004 1:42 PM Subject: Re: indexed=true is only valid within an enclosing iterate tag I am using Struts 1.1, I just copied jstl.jar, struts.jar and struts-el.jar into my project lib directory to be sure. Still getting the exception: javax.servlet.jsp.JspException: indexed=true is only valid within an enclosing iterate tag at org.apache.struts.taglib.html.BaseHandlerTag.prepareIndex(BaseHandlerTag.jav a:663) at org.apache.struts.taglib.html.CheckboxTag.doStartTag(CheckboxTag.java:188) at org.apache.strutsel.taglib.html.ELCheckboxTag.doStartTag(ELCheckboxTag.java: 531) I checked the source code around line 663 of BaseHandlerTag, here is what it looks like: // Look for JSTL loops if (iterateTag == null) { Integer i = getJstlLoopIndex(); if (i != null) { index = i.intValue(); found = true; } } else { index = iterateTag.getIndex(); found = true; } if (!found) { // this tag should only be nested in iteratetag, if it's not, throw exception JspException e = new JspException(messages.getMessage(indexed.noEnclosingIterate)); RequestUtils.saveException(pageContext, e); throw e; } Seems as though getJstlLoopIndex() isn't doing it's job, any ideas why? I have tried it with declaring the Loop Status in the c:forEach with varStatus=loop and without, still get the exception. Niall Pemberton wrote: Hmmm. The thinking behind my suggestion was is jstl working properly for you or is the indexed thing just hinding some other root cause I'm out of ideas - the only other thing I can think of is what version of Struts are you using - I believe jstl was only catered for from Struts 1.1 - so if you were using a version before that you would get the message you're seeing. Niall - Original Message - From: Paul Barry [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 10:21 PM Subject: Re: indexed=true is only valid within an enclosing iterate tag Yeah, if I remove the indexed=true, my JSP code looks like this: c:forEach var=item items=${items} html:text name=item
indexed=true is only valid within an enclosing iterate tag
I am trying to use indexed properties in a form, as described in James Turner's Article Succeeding With Struts: Indexed Properties and Beans as Properties at http://www.developer.com/java/ejb/article.php/2233591 The example shows you can use c:forEach with html:text indexed=true/, like this: c:forEach var=lines items=${purchaseOrderBeanForm.map.lines} TRTDhtml:text indexed=true name=lines property=partNumber//TD TDhtml:text indexed=true name=lines property=quantity//TD TDhtml:text indexed=true name=lines property=price//TD/TR /c:forEach But when I try to do that, I get this error: indexed=true is only valid within an enclosing iterate tag Is my code wrong or is the example wrong? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: indexed=true is only valid within an enclosing iterate tag
If I do this: c:forEach var=item varStatus=loop items=${items} html:text property=items[${loop.index}].code/ /c:forEach It gives me the results I want: input type=text name=interests[0].code value=ABC / input type=text name=interests[1].code value=BCD / ... But I can't get indexed=true to work with c:forEach Paul Barry wrote: Yeah, if I remove the indexed=true, my JSP code looks like this: c:forEach var=item items=${items} html:text name=item property=code/ /c:forEach I get a bunch of HTML inputs like this: input type=text name=code value=ABC / With different values but all named code. Code is a property of item, and each item in items has a different code. Niall Pemberton wrote: What happens if you remove the indexed attribute from all the html:text - does it work properly then (except for the name attribute) is the html page generated OK? Niall - Original Message - From: Paul Barry [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 9:49 PM Subject: indexed=true is only valid within an enclosing iterate tag I am trying to use indexed properties in a form, as described in James Turner's Article Succeeding With Struts: Indexed Properties and Beans as Properties at http://www.developer.com/java/ejb/article.php/2233591 The example shows you can use c:forEach with html:text indexed=true/, like this: c:forEach var=lines items=${purchaseOrderBeanForm.map.lines} TRTDhtml:text indexed=true name=lines property=partNumber//TD TDhtml:text indexed=true name=lines property=quantity//TD TDhtml:text indexed=true name=lines property=price//TD/TR /c:forEach But when I try to do that, I get this error: indexed=true is only valid within an enclosing iterate tag Is my code wrong or is the example wrong? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: indexed=true is only valid within an enclosing iterate tag
I meant input type=text name=items[0].code value=ABC / input type=text name=items[1].code value=BCD / Paul Barry wrote: If I do this: c:forEach var=item varStatus=loop items=${items} html:text property=items[${loop.index}].code/ /c:forEach It gives me the results I want: input type=text name=interests[0].code value=ABC / input type=text name=interests[1].code value=BCD / ... But I can't get indexed=true to work with c:forEach Paul Barry wrote: Yeah, if I remove the indexed=true, my JSP code looks like this: c:forEach var=item items=${items} html:text name=item property=code/ /c:forEach I get a bunch of HTML inputs like this: input type=text name=code value=ABC / With different values but all named code. Code is a property of item, and each item in items has a different code. Niall Pemberton wrote: What happens if you remove the indexed attribute from all the html:text - does it work properly then (except for the name attribute) is the html page generated OK? Niall - Original Message - From: Paul Barry [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 9:49 PM Subject: indexed=true is only valid within an enclosing iterate tag I am trying to use indexed properties in a form, as described in James Turner's Article Succeeding With Struts: Indexed Properties and Beans as Properties at http://www.developer.com/java/ejb/article.php/2233591 The example shows you can use c:forEach with html:text indexed=true/, like this: c:forEach var=lines items=${purchaseOrderBeanForm.map.lines} TRTDhtml:text indexed=true name=lines property=partNumber//TD TDhtml:text indexed=true name=lines property=quantity//TD TDhtml:text indexed=true name=lines property=price//TD/TR /c:forEach But when I try to do that, I get this error: indexed=true is only valid within an enclosing iterate tag Is my code wrong or is the example wrong? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT] Oracle JDev 10g Final (9.0.5.1 build 1605) is out!
I have been using Eclipse for a while now. It is a little slow a times, but overall works pretty well. Have any eclipse users tried JDeveloper? Any reason to switch? Is JDeveloper free? Amjad Shahrour wrote: Just wanted to say my toughts about Jdeveloper10g. Simply it is GREATE!!. And there is no other IDE that can even compete with it. *It has everything that I need. * extraordinary performace ( I cant believe its pure java ;) ) * very very very organized. * I feel very comfortable when I use it. * this what IDEs should be. * IMO it is far better than VS.net. good work Jdeveloper10g team. I am Looking forward a plugin that simplyfies the JSF development (visually). regards Amjad Shahrour Application Developer Tel: +966.2.653.3334 ext 213 [EMAIL PROTECTED] www.labbaik.com -Original Message- From: Duncan Mills [mailto:[EMAIL PROTECTED] Sent: Sunday, April 18, 2004 11:12 AM To: Struts Users Mailing List Subject: Re: [OT] Oracle JDev 10g Final (9.0.5.1 build 1605) is out! Eric it's a pure Java App - you can run it on Mac, Linux or whatever - plenty of people did run the Preview on Mac without too many problems - if you have any problems or issues just post them on OTN. Regards Duncan Mills Senior Principal Product Manager Oracle Application Development Tools [EMAIL PROTECTED] Erik Price wrote: On Apr 14, 2004, at 4:24 AM, Christian Bollmeyer wrote: Finally! http://otn.oracle.com/software/products/jdev/index.html (249MB) -- Chris No MacOSX version? :( - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Pfont face=Arial, Helvetica, sans-serif size=2 style=font-size:13.5px___BRDIVFONT color=#5472b6Labbaik - The Integrated Solution Provider for the Hospitality Industry/FONT/DIV/font - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
html:text for Date property
What is the best way to deal with a Date property in an ActionForm? My ActionForm has a object that has a Date property that I want to set. So I have html:text property=object.date If I populate the that property in the Action like this: MyObject obj = new MyObject(); obj.setDate(new Date()); form.setObject(obj); The html:text tag does a toString() on the object.date property. How can I get it to display in the MM/DD/ format instead? Likewise, how do I make it so the user can enter a date in the format of MM/DD/ and have it correctly set the Date property? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html:text for Date property
Yeah, I guess I could do that. I think need 2 properties. I would create a dateAsString property, have the form get and set that, and then have the getters and setters set and convert the actual Date. This way I can call getDate to get a Date and getDateAsString to get it as a formatted String. Are their other ways to handle this, so I don't need 2 properties? Slattery, Tim - BLS wrote: ActionForm has a object that has a Date property that I want to set. So I have html:text property=object.date If I populate the that property in the Action like this: MyObject obj = new MyObject(); obj.setDate(new Date()); form.setObject(obj); The html:text tag does a toString() on the object.date property. How can I get it to display in the MM/DD/ format instead? Likewise, how do I make it so the user can enter a date in the format of MM/DD/ and have it correctly set the Date property? I'd have the getter format the Date as a string (use SimpleDateFormat.format(), you can specify any of a wide variety of formats). Likewise, the setter should accept a string and use SimpleDateFormat.parse() to turn it into a Date. If parse() returns null then the String could not be turned into a Date, and you need to display an error message. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: html:text for Date property
This seems to work pretty well: private Date dateOfBirth; private static final DateFormat dateOfBirthFormat = new SimpleDateFormat(MM/dd/); public Date getDateOfBirth() { return dateOfBirth; } public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } public String getDateOfBirthString() { return dateOfBirthFormat.format(dateOfBirth); } public void setDateOfBirthString(String dateOfBirthString) throws ParseException { this.dateOfBirth = dateOfBirthFormat.parse(dateOfBirthString); } And then I use dateOfBirthString as the property in the html:text tag. I'll also create a rule in the validator to make sure that dateOfBirthString is the right format, so the ParseException never happens. Christian Bollmeyer wrote: On Friday 09 April 2004 21:19, Paul Barry wrote: Generally, it's a good idea to have only String and boolean properties in an ActionForm and convert the information gathered for further processing lateron. For complex validations (like Dates), I usually check in validate() if the value entered can be successfully converted via SimpleDateFormat and do the actual conversion when populating the VO bean. But you can have 2 properties in the form as well. HTH, -- Chris. BTW, as such conversions are needed quite often, it's a good idea to write a small utility function that does the conversion check and put it in either your BaseActionForm or some general utility class. Yeah, I guess I could do that. I think need 2 properties. I would create a dateAsString property, have the form get and set that, and then have the getters and setters set and convert the actual Date. This way I can call getDate to get a Date and getDateAsString to get it as a formatted String. Are their other ways to handle this, so I don't need 2 properties? Slattery, Tim - BLS wrote: ActionForm has a object that has a Date property that I want to set. So I have html:text property=object.date If I populate the that property in the Action like this: MyObject obj = new MyObject(); obj.setDate(new Date()); form.setObject(obj); The html:text tag does a toString() on the object.date property. How can I get it to display in the MM/DD/ format instead? Likewise, how do I make it so the user can enter a date in the format of MM/DD/ and have it correctly set the Date property? I'd have the getter format the Date as a string (use SimpleDateFormat.format(), you can specify any of a wide variety of formats). Likewise, the setter should accept a string and use SimpleDateFormat.parse() to turn it into a Date. If parse() returns null then the String could not be turned into a Date, and you need to display an error message. --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
validator one of multiple fields required
Is there an easy way to check that at least one of multiple fields is filled in with the validator? Kind of like: if(username != null || firstname != null || lastname != null) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with Formbean validate method forwarding to input page
Make your input action an error page, which just has the error and no sensitive data and make a success forward that you only send the user to if everything checks out. Todd Bryant wrote: I have need for every page in my web app to be secure. What I originally did was extend the Action class to make a secure action class. The SecureAction's perform method validates that the user is logged in and if not, sends them to the login page. All actions in my app extend SecureAction. To protect my jsp's, I put them in a subfolder of WEB-INF, WEB-INF/jsp. This way a user cannot directly access any jsp. They can only be accessed through a forward in an action. This completely secures all resources in my application. This is where I run into a problem. If I use the validate() method of the formbean and it returns a non-empty ActionErrors object, then the request is diverted to resource that is set as the input, in this case a jsp. Because of this, if a user were to put in some bogus field values in the url, she would be able to cause the formbean to no validate and get the jsp to display, bypassing the secure action. I can secure each jsp, but this is redundant if I have them in the WEB-INF folder in the first place. I would rather avoid this fix. I know that overriding the default action class is a common way to secure your app as I have read about it more than one place, however, I have never seen this problem addressed. Has anyone else ran across this problem before and come up with a solution? Thanks in advance. Todd Bryant Programmer/Analyst University of Nebraska Foundation 402-472-0107 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with Formbean validate method forwarding to input page
Maybe you should be handling your security in the request processor. Have a method like this: protected ActionForward processActionPerform( HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException { try { validSession(request); return (action.execute(mapping, form, request, response)); } catch (SecurityException e) { return (processException(request, response,e, form, mapping)); } } Where validateSession throws a SecurityException if the user is not logged in and processException knows where to send the user to log in. There are different ways to do it, but the basic principle is to authenticate the user's session before the Action executes, so you don't have to worry about that in the Action. Todd Bryant wrote: That is a good suggestion, and I had thought of that, but the problem is that a user would have to go from the error page back to the page they were on. This would make it prohibitively difficult to interact with this particular app (too many clicks). -Original Message- From: Paul Barry [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 4:07 PM To: Struts Users Mailing List Subject: Re: Problem with Formbean validate method forwarding to input page Make your input action an error page, which just has the error and no sensitive data and make a success forward that you only send the user to if everything checks out. Todd Bryant wrote: I have need for every page in my web app to be secure. What I originally did was extend the Action class to make a secure action class. The SecureAction's perform method validates that the user is logged in and if not, sends them to the login page. All actions in my app extend SecureAction. To protect my jsp's, I put them in a subfolder of WEB-INF, WEB-INF/jsp. This way a user cannot directly access any jsp. They can only be accessed through a forward in an action. This completely secures all resources in my application. This is where I run into a problem. If I use the validate() method of the formbean and it returns a non-empty ActionErrors object, then the request is diverted to resource that is set as the input, in this case a jsp. Because of this, if a user were to put in some bogus field values in the url, she would be able to cause the formbean to no validate and get the jsp to display, bypassing the secure action. I can secure each jsp, but this is redundant if I have them in the WEB-INF folder in the first place. I would rather avoid this fix. I know that overriding the default action class is a common way to secure your app as I have read about it more than one place, however, I have never seen this problem addressed. Has anyone else ran across this problem before and come up with a solution? Thanks in advance. Todd Bryant Programmer/Analyst University of Nebraska Foundation 402-472-0107 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ORM Tools (Ibatis, Hibernate, OJB....)
I don't know much about ORM toools, but I can say that iBatis SQL Maps is not an ORM tool. As I understand it, ORM tools map java object to database tables, whereas SQL Maps map java objects to SQL statements. iBatis just makes using JDBC much easier, whereas ORM tools hide the JDBC from you, doing the persistence work for you. Hibernate and OJB might be useful depending on your project, but SQL Maps will be an easier transition for you if you are used to working with JDBC, especially in a place where you may have people that specifically work on writing and tuning SQL queries. Marcelo Epstein wrote: Hi, Thanks everybody! Now I am convinced to use an ORM tool. The big problem is whitch one? Hibernate? Ibatis ?OJB? Whitch one is preferable to use with Struts?? Macelo Epstein On Tue, 06 Apr 2004 11:29:21 -0600, Larry Meadors [EMAIL PROTECTED] escreveu: De: Larry Meadors [EMAIL PROTECTED] Data: Tue, 06 Apr 2004 11:29:21 -0600 Para: [EMAIL PROTECTED] Assunto: Re: Connection Pooling (How i use...) I have yet to see a *good* example of how to do jdbc on the net. Most are very simple one-off throws SQLException examples that don't seem to take into consideration little things like stability and releasing resources. :) That is why I think tools like iBATIS are so powerful - you get all the power of JDBC without the pain. Larry [EMAIL PROTECTED] 04/06/04 11:15 AM Now I am closing the connection in the finally block. The exemple... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: BeanUtils.copyProperties() throws java.lang.IllegalArgumentException: No origin bean specified
Yeah, it was actually my dao that returning a null UserBO. Makes since, sense user is the origin. Marco Mistroni wrote: Hi, Make sure that the userForm is not null.. I m using BeanUtils.copyProperties all the time and it Just work fine Hope this helps Regards marco -Original Message- From: Paul Barry [mailto:[EMAIL PROTECTED] Sent: 02 April 2004 00:12 To: [EMAIL PROTECTED] Subject: BeanUtils.copyProperties() throws java.lang.IllegalArgumentException: No origin bean specified I am trying to use BeanUtil.copyProperties() as described in 5.6.7 in Struts in Action (Husted). I have an Interface UserBO which my ActionForm implements. I also have a standard JavaBean UserBOImpl which implements the Interface. I have a DAO that returns a UserBOImpl. I would like to use BeanUtils.copyProperties() to copy all of the UserBOImpl properties into the ActionForm. So I am trying this code in the execute method of my Action: UserBO user = dao.getUser(myForm.getId()); UserBO userForm = (UserBO)form; BeanUtils.copyProperties(userForm,user); myForm is just the ActionForm cast into the ActionForm I wrote that implements UserBO. This code compiles, but when it runs I get a java.lang.IllegalArgumentException: No origin bean specified. Does anyone know why I am getting this error? Is anyone else doing something like this? Anyone getting this error? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
validator integer required
I have an ActionForm with an int property called id. If I use the validator required validation, it always passes the validation, even if there is no request parameter called id. Is this is correct behavior, or am I doing something wrong? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [OT] UI Suggestion Request
I have seen people create a link to a pop-up window next to the a text input box. The pop-up window has a scrolling, possibly paged list of the descriptions you want the users to be able to select from. Each description is a hyperlink and when the user clicks on one of the descriptions, the pop-window closes and uses javascript to update the input text field with the code corresponding to the link the user clicked on. Avinash Gangadharan wrote: Hello All, I have a field in a form which expects a predefined set of data existing in the database. The dataset is of type code-description, where the user is expected to select or enter a description and the form passes back a code for it. This can be presented best in the form of a dropdown list. But my problem is that this set of data is huge ( around 200 rows ) and the descriptions for each code is also pretty long. What do you guys think could be a good replacement of the drop down list to prevent any bad data entry. I want to force the users to do something like a search and select kind of thing. Thanks Avinash - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validator and dispatch action
Ah, I got you now. No, I didn't try that, I will give it a try. Adam Hardy wrote: I mean, try changing it in the code in your action when you want to validate, change it back afterwards to its previous value when done. Is that what you tried? String oldName = mapping.getName(); mapping.setName(widget-edit); form.validate(mapping, request); mapping.setName(oldName); On 03/31/2004 05:52 PM Paul Barry wrote: The name of the action-mapping has to correspond to the name of the form-bean. Adam Hardy wrote: If I really wanted to stick with your set-up, I see a way it might be possible, although I have not done this myself. Try changing the 'name' attribute of the mapping to the validation that you defined in the validation.xml, e.g. 'widget-update' or 'widget-edit' and then call the validate() method. My main worry is that ActionMapping may not like being changed, but if so, you could instantiate a new one. Adam On 03/31/2004 05:18 PM Paul Barry wrote: Hello Everyone, I am using the validator and dispatch actions and I am wonder what the best way to do this is. Consider that I have the following method in a dispatch action: add- populates collections for drop-down lists, forwards to jsp page create - needs to do validation and store in database edit - needs to populate form with the data to edit, forward to jsp page update - needs to do validation and update database delete - needs to delete a record from the database You can see how the validation would be different for these actions. Let's say this is a dispatch action related to administrating users. So for add, there would be no validation, it just gets the data need to build the form. For create, there might be a password and verify password field that need to be validated, but update wouldn't have those fields. Edit and delete would have to have a parameter for the primary key of the record to edit or delete. Now I found something related at this link: http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction Which says to set validate to false in the struts-config.xml and then call validate method within each method of the dispatch action, like this: ActionErrors errors = new ActionErrors(); errors = form.validate(mapping, request); // Report any errors we have discovered back to the original form if (!errors.isEmpty()) { saveErrors(request, errors); return new ActionForward(mapping.getInput()); } This seems like a really good solution to me, but there is one problem. How do you call a different set of validation rules, based on which method you are in? Doesn't this need to be something like this: edit() { ActionErrors errors = new ActionErrors(); errors = form.validateEdit(mapping, request); } update() { ActionErrors errors = new ActionErrors(); errors = form.validateUpdate(mapping, request); } Because the rules for validating edit and update are different. You could define different action-mappings in your struts config for each dispatch method, and then a form in your validation.xml for each action-mapping, where the form name is the same as the path property of the action-mapping, but doesn't this defeat the purpose of the dispatch action? Why not just have separate actions at that point? I think the answer is to just not use the dispatch action with the validator, but I wanted to know if others had found a way to do it. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validator and dispatch action
Yeah, I guess that would work, but seems kludgey. Wouldn't it be easier to just have separate actions for each operation? The struts books that I have read (Struts in Action, Husted and Programming Jakarta Struts, Cavaness) claim that the dispatch action makes the application easier to maintain by grouping related operations together, but it seems that it makes using the validator more difficult. Have others found this to be the case? Adam Hardy wrote: Sorry, that's the only property you do NOT want to copy! I mean all the others. On 03/31/2004 06:44 PM Adam Hardy wrote: It's worth trying it with a new mapping then. Copy across the relevant bits from the real mapping, in pseudocode: newMapping = new Mapping(); newMapping.setName(origMapping.getName()); etc. On 03/31/2004 06:37 PM Takhar, Sandeep wrote: I thought there used to be a way in the struts-config to say use this form name even though we are using the same class name= property=?? It would still require a different mapping...if it is true sandeep -Original Message- From: Paul Barry [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 31, 2004 11:29 AM To: Struts Users Mailing List Subject: Re: validator and dispatch action I get this exception: javax.servlet.ServletException: Configuration is frozen Adam Hardy wrote: I mean, try changing it in the code in your action when you want to validate, change it back afterwards to its previous value when done. Is that what you tried? String oldName = mapping.getName(); mapping.setName(widget-edit); form.validate(mapping, request); mapping.setName(oldName); On 03/31/2004 05:52 PM Paul Barry wrote: The name of the action-mapping has to correspond to the name of the form-bean. Adam Hardy wrote: If I really wanted to stick with your set-up, I see a way it might be possible, although I have not done this myself. Try changing the 'name' attribute of the mapping to the validation that you defined in the validation.xml, e.g. 'widget-update' or 'widget-edit' and then call the validate() method. My main worry is that ActionMapping may not like being changed, but if so, you could instantiate a new one. Adam On 03/31/2004 05:18 PM Paul Barry wrote: Hello Everyone, I am using the validator and dispatch actions and I am wonder what the best way to do this is. Consider that I have the following method in a dispatch action: add- populates collections for drop-down lists, forwards to jsp page create - needs to do validation and store in database edit - needs to populate form with the data to edit, forward to jsp page update - needs to do validation and update database delete - needs to delete a record from the database You can see how the validation would be different for these actions. Let's say this is a dispatch action related to administrating users. So for add, there would be no validation, it just gets the data need to build the form. For create, there might be a password and verify password field that need to be validated, but update wouldn't have those fields. Edit and delete would have to have a parameter for the primary key of the record to edit or delete. Now I found something related at this link: http://nagoya.apache.org/wiki/apachewiki.cgi?ValidatorDispatchAction Which says to set validate to false in the struts-config.xml and then call validate method within each method of the dispatch action, like this: ActionErrors errors = new ActionErrors(); errors = form.validate(mapping, request); // Report any errors we have discovered back to the original form if (!errors.isEmpty()) { saveErrors(request, errors); return new ActionForward(mapping.getInput()); } This seems like a really good solution to me, but there is one problem. How do you call a different set of validation rules, based on which method you are in? Doesn't this need to be something like this: edit() { ActionErrors errors = new ActionErrors(); errors = form.validateEdit(mapping, request); } update() { ActionErrors errors = new ActionErrors(); errors = form.validateUpdate(mapping, request); } Because the rules for validating edit and update are different. You could define different action-mappings in your struts config for each dispatch method, and then a form in your validation.xml for each action-mapping, where the form name is the same as the path property of the action-mapping, but doesn't this defeat the purpose of the dispatch action? Why not just have separate actions at that point? I think the answer is to just not use the dispatch action with the validator, but I wanted to know if others had found a way to do it. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail