Re: [S2.2.1] Struts Type Converter for sub-model objects not working?
Look at the bottom of your message and also the top. 'contact.contactLead.income' evaluated to '$123' and you do not have a method com.afs.entity.ContactLead.setIncome([Ljava.lang.String;)] Scott On Fri, Dec 10, 2010 at 2:53 PM, Burton Rhodes burtonrho...@gmail.comwrote: I am having issues trying to get a Type Converter to run when converting a field that is a sub-object of the main model. For example, I have a Contact class that contains a ContactLead class. I have an Action class that saves a new Contact and ContactLead at the same time. Originally, I set up my ContactCreateAction-conversion.properties file to convert the contact.contactLead.income field (three levels deep). However, MyCurrencyConverter class never gets called. I then changed my Action and Jsp pages to have seperate Contact and ContactLead objects and changed the conversion.properties file to convert contactLead.income. In this case, MyCurrencyConverter is called and everything works fine. Although everything is fine, shouldn't the conversion be recursive? Is this supposed to work, and I'm doing something wrong? I have tried it both ways several times to make sure I didn't just mess something up, but each time I'm getting the same result. Any comments welcome. Below are code snippets only. *** DOES NOT WORK *** ContactCreateAction-conversion.properties: contact.contactLead.income=com.afs.web.converter.MyCurrencyConverter Jsp File: s:textfield name=contact.contactLead.income value=%{getText('format.money',{contact.contactLead.income != null ? contact.contactLead.income :''})} / *** DOES WORK *** ContactCreateAction-conversion.properties: contactLead.income=com.afs.web.converter.MyCurrencyConverter Jsp File: s:textfield name=contactLead.income value=%{getText('format.money',{contactLead.income != null ? contactLead.income :''})} / The Contact Class // Most code ommitted public class Contact implements Serializable { @Id @GeneratedValue @Column(name = ContactId) private Integer contactId; @OneToOne(cascade = { CascadeType.ALL }, fetch=FetchType.LAZY) @JoinColumn(name=ContactLeadId) private ContactLead contactLead; ... More veriables and getters/setters below } *** THE ERROR *** Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The first TextProvider in the ValueStack (com.afs.web.action.contact.ContactCreateAction) could not locate the message resource with key 'contact.contactLead.income' Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The default value expression 'contact.contactLead.income' was evaluated and did not match a property. The literal value 'contact.contactLead.income' will be used. Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The first TextProvider in the ValueStack (com.afs.web.action.contact.ContactCreateAction) could not locate the message resource with key 'contact.contactLead.nextStepDate' Dec 10, 14:41:50 (CommonsLogger.java:56) WARN : The default value expression 'contact.contactLead.nextStepDate' was evaluated and did not match a property. The literal value 'contact.contactLead.nextStepDate' will be used. Dec 10, 14:41:55 (CommonsLogger.java:60) WARN : Error setting expression 'contact.contactLead.income' with value '[Ljava.lang.String;@1fbc2c7' ognl.MethodFailedException: Method setIncome failed for object com.afs.entity.contactl...@16e1c2c [java.lang.NoSuchMethodException: com.afs.entity.ContactLead.setIncome([Ljava.lang.String;)] at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1285) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2245) at ognl.ASTProperty.setValueBody(ASTProperty.java:127) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.ASTChain.setValueBody(ASTChain.java:227) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.Ognl.setValue(Ognl.java:737) at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209) at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:288) at
Re: [S2.2.1] Struts Type Converter for sub-model objects not working?
I know. I don't have a setIncome(String) method. But I do have setIncome(BigDecimal) method , hence the type conversion. Normally the class MyCurrencyCoverter will covert the String to BigDecimal, but it's never called. I am wondering what I am doing wrong that the conversion class is not called. On Saturday, December 11, 2010, stanl...@gmail.com wrote: Look at the bottom of your message and also the top. 'contact.contactLead.income' evaluated to '$123' and you do not have a method com.afs.entity.ContactLead.setIncome([Ljava.lang.String;)] Scott On Fri, Dec 10, 2010 at 2:53 PM, Burton Rhodes burtonrho...@gmail.comwrote: I am having issues trying to get a Type Converter to run when converting a field that is a sub-object of the main model. For example, I have a Contact class that contains a ContactLead class. I have an Action class that saves a new Contact and ContactLead at the same time. Originally, I set up my ContactCreateAction-conversion.properties file to convert the contact.contactLead.income field (three levels deep). However, MyCurrencyConverter class never gets called. I then changed my Action and Jsp pages to have seperate Contact and ContactLead objects and changed the conversion.properties file to convert contactLead.income. In this case, MyCurrencyConverter is called and everything works fine. Although everything is fine, shouldn't the conversion be recursive? Is this supposed to work, and I'm doing something wrong? I have tried it both ways several times to make sure I didn't just mess something up, but each time I'm getting the same result. Any comments welcome. Below are code snippets only. *** DOES NOT WORK *** ContactCreateAction-conversion.properties: contact.contactLead.income=com.afs.web.converter.MyCurrencyConverter Jsp File: s:textfield name=contact.contactLead.income value=%{getText('format.money',{contact.contactLead.income != null ? contact.contactLead.income :''})} / *** DOES WORK *** ContactCreateAction-conversion.properties: contactLead.income=com.afs.web.converter.MyCurrencyConverter Jsp File: s:textfield name=contactLead.income value=%{getText('format.money',{contactLead.income != null ? contactLead.income :''})} / The Contact Class // Most code ommitted public class Contact implements Serializable { �...@id �...@generatedvalue �...@column(name = ContactId) private Integer contactId; �...@onetoone(cascade = { CascadeType.ALL }, fetch=FetchType.LAZY) �...@joincolumn(name=ContactLeadId) private ContactLead contactLead; ... More veriables and getters/setters below } *** THE ERROR *** Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The first TextProvider in the ValueStack (com.afs.web.action.contact.ContactCreateAction) could not locate the message resource with key 'contact.contactLead.income' Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The default value expression 'contact.contactLead.income' was evaluated and did not match a property. The literal value 'contact.contactLead.income' will be used. Dec 10, 14:41:49 (CommonsLogger.java:56) WARN : The first TextProvider in the ValueStack (com.afs.web.action.contact.ContactCreateAction) could not locate the message resource with key 'contact.contactLead.nextStepDate' Dec 10, 14:41:50 (CommonsLogger.java:56) WARN : The default value expression 'contact.contactLead.nextStepDate' was evaluated and did not match a property. The literal value 'contact.contactLead.nextStepDate' will be used. Dec 10, 14:41:55 (CommonsLogger.java:60) WARN : Error setting expression 'contact.contactLead.income' with value '[Ljava.lang.String;@1fbc2c7' ognl.MethodFailedException: Method setIncome failed for object com.afs.entity.contactl...@16e1c2c [java.lang.NoSuchMethodException: com.afs.entity.ContactLead.setIncome([Ljava.lang.String;)] at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1285) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org