Announcement Announcement Module
Collapse
No announcement yet.
IllegalArgumentException Cannot convert value of type String to required type Product Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IllegalArgumentException Cannot convert value of type String to required type Product

    Hi to all,

    I receive the exception
    Failed to convert property value of type [java.lang.String] to required type [beans.Product] for property product; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [beans.Product] for property product: no matching editors or conversion strategy found
    in the Errors errors object even before my DetailProductValidator starts validating.


    I don't understand why Spring does that. I don't have any input field that is mapped directly to the product property/object. I just use the product object's properties in the jsp. For example, I use:
    HTML Code:
    <form:options items="${dpBackObj.product.colorMap}"/>
    <!-- or -->
    ${dpBackObj.product.priceInDollars}
    but I never use:
    HTML Code:
    <form:input path="product"/>
    Can anyone please explain why this happens? And maybe inform me of a simple solution?

    The bean configuration for the controller is:
    HTML Code:
    	<!-- DETAIL PRODUCT FORM CONTROLLER -->
    <bean id="productDetailFormController" name="/detail.htm /addToCart.htm" 
    		class="detailProduct.DetailProductFormController">
    	<property name="sessionForm" value="true" />
    	<property name="commandName" value="dpBackObj" />
    	<property name="commandClass" value="detailProduct.DetailProductBackingObject" />
    	<property name="validator">
    		<bean class="detailProduct.DetailProductValidator" />
    	</property>
    	<property name="formView" value="detail" />
    	<property name="successView" value="redirect:/viewCart.htm" />
    	<property name="cartService" ref="cartServiceImpl"/>
    </bean>
    The backing object for the DetailProductFormController is:
    Code:
    public class DetailProductBackingObject {
    	private String quantityOverflowError;
    	private Product product;
    	private int quantity;
    	private ShoppingCart shoppingCart;
    	private long sizeId;
    	private long colorId;
    	public DetailProductBackingObject() {
    		this.product = new Product();
    		this.sizeId = -1;
    		this.colorId = -1;
    	}
    	//getters and setters
    }
    If you need some other info, I will provide. I also use Spring 2.5.5.

    Kind Regards,
    Despot

  • #2
    Solved

    The answer is here.

    Regards.

    Comment

    Working...
    X