This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 have issue to display JPA proxy objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 have issue to display JPA proxy objects" Watch "Struts2 have issue to display JPA proxy objects" New topic

Struts2 have issue to display JPA proxy objects

Alex Winner

Joined: Jun 01, 2011
Posts: 5
I bet this is a Struts2 bug and I did found a work around to share. Just wondering if anyone has same issue before or may be have a better solution:
I am on JPA 2.0 and Struts2 version 2.3.3 running on RAD test environment.

I have an JPA object Account and Address:

So when I read an account information back in my action class, I see the address information is returned (but in proxy mode). So I can see the address1 information. But if I have JSP like (1st option):

It display nothing. But if I have JSP like (2nd option):

It display correct address retreived from database. however, if I used this second option, after I submit the form for update, I CANNOT get updated value in my action class. But the first one does get correct updated address1 after submit for update.

To find out why, I manually create a account and its address object and send to display using the first option, it works. The only different is manually created address object is a local object while address object retrieved from database is a proxy object. So, looks like there is something to do with the proxy object.

I twisted a while and found an work around to have both displaying and updating work is that I have to use both as following:
<s:iterator status="addressStat" value="account.addresses">
<s:textfield key="account.addresses[%{#addressStat.index}].address1" value="address1" required="true" size="32" maxlength="40"/>

While this sounds funny, it works. If you have any better solution please share.


I agree. Here's the link:
subject: Struts2 have issue to display JPA proxy objects
Similar Threads
@Generatedvalue and MySQL
Merging problem - id is generated instead of cusotm id.
Struts2 - <s:iterator> in two-Dimensional Array.
Struts2 nested iterators with listboxes
EJB3/JPA @OneToOne