Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using html:hidden in struts

 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
I'm trying to send a hidden value with a form. I do this:

<html:hidden name="bug" property="id"/>

where bug is a bean that I'm using without problems in the JSP.

But when I execute the Action I get the following exception:

java.lang.NullPointerException
at ibt.struts.action.ModificarBugAction.execute(ModificarBugAction.java:59)

and line 59 of ModificarBugAction is:

Integer bugId=new Integer(modificarBugForm.getBugId());


What am I doing wrong??
Regards
Miguel
 
Andy Deighton
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there definitely a value in that property ("id")?
If id is an attribute of bug, is bug an attribute of your ActionForm? What does getBugId() answer? Does it do something like getBug().getId()?
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>Is there definitely a value in that property ("id")?

yes, id has a value

>>If id is an attribute of bug,

yes, it is an attribute of bug

>>is bug an attribute of your ActionForm?

no, it is a bean defined in a JSP that I receive from the request

>>What does getBugId() answer? Does it do something like getBug().getId()?

getBugId()??? I don't know...

Thanks
 
Andy Deighton
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said:
"Integer bugId=new Integer(modificarBugForm.getBugId());"

So, I was wondering what getBugId() answered?
If bug is a bean on your JSP, then how do you expect to get it from your ActionForm? You have to set it somewhere on your modificarBugForm in order for that getBugId() method to work.
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh...I think that's the problem. I'll have a try and tell you..
Thanks a lot
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting the same error, but the problem is there.
In my modificarBugForm I have a property called id (it was called bugId, but I changed it) and I don't kno how to give to that property the value I have in the jsp bean's property called id
 
Andy Deighton
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could add a value= attribute to your html:hidden tag...

<html:hidden property="id" value="<%=bug.getId()%>"/>

This assumes that "bug" is a bean defined in your JSP..

<bean efine id="bug" name="bug"/>
This will create a "bug" bean (that name is got from id=) that is a copy of the bean called "bug" (name=) which is found in the default scope.

Does that help? I think there's a nicer way, but I'm thinking about it..!
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have a try
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep having the same problem
 
Miguel Flecha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works!! your solution was correct, I also had a problem with struts-config.xml
Thanks a lot
 
Andy Deighton
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool! I think there's a more elegant solution. Look at this site:

http://struts.apache.org/userGuide/index.html

And check out the Developer Guide links ("HTML tags, Bean tags" etc.)

Andy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic