This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, In my JSP view component I am setting a Bean's property like this: <jsp:useBean id="xxxDetails" class="fun.moreFun.xxxDetails" scope="request"/> <jsp:setProperty name="xxxDetails" property="*"> First of all I am not able to find the xxxDetails instance in my controller. If I set the scope as session I get the xxxDetails instance. Secondly, even if I get the instance (scope="session") the properties are null! Meaning, something is going worng at property="*". I have set the field names and the property names as same. Thirdly, if I set the properties using field names like: <jsp:useBean id="xxxDetails" class="fun.moreFun.xxxDetails" scope="request"/> <jsp:setProperty name="xxxDetails" property="yyy" value="yyy"> It gives introspection error as the yyy propery is of int type. As far as I know while introspection values are converted atomaticaly to the required datatypes using (Class).valueOf(), then it should work. Please tell me where I am making the mistakes.
I must admit I'm a bit confused. You're talking about your controller. Do you use a servlet as controller or are you handling everything with JSP's. Both methods are possible, but I would prefer to work with JSP's for the view, java beans for the model and servlets as controller. ABout the session and request scope :if you're using a java bean with request scope, then this bean will be deleted as soon as the user is rquesting another page. With a session, you will have a bean as long as the client session exists, not matter how many pages the user will request. Normally, I never work with setProperty and getProperty (I prefer working with servlets and DAO's who make the java beans and hand them over to the JSP's). But if I'm not mistaken, when you write : <jsp:useBean id="xxxDetails" class="fun.moreFun.xxxDetails" scope="request"/><jsp:setProperty name="xxxDetails" property="*"> You are making a new Java bean. SO the content of all the variables depend on how you made the constructor. In that case, it's normal that your variables don't have any value, if you didn't define a default value in your constructor.
Actually, I have a similar problem. Here's my setting: - A servlet controller as entry point, instanciates a bean and puts it in the session. Then a dispatcher forwards to a JSP page - The JSP page sets the property value in the bean and goes back to the controller. - The controller, which should display the bean property value, actually outputs null. I would be ready to think the bean property wasn't set correctly, but if I forward to a second JSP page to display the bean value, then it display the value correctly. I'm really puzzled, so if anyone has an input on that, I would appreciate greatly. Thanks, Tom