Alex Winner

Greenhorn
+ Follow
since Jun 01, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Winner

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:
code=java]
<s:iterator status="addressStat" value="account.addresses">
<s:textfield key="account.addresses[%{#addressStat.index}].address1" value="address1" required="true" size="32" maxlength="40"/>
</s:iterator>
[/code]

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

Thanks,

12 years ago
I have a class Bid:
public class Bid implements Serializable {
...
@ManyToOne
@JoinColumn(name="ACCOUNT_ID")
private Account account;

@Column(name="BID_PRICE")
private BigDecimal bidPrice;
...
}

in my action class ListingAction:
public class ListingAction extends ActionSupport {
...
private List<Bid> bids = null;
public String getBids() throws Exception {
...
}
...
}

I run getBids and in debug mode, I can see all bids information returned include the "Account" information and loginId. but the JSP show the nothing for loginId (first 4 cell), but bidPrice is showing up correctly.
<s:iterator value="bids">
<tr>
<td>
<s:property value="account"/>
</td>
<td>
<s:property value="account.loginId"/>
</td>
<td>
<s:property value="%{account.loginId}"/>
</td>
<td>
<s:property value="%{#account.loginId}"/>
</td>
<td>
<s:property value="bidPrice"/>
</td>
</tr>
</s:iterator>

Any idea?
12 years ago
Even I put a jsp as a forward result. I still get same exception. The image is displayed, the jsp is not display though.
12 years ago
I got "[Servlet Error]-[Response already committed.]: java.lang.IllegalStateException: Response already committed." when I out stream an image in struts2 class:

public String execute() throws Exception {
FileInputStream fis = new FileInputStream(path);
ServletOutputStream out = response.getOutputStream();
response.setContentType(pathContentType);
byte[] rd = new byte[fis.available()];
fis.read(rd);
out.write(rd);
fis.close();
out.close();
if (hasErrors()) return INPUT;
else return SUCCESS;
}
....

Actually, I only need to output the image in the action, I don't know how to let struts2 action not forward to a result. so I left the result empty:
<action name="image_*" method="{1}" class="com.solution.trade.listing.Image">
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">image/png,image/gif,image/jpeg,image/pjpeg,application/pdf</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="input">Image.jsp</result>
<result></result>
</action>

I debuged into the excute methods and found the error is not generated in excute methods, but after it returns. The image display fine, but just throw this annoying exception.

If anyone could provide tips on how to stream out a image within struts2 action, it is greately appreciated.


12 years ago
I have same problem, and found that because when I trying to access http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd I see that project got closed and the link is not valid anymore. I just removed the error dtd link (temporary fix, before apache get new link work)

<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

and get it works though there is still a warning.
12 years ago