Hello group,

 

I realized that my code in red (see below-earlier post) was being executed
for each row as the table is built.

That is why my request did not contain a value. I modified the code as
follows:

 

<c:forEach var="person" begin="0" items="${requestScope.personList}">

    <tr>

        <form id="personForm" action="DeletePerson" method="post">

            <td>${person.id}&nbsp;&nbsp;</td>

            <td>${person.firstName}&nbsp;&nbsp;</td>

            <td>${person.lastName}&nbsp;&nbsp;</td>

            <th>

                <input type="submit" value="DeletePerson"

                   onclick="<c:set var="delete_person" scope="session"
value="${person}"/>">

            </th>

        </form>

    </tr>

</c:forEach>

 

Now I get a person (in the session scope) but it is always the last row in
the table (which makes sense since it is being evaluated once for each row).

I can't figure out how to pass the person object of the row that contains
the delete button I am clicking.

I am able to successfully remove the person and persist the changes but it's
the wrong person!

 

Can anyone help me solve this? I have searched everywhere for an answer to
no avail.

 

Thanks,

 

Cj .

 

  _____  

From: java-ee-j2ee-programming-with-passion@googlegroups.com
[mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of
Constantine J Coutsoukes
Sent: Monday, January 26, 2009 11:16 PM
To: 'Java EE (J2EE) Programming with Passion!'
Subject: [java ee programming] Re: Java Persistence API (JPA) Basics
homework

 

 

Hi.

 

I'm trying to create a delete button for each row then set a request
parameter with the current "person".

The bold lines are the lines of code I added to the example:

 

<c:forEach var="person" begin="0" items="${requestScope.personList}">

    <tr>

        <form id="personForm" action="DeletePerson" method="post">

            <td>${person.id}&nbsp;&nbsp;</td>

            <td>${person.firstName}&nbsp;&nbsp;</td>

            <td>${person.lastName}&nbsp;&nbsp;</td>

            <th><input type="submit" value="DeletePerson"
name="DeletePerson">

                    <c:set var="delete_person" scope="request"
value="${person}"/>

                </input>

            </th>

        </form>

    </tr> 

</c:forEach>

 

This reaches my DeletePersonServlet, which is almost identical to the
CreatePersonServlet, except that I try to extract the person from the
request like this:

 

Person person = (Person) request.getAttribute("delete_person");

 

And then further down instead of persisting the object I try to remove it:

 

em.remove(person);

 

This is where I get:

 

javax.servlet.ServletException: java.lang.IllegalArgumentException: Object:
null is not a known entity type.

 

In other words my parameter is not being set by my above code in red.

 

I am baffled by this homework. Any help would be greatly appreciated.

 

Thanks,

 

Cj .

 

-----Original Message-----
From: java-ee-j2ee-programming-with-passion@googlegroups.com
[mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of
zoso967
Sent: Monday, January 26, 2009 7:49 PM
To: Java EE (J2EE) Programming with Passion!
Cc: zoso...@nyc.rr.com
Subject: [java ee programming] Java Persistence API (JPA) Basics homework

 

 

 

Hello group.

 

I am having trouble with the Java Persistence API (JPA) Basics

homework.

 

The homework says:

 

For each entry (user) being displayed, provide a "Delete" option

 

The only example of this was in the CDLibrary project but that was a

full blown JSF application and the majority of the work was done by

the IDE.

 

The source for our homework project is not a JSF application and the

example uses JSF to do the deletes.

 

Are we supposed to make our homework a JSF application or are we just

supposed to use JSTL?

In either case, I am having trouble. I seem to have trouble with most

of the UI homeworks.

 

Can anyone point me in the right direction?

 

Thanks,

 

Cj .

 





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Java 
EE (J2EE) Programming with Passion!" group.
To post to this group, send email to 
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to 
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to