Hi. I have a database which has a table "Person". A person has many attributes, including name, last name, age, sex, etc. I want to have a page where one would have a form with text boxes for each one of the attributes a person has (name, age...). If I only fill the text boxes "name" and "lastname" and send the form, I'd like to show every single single person which coincides with this search. I understand there's something called logic:iterate or something like that to do this. In any case, my real question is the following: I want to be able to click in any person I want which was part of the result of the search and then show on the linked page his or her attributes. Here's an example:
Let's say I have three persons:
Person 1: Name: A, LastName: B
Person 2: Name: B, LastName: C
Person 3: Name: A, LastName: D
In the search page, I do a search only by the name. I write A as a name. Obviously, 2 persons are matched. It should print:
I want to click in "A, D" so this can take me to other page where I can see all the attributes of the person. How can I do this? I'm using Struts 1.3. Thanks
Haven't done this before but:
First of all you would use JSTL SQL tag or Prepared Statement with JDBCso you can make use of your parameters the nice way.
In the table where you display your data in <td> you would also put it in anchors that all point to a view(if using JSTL SQL tag) or a servlet using a DAO to fetch the data according to parameters and dispatch to a view. I think it's better to pass the result set (holding the search data) as an attribute on the request object, because you might have a lot of entries and hence a lot of parameters to pass with GET (which won't do). In the subsequent page/servlet you manage the resultset data and display what/how you whish it.
And keep in mind this advice comes from a newb, so you better get more opinion or just read about more.
Create a link with the person's ID as the request parameter.
Joined: Nov 11, 2009
Mmm, I'm using Hibernate. I have been able to display the list of persons but I don't know how to make each person a link to other page with his or her attributes being displayed. I didn't understand much what you said but I think one way to do what I want is passing the parameters in the link and having the Action Controller take care of everything. I have something like this:
As you can see, I could click on any person and it would take me to attributes.jsp. I want to display all of the information for this person there, but I need to tell the action controller (which should be in the html:link tag) who is the person (I have an unique id for each person). How can I achieve this?
Create a link with the user's ID as the request parameter.
The <html:link> documentation might provide you with a clue as to how to do this, specifically the "paramId" and "paramName" or "paramName"/"paramProperty" attributes.
Joined: Nov 11, 2009
I think I did what you said:
But then in actionPerson.java if I do request.getParameter ("id) it returns null. I'm not passing the parameters as I should. I have the strange sensation that before the Action Controller takes this information, an ActionForm must be involved. I just don't know how
No, the "paramProperty" attribute should only be used if the "paramName" is used, like the documentation says.
It's a pretty simple matter to look at the generated HTML output and see that something has gone wrong, I'd assume. Most likely you'll want to include the ID of each person you're iterating over, not a random, hard-coded value anyway.
You *can* (and probably *should*) use an ActionForm--I don't even remember if you have to or not; it's been around five years since I've thought about Struts 1.