File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Problem mapping to form bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem mapping to form bean" Watch "Problem mapping to form bean" New topic

Problem mapping to form bean

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi All,

I'm trying to learn struts so I am experimenting on some simple web programs.
I have a table that displays list of users and in the last row of each column I made 3 submit buttons that allows the user to VIEW, EDIT and DELETE each row. Also I also name the three button with property ManageUser.

What I want is for me to have a reference on what button was click.
I did make a form bean with ManageUser as private variable so I can get the value if its VIEW, EDIT or DELETE.

But when I try to extract the value from the javabean in the action class to which this form bean is map, no value can be retrieved and Myform.getManageUser() returns null.

Here's my struts config xml.

I have done a form bean with html text field and password and it works fine. I'm just experimenting if I could do it with buttons.. Can I do it this way? Thanks.

Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The reason the property is null is that you have specified the wrong property name in your <html:submit> tag. It should be manageUser, not ManageUser.

Here are a couple of more suggestions:

Move the <html:form> stanza so that it is inside the <logic:iterate> stanza. That way you will have a separate form for each row. When one of the buttons in a row is pressed, only the data for that row will be submitted.

Remove the line

It isn't going to work. The result of this would be that the User id of the last user is always the one in the request, not the user of the row for which a submit button was pressed. Replace it with:

And add a userId property to your ActionForm bean.

You might also want to consider using a LookupDispatchAction.
[ July 18, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi Merill,

Thanks for your patient analysis of my rather "messy" code and giving valuable suggestion on how to execute what I really wanted even if I really didnt directly ask about it

I did tried what you suggest about LookupDispatchAction and found it really useful since I could separate the processing into different ActionForward sequence instead of using if-else statement..

My Struts Config..

Thanks again...
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Problem mapping to form bean
It's not a secret anymore!