I have a simple page the has 2 parts...
Part 1) Information at the top about a contact that the user is viewing.
Part 2) A form where a user can edit the information of a transaction
that relates to the contact.
When the user enters a invalid entry for a number field (in this
example xaction.listPrice), everything works perfectly in Part 2 of
the page (a fieldError is given and the form refilled). However, Part
1 is null since the parameterInterceptor doesn't call my action class.
How do I "refill" the Contact object information when this happens?
Or is my implementation of the Struts framework incorrect?
Many thanks for any assistance/guidance!
[***TestAction.java***]
public class TestAction extends ActionSupport {
private Contact contact;
private Xaction xaction;
// Get the contact and transaction to display on the page
public String execute() throws Exception{
// Get the xaction using hibernate
XactionHome xactionHome = new XactionHome();
// xactionId will be initially populated by url string
(Test_show.action?xaction.xactionId=1234)
this.xaction = xactionHome.findById(xaction.getXactionId());
this.contact = xaction.getContact();
return SUCCESS;
}
// Save the xaction information and redisplay
public String save() throws Exception {
// Get persisted xaction in database
XactionHome xactionHome = new XactionHome();
Xaction xa = xactionHome.findById(xaction.getXactionId());
// Now Update xaction Information
xa.setPropNum(xaction.getPropNum());
xa.setPropStreet(xaction.getPropStreet());
xa.setListPrice(xaction.getListPrice());
xactionHome.attachDirty(xa);
// Fill contact and transaction with the persisted version
this.xaction = xa;
this.contact = xa.getContact();
return SUCCESS;
}
// GETTER and SETTER Methods
public Xaction getXaction() {
return this.xaction;
}
public void setXaction(Xaction xaction) {
this.xaction = xaction;
}
public Contact getContact() {
return this.contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
[***test.jsp***]
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<!-- *** PART 1 *** -->
Contact Name: <s:property value="%{contact.firstName}" /> <s:property
value="%{contact.lastName}" />
<!-- *** Part 2 *** -->
<br>
<s:fielderror />
<br>
<s:form name="frmTest" action="Test_save">
<s:hidden name="xaction.xactionId" value="%{xaction.xactionId}" />
<s:textfield name="xaction.propNum" />
<s:textfield name="xaction.propStreet" />
<s:textfield key="xaction.listPrice" />
<s:submit value="Save" />
</s:form>
</body>
</html>
[***struts.xml***]
<action name="Test_show" class="com.rre.web.action.TestAction">
<result>/test.jsp</result>
<result name="input">/test.jsp</result>
<result name="error">/test.jsp</result>
</action>
<action name="Test_save" class="com.rre.web.action.TestAction" method="save">
<result>/test.jsp</result>
<result name="input">/test.jsp</result>
<result name="error">/test.jsp</result>
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]