• 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

mapping.getAttribute gives null pointer exception

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want initialize some form variables before I show the jsp page.
So In my action class, I create a new PersonForm and set the initial values for required fields.
then I want to set the form in the mapping, so that wehn the jsp will show with inital values.
but when I do a
mapping.setAttribute("personForm");
it doesnt set the value and gives me an exception. In the debug mode I can see that attribute is null.

how do I set the form in the required scope?
I have tried
if ("request".equals(mapping.getScope()))
request.setAttribute(mapping.getAttribute(), personForm);
else
session.setAttribute(mapping.getAttribute(), personForm);

This doesnt give me any errors.

but still the value is not set.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your Action mapping element for that action in the struts-config.xml specify that the action should have a form associated with it? If not, that is why you are getting null.
 
Rajani Deshpande
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah it does...
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you know the name of the form bean and it's scope, why not just keep it simple, and do the following?

request.setAttribute("personForm", personForm);

or

request.getSession().setAttribute("personForm", personForm);
reply
    Bookmark Topic Watch Topic
  • New Topic