You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mike Young <mi...@e-mage.com.au> on 2004/07/12 08:50:59 UTC
Html Buttons & DynaValidator Forms
Hi,
I am trying to implement antonio lagnada's html buttons 'pattern'
(http://j2ee.lagnada.com/struts/html-buttons.htm) with DynaValidatorForms
however I am have problems in the Action form when I try to interrogate
the getters to find which button has been pressed.
I am fairly new to struts so I may have interpreted how to implement this
'pattern' with DynaValidatorForms incorrectly, and would really appreciate
some direction.
here is where my problem lies ... I have my action 'AddTrainer' as follows
...
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
ActionForward forward = mapping.getInputForward(); AddTrainerForm
addTrainerForm = (AddTrainerForm) form;
String foo = (String)addTrainerForm.get("buttons.submit.name");
---snip----
At this point it stack dumps because property buttons.submit.name doesn't
exist. I have toyed with the idea of creating it as a form-property but I
don't think that this is right.
I understand that when submit is pressed
---snip----
<html:submit property="buttons.submit.name">Submit</html:submit>
---snip----
It will carry out a getButtons().getSubmit().setName("Submit")
But how do I interrogate that setter when I am using dynamic forms?
Here is the other bits of pertiment code ...
strus-config.xml
---snip----
<form-beans>
<form-bean name="addTrainerForm"
type="com.struts.addtrainer.AddTrainerForm">
<form-property name="tnrId" type="java.lang.String"/> <form-property
name="tnrFirstname" type="java.lang.String"/> <form-property
name="tnrSurname" type="java.lang.String"/>
</form-bean>
</form-beans>
---snip----
<action path="/addTrainer"
input="/jsp/addTrainer.jsp"
name="addTrainerForm"
scope="request"
validate="true"
type="com.struts.addtrainer.AddTrainer"> <forward
name="addtrainer.cancel" path="/app/homePageSetup"/> <forward
name="addtrainer.success" path="/app/trainerDetailSetup"/>
</action>
---snip----
Created HtmlButton class as per example in url metioned above
Created AddTrainerButtons as per example in url mentioned above
{ExampleButtons.java}
Modified my AddTrainerForm as follows ...
public class AddTrainerForm extends DynaValidatorForm
private AddTrainerButtons m_buttons = null;
---snip----
public void reset(ActionMapping mapping, HttpServletRequest request)
{
ActionServlet servlet = super.getServlet(); m_buttons = new
AddTrainerButtons();
}
---snip----
public AddTrainerButtons getButtons() {
return m_buttons;
}
}
public void setButtons(AddTrainerButtons buttons) {
m_buttons = buttons;
}
---snip----
thanks to anybody and everybody who may be able to help my understanding
of this!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org