• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring MVC question

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem here in getting MVC work between two pages. I have a login form, that is authenticating the customer and then gets the customer information based on the login details. This populates object called "Customer" and hands off to another controller, AccountController, who just displays account.jsp. I am trying to access this Customer object on the account.jsp, but for some reason, I see the object is getting null on account.jsp, however i see Customer object is set with all values before the request is handed off to AccountController.

Here is the code snippet from my xxx-servlet.xml
<bean id="accountController" class="com.controller.AccountController" />
<bean id="logonForm" class="com.controller.LogonFormController">
<property name="commandName"><value>login</value></property>
<property name="commandClass"><value>com.business.Login</value></property>
<property name="validator"><ref bean="logonValidator"/></property>
<property name="formView"><value>login</value></property>
<property name="successView"><value>account.htm</value></property>
<property name="customer" ref="customer"></property>
<property name="serviceManager" ref="serviceManager"></property>
</bean>

---------------
Code from LogonFormController:

public ModelAndView onSubmit(Object command) throws ServletException {
Login login = (Login) command;
String custid = login.getCustomerid();
logger.info("custid in onSubmit is:" + custid);
customer = serviceManager.retrieveCustomer(custid);
if(customer!=null) logger.error("customer name is: " + customer.getFirst_name());

return new ModelAndView(new RedirectView(getSuccessView()));
}

====================

I see the name here spitting out without any problem. But, on account.jsp,
<c ut value="${customer.customer_id }" />

This doesnt show any value when I execute the app.

Any help on where I could be wrong is greatly appreciated.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This populates object called "Customer" and hands off to another controller,


But is the customer stored anywhere, like as a request attribute, or a session attribute ? If not, it will get lost in the ActionController.
 
bala kiran
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was under the assumption that it will be passed over to the next controller as we declared it as reference bean for the first controller. Do I need to explicitly set in the session?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala...

I'm not sure why you are forwarding to another controller to display your page. Your page is rendered and submitted. The controller runs, then just displays the next page (With all your loaded data, no need to forward to another controller). If there needs to be a submit done from that (2nd) page, it can hit another controller on the submit.

This two controller thing seems to come from a Struts background. I have had to help a couple other people with this as well.

Try something like this...

xxx-servlet.xml



Your LogonFormController.....



Then in your account.jsp you should be able to reference your values by the ${customer.yourAttribute}.

Give that a try...let us know what you find.

Nick
 
a wee bit from the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic