File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Using html:hidden in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using html:hidden in struts" Watch "Using html:hidden in struts" New topic
Author

Using html:hidden in struts

Miguel Flecha
Ranch Hand

Joined: Jun 23, 2004
Posts: 85
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

Joined: Apr 01, 2003
Posts: 39
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

Joined: Jun 23, 2004
Posts: 85
>>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

Joined: Apr 01, 2003
Posts: 39
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

Joined: Jun 23, 2004
Posts: 85
ohhh...I think that's the problem. I'll have a try and tell you..
Thanks a lot
Miguel Flecha
Ranch Hand

Joined: Jun 23, 2004
Posts: 85
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

Joined: Apr 01, 2003
Posts: 39
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

Joined: Jun 23, 2004
Posts: 85
I'll have a try
Miguel Flecha
Ranch Hand

Joined: Jun 23, 2004
Posts: 85
I keep having the same problem
Miguel Flecha
Ranch Hand

Joined: Jun 23, 2004
Posts: 85
It works!! your solution was correct, I also had a problem with struts-config.xml
Thanks a lot
Andy Deighton
Ranch Hand

Joined: Apr 01, 2003
Posts: 39
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
 
Don't get me started about those stupid light bulbs.
 
subject: Using html:hidden in struts
 
Similar Threads
Unexpected behavior of Validator's Java Script
BAS 4.5.1
Error: According to TLD, tag html:hidden must be empty, but is not
bean:write Vs html:text
getting the value from <bean:write> tag