Results 1 to 6 of 6
- 11-26-2012, 11:46 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 21
- Rep Power
- 0
could not able to set property from springapp-servlet.xml, throws Failed to convert
i am trying to set the value from the springapp-servlet.xml and it fails to set the property by giving error message
Failed to convert property value of type [java.lang.String] to required type [ProductManager] for property 'productManager'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [ProductManager] for property 'productManager': no matching editors or conversion strategy found
my code
---------
springapp-servlet.xml
---------------------------------
HelloControllerJava Code:view plaincopy to clipboardprint? <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="productManager" class="SimpleProductManager"> <property name="products"> <list> <ref bean="product1"/> <ref bean="product2"/> </list> </property> </bean> <bean id="product1" class="Product"> <property name="description" value="Chair"/> </bean> <bean id="product2" class="Product"> <property name="description" value="Desk"/> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages"/> </bean> <bean name="/hello.htm" class="HelloController"> <property name="productManager" value="productManager"/> </bean> <!-- we can prefix="/" http://localhost:8080/HelloSpring/hello.htm specify the path in modelview from the controller OR Decouple the view from the controller prefix="/WEB-INF/jsp/" --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> </beans>
-----------------
Java Code:view plaincopy to clipboardprint? /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author gopc */ import java.util.Date; import java.util.Map; import java.util.HashMap; import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.IOException; public class HelloController implements Controller { private ProductManager productManager; protected final Log logger = LogFactory.getLog(getClass()); //Writing some business logic in the controller public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String now = (new java.util.Date()).toString(); logger.info("returning hello view with " + now); Map<String, Object> myModel = new HashMap<String, Object>(); myModel.put("now", now); myModel.put("products", this.productManager.getProducts()); return new ModelAndView("hello", "model", myModel); } public void setProductManager(ProductManager productManager) { this.productManager = productManager; } }
SimpleProductManager
------------------------------
Java Code:view plaincopy to clipboardprint? /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author gopc */ import java.util.List; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; public class SimpleProductManager implements ProductManager{ private List<Product> products; protected final Log logger = LogFactory.getLog(getClass()); public List<Product> getProducts() { logger.info("inside getProducts "); return products; } public void increasePrice (int per) { if (products != null) { for (Product prod : products) { double newPrice = prod.getPrice() * (100 + per) /100; prod.setPrice(newPrice); } } } public void setProducts(List <Product> products ) { logger.info("inside setProducts "); this.products = products; } }
- 11-26-2012, 12:27 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: could not able to set property from springapp-servlet.xml, throws Failed to conve
It's 'ref="productManager" not 'value="productManager".
'ref' is used for beans.Please do not ask for code as refusal often offends.
- 11-27-2012, 03:25 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 21
- Rep Power
- 0
Re: could not able to set property from springapp-servlet.xml, throws Failed to conve
yes it has worked, thanks very much..
- 11-27-2012, 03:36 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 21
- Rep Power
- 0
Re: could not able to set property from springapp-servlet.xml, throws Failed to conve
another thing, i the jsp i had included the jstl, and messages.properties contains the below one.i call from the jsp using the messages.properties.
but the when i try to run, the tag is not showing.. it is diplaying like this.
???heading???
???greeting??? Tue Nov 27 10:33:12 SGT 2012
messages.properties (\HelloSpring\build\web\WEB-INF\classes)
----------------------------------------------------------------
JSP code (hello.jsp)Java Code:title=SpringApp heading=Hello :: SpringApp greeting=Greetings, it is now
---------
[/CODE]Java Code:<%@ include file="/WEB-INF/jsp/include.jsp" %> <html> <head><title><fmt:message key="title"/> </title></head> <body> <h1>Hello - Spring Application</h1> <!-- <p>Greetings.it is now ${now} </p> --> <!-- <p>Greetings.it is now <c:out value ="${now}" /> </p> --> <h1><fmt:message key="heading"/></h1> <p><fmt:message key="greeting"/> <c:out value="${model.now}"/></p> <h3>Products</h3> <c:forEach items="${model.products}" var="prod"> <c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br> </c:forEach> </body> </html>Last edited by cgk_js; 11-27-2012 at 04:05 AM.
- 11-27-2012, 09:38 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: could not able to set property from springapp-servlet.xml, throws Failed to conve
First, have you defined your javax.servlet.jsp.jstl.fmt.localizationContext in the web.xml?
That tells the i18n tags what bundle to use.
Second, the bundle name should end '_<2char code>', so english would be 'messages_en.properties'.
You probably also want to define a fallback, javax.servlet.jsp.jstl.fmt.fallbackLocale.Please do not ask for code as refusal often offends.
- 12-03-2012, 04:30 AM #6
Member
- Join Date
- Oct 2012
- Posts
- 21
- Rep Power
- 0
Re: could not able to set property from springapp-servlet.xml, throws Failed to conve
i got the problem being resolved..
following are the step's i did it..
1) in the springapp-context.xml (dispacher ), i add the below
2) second, i placed the messages.properties file inside the /WEB-INF/classes. make sure that after clean and deploy the file stills exits.XML Code:<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages"/> </bean>
Similar Threads
-
throws
By java4amanda in forum New To JavaReplies: 2Last Post: 03-29-2012, 09:08 AM -
throws exception
By simorgh in forum New To JavaReplies: 1Last Post: 07-30-2010, 12:24 AM -
Be Elite Join Property Elite , Property Realtor Needed , Career With Us -
By mindyyong in forum Jobs OfferedReplies: 0Last Post: 06-25-2009, 05:28 AM -
throws
By jdgallag in forum New To JavaReplies: 14Last Post: 02-11-2009, 01:07 AM -
throws Exception
By javaplus in forum New To JavaReplies: 1Last Post: 11-06-2007, 07:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks