You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burton Rhodes <bu...@gmail.com> on 2008/10/24 12:49:27 UTC
Correct implementation of parameterInterceptor??
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Correct implementation of parameterInterceptor??
Posted by Burton Rhodes <bu...@gmail.com>.
After a bit of reading I realized I needed to implement modeldriven
and parameter interceptor interfaces. Works like a charm now and much
cleaner.
Thanks for the reply!
On 10/27/08, Adam Hardy <ah...@cyberspaceroad.com> wrote:
> Burton Rhodes on 24/10/08 11:49, wrote:
>> 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?
>>
> [SNIP]
>> [***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>
>
> Well, I'm no expert on the conventional implementation of struts, so take
> this
> with a pinch of salt, but you need to pass through all the data you use on
> your
> page if you want it to re-appear in your form after validation failure. Try
> making contact.firstName and contact.lastName hidden fields.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Correct implementation of parameterInterceptor??
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Burton Rhodes on 24/10/08 11:49, wrote:
> 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?
>
[SNIP]
> [***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>
Well, I'm no expert on the conventional implementation of struts, so take this
with a pinch of salt, but you need to pass through all the data you use on your
page if you want it to re-appear in your form after validation failure. Try
making contact.firstName and contact.lastName hidden fields.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org