null value for a nested property
I currently am using an html:text tag on a form to display the name of a state. The tags looks like: html:text name=address property=state.name/ The problem is that ocassionally the state field on the address bean is null. When this occurs the PropertyUtils.getNestedProperty() method throws an IllegalArgumentException which causes my jsp to break. To circumvent this problem I have written my own tag that extends BaseFieldTag and overrides the doStartTag() method. I basically perform the same functions as the BaseFieldTag.doStartTag() method, except that instead of the following call: Object value = RequestUtils.lookup(pageContext, name, property, null); to get the value I catch the IllegalArgumentException and set the return value to an empty string: try{ valueObject = RequestUtils.lookup(pageContext, name, property, null); }catch(IllegalArgumentException e){ //This exception indicates that one of the nested properties returned null //we want to set the value to null and not throw the exception out //to the jsp valueObject = ; } I am wondering if there is a better way of dealing with this problem. I don't like the solution I am using, but I can't think of anything else. How about adding an attribute to the form tags that specify how null property values should be handled? Thanks for your help, Dave -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Testing within Struts Framework
We have been using ant (http://jakarta.apache.org/ant/) to do a nightly build of all of our classes and ejbs and then deploy them to an instance of Orion application server. For each bean we write we write a corresponding JUnit test class that is named by prefixing the name of the bean with Test (so the Customer bean would have a corresponding TestCustomer class). The final step was to write a Perl script that performs the following steps. 1)Shuts down the test instance of Orion 2)Checks the latest version of the application out of CVS 3)Runs our ANT script to build and deploy the classes and Beans to Orion. 4)Starts Orion 5)Runs all of the junit Test classes (see above). 6)Emails a log of all compile and test failures to the development team. We run this script (called the Nun) on a nightly basis. This automated build-deploy-test process (very XP in conception) has led to much better code, immediate notification of both compile time and integration errors, and has made our team development environment possible. We are doing our front end testing using a product called E-Tester developed by Empirix (http://www.empirix.com/Empirix/web+test+monitoring/products/functional+test ing.html). We looked into open source options but the only one we found was HTTPUnit http://httpunit.sourceforge.net/. We found this to be more complicated to use as you have to write code for the tests. Since we have a non-coder developing the front end test suites, this approach would not have worked for us. We have had great success with E-Tester. Dave Boardman Integral7 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Barry Nauta Sent: Tuesday, October 23, 2001 8:00 AM To: [EMAIL PROTECTED] Subject: Testing within Struts Framework I am currently looking at how to test my EJBs within Struts. I have been reading about JUnit, Cactus ( http://jakarta.apache.org/cactus/ ), MockObjects etc. I would like to go as far as implementing mouseclicks within the webpage to simulate user-interaction. Any suggestions/comments/known pitfalls? Barry -- Whatever you do will be insignificant, but it is very important that you do it -- Mahatma Ghandi
deep nesting of value objects in a form bean
I am looking for some confirmation of the approach I have taken in developing an ActionForm that represents an Entity bean hierarchy that nests several beans deep. I have a form bean that I use to update a Candidate entity bean. The Candidate bean has an Address entity bean associated with it, and the Address bean contains both a Country entity bean and a State entity bean. I have created ValueObjects for each of these entity beans so that, for instance, I can call CandidateVO.getAddress().getState().getCode() to retrieve the state code. With the ValueObjects nested in this way I can simply call the setCandidateVO() on the ActionForm and use nested properties in my jsp to interact with the ActionForm. For instance, if the following field were in the jsp, then getCandidateVO().getAddress().getState().setCode() would be called when the form is submitted: html:text property=candidateVO.address.state.code size=2 maxlength=2/ I have then planned on writting updateVO() methods on each of the entity beans that would be used to update the beans from the newly updated ValueObjects. I have 2 questions about this scenario: 1)From what I ahve read, ValueObjects are supposed to be immutable, however, in the scenario above they clearly are not. Is there a way to accomplish the above scenario without making the ValueObjects mutable. 2)If one of the attributes of one of my entity beans is not a String, is there still a way to use nested properties to set that attribute? Or do I need to create a method that does the type conversion in the ActionForm, and then populate the ValueObject back in my Action class? thanks, Dave
populating an ActionForm using BeanUtils.populate
I am attempting to populate an ActionForm from a ValueObject using BeanUtils.populate(). The ActionForm has all of the appropriately named setter methods and attributes, and the ValueObject returns a map with keys corresponding to the attribute names on the ActionForm. The problem is that when I place the value of the ValueObject's id attribute (a Long) in the map, the populate method fails with the following exception: java.lang.IllegalArgumentException: argument type mismatch at java.lang.reflect.Method.invoke(Native Method) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.j ava:986) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.j ava:902) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:93 0) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:506) at com.integral7.web.durango.CandidateDetailAction.perform(CandidateDetailActio n.java:118) It appears that BeanUtils.populate() requires the values in the map to be of type String or String[], is this true? If so, should I be converting the id to a String in the ValueObject.toMap() method? Thanks, Dave
EJB, Form beans, value objects, etc.
I am hoping that someone can clear up what has become a foggy picture in my mind regarding the transfer of data between an ActionForm bean and corresponding entity beans. Ted Husted wrote: Using a nested bean on your ActionForm lets you use the form like a wrapper, so you don't have to define everything twice, if your business beans and ActionForm beans would otherwise be identical I take this to mean that if my ActionForm bean and entity bean are identical then I can supply getters and setters on the ActionForm bean for the entity bean and use the nested bean format in my jsp. In this way my ActionForm will be populated correctly from the entity bean and changes made in the jsp will be reflected in the entity bean. A second scenario occurs when properties on the ActionForm do not match those on the entity bean. In this situation I am a little unclear what to do. One suggestion I read was to create a toMap() method on the ActionForm bean and then use this with the BeanUtils.populate() method to populate your entity bean. My question here does the data transformation take place in the toMap() method, or does BeanUtils.populate() do the transformation for you? Also, this takes care of moving data from the ActionForm bean to the entity bean, but how about doing the opposite (populating the ActionForm bean from the entity bean), does the entity bean also need to expose a toMap() method that can then be used with BeanUtils.populate() to populate the ActionForm bean? A couple final questions: 1)I have seen a lot written about value object beans. From what I gather these seem to be light weight proxies for entity beans. Is this correct? If so what is the advantage to using them over entity beans? How are they typically instantiated, is there a method provided by the entity bean? How does data get from a value object bean to its corresponding entity bean? 2)I have seen several references to PropertyUtils class. Does this class enter in any way to solutions to my questions above? Thanks for your help. Regards, Dave
RE: dynamic template tag parameter values
I have only run the struts 1.0 example, and have not yet downloaded struts 1.1(I could not find it at the Struts site). I downloaded the JAXP reference implementation and placed jaxp.jar, crimson.jar and xalan.jar in my classpath. After restarting Tomcat I got the same error message as before. Thanks, Dave -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ]On Behalf Of Cedric Dumoulin Sent: Monday, September 03, 2001 3:33 AM To: [EMAIL PROTECTED] Subject: Re: dynamic template tag parameter values The tiles tutorial have been moved into the tiles-doc.war file, under 'tutorial'. I think the error is issue because the servlet has failed to start. Are you sure you use a jaxp1.1 compliant parser ? Does Struts1.1 example runs with your configuration ? Cedric David Boardman wrote: A couple of questions about Tiles, When I downloaded the binary distribution I did not see the tiles-tutorial.war file and was therefore missing some of the files necessary to go through your tutorial. Am I missing something in the distribution, or was the tutorial removed. Secondly, when I attempt to run both the tiles-docs application and the tiles-channel application I got an exception with the following message: Tag Insert : Can't get component definition 'mainLayout'. Check if this name exist in component definitions. I simply placed the war files in the webapps directory of my tomcat server to deploy them. thanks for the help. Dave -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ]On Behalf Of Cedric Dumoulin Sent: Friday, August 31, 2001 5:01 AM To: [EMAIL PROTECTED] Subject: Re: dynamic template tag parameter values You can do something like : template:put name=sidebar content='%= /jsps/sidemenu+ clientName+ .jsp%'/ But you certainly have to put some processing before to check if the clientName is valid. Also, you can check Tiles contribution for others ideas. For example, you can adapt the channels example to fit your client names. Cedric Tiles sites : http://www.lifl.fr/~dumoulin/tiles/ (mirror) : http://www.geocities.com/cedricdumoulin/tiles/ David Boardman wrote: Our site will be accessed by users via other sites on the web. For instance, our site might be accessed from a link on Cisco's site. When this occurs we want the GUI to be different than the default GUI (same general layout, but different graphics etc.) To do this I was hoping to include a client parameter in the query string (http://oursite.com/login.jsp?client=Xxx) and then use that to dynamically set the value of the content parameter within a template:put tag to load the appropriate jsp. I believe I can retrieve the query string parameter using bean:parameter id=clientName name=client. However, I am not sure how to dynamically include this value in the content parameter of the template:put tag. For example, my default template currently looks like this: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/top.jsp/ template:put name=sidebar content=/jsps/sidemenu.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footer.jsp/ /template:insert ** for Cisco I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topCisco.jsp/ template:put name=sidebar content=/jsps/sidemenuCisco.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerCisco.jsp/ /template:insert ** and for client=Xxx I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topXxx.jsp/ template:put name=sidebar content=/jsps/sidemenuXxx.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerXxx.jsp/ /template:insert ** Any help would
RE: dynamic template tag parameter values
A couple of questions about Tiles, When I downloaded the binary distribution I did not see the tiles-tutorial.war file and was therefore missing some of the files necessary to go through your tutorial. Am I missing something in the distribution, or was the tutorial removed. Secondly, when I attempt to run both the tiles-docs application and the tiles-channel application I got an exception with the following message: Tag Insert : Can't get component definition 'mainLayout'. Check if this name exist in component definitions. I simply placed the war files in the webapps directory of my tomcat server to deploy them. thanks for the help. Dave -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ]On Behalf Of Cedric Dumoulin Sent: Friday, August 31, 2001 5:01 AM To: [EMAIL PROTECTED] Subject: Re: dynamic template tag parameter values You can do something like : template:put name=sidebar content='%= /jsps/sidemenu+ clientName+ .jsp%'/ But you certainly have to put some processing before to check if the clientName is valid. Also, you can check Tiles contribution for others ideas. For example, you can adapt the channels example to fit your client names. Cedric Tiles sites : http://www.lifl.fr/~dumoulin/tiles/ (mirror) : http://www.geocities.com/cedricdumoulin/tiles/ David Boardman wrote: Our site will be accessed by users via other sites on the web. For instance, our site might be accessed from a link on Cisco's site. When this occurs we want the GUI to be different than the default GUI (same general layout, but different graphics etc.) To do this I was hoping to include a client parameter in the query string (http://oursite.com/login.jsp?client=Xxx) and then use that to dynamically set the value of the content parameter within a template:put tag to load the appropriate jsp. I believe I can retrieve the query string parameter using bean:parameter id=clientName name=client. However, I am not sure how to dynamically include this value in the content parameter of the template:put tag. For example, my default template currently looks like this: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/top.jsp/ template:put name=sidebar content=/jsps/sidemenu.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footer.jsp/ /template:insert ** for Cisco I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topCisco.jsp/ template:put name=sidebar content=/jsps/sidemenuCisco.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerCisco.jsp/ /template:insert ** and for client=Xxx I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topXxx.jsp/ template:put name=sidebar content=/jsps/sidemenuXxx.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerXxx.jsp/ /template:insert ** Any help would be greatly apprecitated. Thanks, David Boardman Integral7
dynamic template tag parameter values
Our site will be accessed by users via other sites on the web. For instance, our site might be accessed from a link on Cisco's site. When this occurs we want the GUI to be different than the default GUI (same general layout, but different graphics etc.) To do this I was hoping to include a client parameter in the query string (http://oursite.com/login.jsp?client=Xxx) and then use that to dynamically set the value of the content parameter within a template:put tag to load the appropriate jsp. I believe I can retrieve the query string parameter using bean:parameter id=clientName name=client. However, I am not sure how to dynamically include this value in the content parameter of the template:put tag. For example, my default template currently looks like this: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/top.jsp/ template:put name=sidebar content=/jsps/sidemenu.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footer.jsp/ /template:insert ** for Cisco I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topCisco.jsp/ template:put name=sidebar content=/jsps/sidemenuCisco.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerCisco.jsp/ /template:insert ** and for client=Xxx I would like it to look like: ** %@ page language=java % %@ taglib uri=/taglibs/struts-template.tld prefix=template % %@ taglib uri=/taglibs/struts-bean.tld prefix=bean % template:insert template=/jsps/template.jsp template:put name=titlebean:message key=candidate.detail.title//template:put template:put name=top content=/jsps/topXxx.jsp/ template:put name=sidebar content=/jsps/sidemenuXxx.jsp/ template:put name=body content=/jsps/loginBody.jsp/ template:put name=footer content=/jsps/footerXxx.jsp/ /template:insert ** Any help would be greatly apprecitated. Thanks, David Boardman Integral7