You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dirk Markert <di...@dr-markert.de> on 2003/08/18 13:25:38 UTC
Re[2]: DynaActionForms and html:text tags
Hello Louise,
what's the action and its mapping you are using to forward to your
jsp containing
<html:form action="/private/issueLic">
<html:hidden property="issuer" value="manual" />
?
***************************************************************
LP> On Monday, August 18, 2003 at 11:59:46 AM, Dirk Markert wrote:
DM>> Hello Louise,
DM>> can you post your action mapping? Everything else looks fine.
LP> <action path="/private/issueLic"
LP> type="com.xlsior.actions.LicenseIssuer.java"
LP> name="licForm"
LP> validate="true"
LP> scope="session"
LP> input="/private/issue.jsp"
LP> >
LP> <forward name="success"
LP> path="/private/issued.jsp"
LP> redirect="false" />
LP> </action>
DM>> ***************************************************************
LP>>> I'm having problems getting a DynaActionForm to work with a jsp page,
LP>>> and wondered if anyone could help.
LP>>> I've defined all the properties in the DynaActionForm using
LP>>> <form-property /> tags. They all have type java.lang.String. The form
LP>>> is mapped to the Action in the usual way. Actual extracts from the
LP>>> files at the end of this message.
LP>>> I have a jsp page with an html:form tag that refers to the action. The
LP>>> trouble is, that none of the html:text tags work (they refer to
LP>>> properties as defined in the form). The symptom of the not working is
LP>>> org.apache.jasper.JasperException: No getter method for property
LP>>> <whatever> of bean org.apache.struts.taglib.html.BEAN
LP>>> An html:hidden tag and an html:password tag on the same form work
LP>>> fine. Could this be something to do with the fact that the hidden tag
LP>>> has a value set, and the password tag has redisplay="false", so that
LP>>> neither of them are looking in the form bean for values?
LP>>> Any help would be greatly appreciated. I am sure there is something
LP>>> basic I haven't done right, but I can't think what.
Regards,
Dirk
+------- Quality leads ---------------------------------------+
| Dirk Markert dirk.markert@dr-markert.de |
| Dr. Markert Softwaretechnik AG |
| Joseph-von-Fraunhofer-Str. 20 |
| 44227 Dortmund |
+---------------------------------->>>>>>> to success! <<<<<<-+
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: DynaActionForms and html:text tags
Posted by Hue Holleran <st...@openAction.net>.
Hi,
One option would be to use the "input" attribute of the action or
alternatively use DispatchAction to setup the data for your form. In all
cases the recommendation is that you should not go directly to your .jsp but
always go through an action. To enforce this most people put .jsp files
under WEB-INF (I'm not a fan of this approach) or use a security-contraint
in web.xml, e.g. the following prohibits access to "/content/*" and
"/tiles-layouts/*" in your webapp:
<!-- Prohibit direct access to JSP components -->
<security-constraint>
<web-resource-collection>
<web-resource-name>TilesComponents</web-resource-name>
<description>Application JSP Components</description>
<url-pattern>/content/*</url-pattern>
<url-pattern>/tiles-layouts/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>inaccessible</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
Using the "input" attribute is probably simpler - you need to determine a
condition in your action that means it is just the initialisation phase and
return the following:
return (new ActionForward(mapping.getInput()));
... that will fwd to your .jsp defined in the "input" attribute of your
action.
My preferred option is to use DispatchAction in combination with the "input"
attribute of the action that is beneficial when dealing with validation:
<action path="/myAction"
type="tld.domain.actions.MyAction"
name="myForm"
scope="request"
validate="true"
parameter="dispatch"
input="/entryForm.jsp">
<forward
name="Success"
path="/listForm.jsp"/>
</action>
This action can then be called with various "dispatch" parameters that
perform, e.g. initialisation, update etc. So, for instance the link to this
action to setup the form would be something like:
<html:link page="/do/myAction?dispatch=init">Data entry Form</html:link>
Or, alternatively use a global-forward that appends this parameter (in
struts-config):
...
<global-forwards>
...
<forward name="initDataEntry" path="/do/myAction?dispatch=init"/>
...
</global-forwards>
...
... and then the following format for the html:link in the .jsp that will
call the data-entry page:
<html:link forward="initDataEntry">Data entry Form</html:link>
Your form would then post to, say:
...
<html:form action="/do/myAction?dispatch=post">
...
So, you need an action with 2 methods: "init" and "post", say an action
class similar to the following:
package tld.domain.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
public final class MyAction extends DispatchAction {
// This will be called when parameter (i.e. "dispatch") = "init"
public ActionForward init(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Get a reference to the form bean
DynaActionForm dynaForm = (DynaActionForm) form;
// Set some default parameters for this scenario
dynaForm.set("amount", "10000");
// Fwd to the "input" mapping
return (new ActionForward(mapping.getInput()));
}
// This will be called when parameter (i.e. "dispatch") = "post"
public ActionForward post(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Get a reference to the form bean
DynaActionForm dynaForm = (DynaActionForm) form;
// Do some custom validation (or delegate to model)
if ... {
// Add some error messages here
...
// Error - return to input mapping
// so user can see errors and re-submit
return (new ActionForward(mapping.getInput()));
}
// We got here - so all must have OK - forward to "Success" page
return (mapping.findForward("Success"));
}
}
Hope that makes sense - it was copy-and-pasted from various places. Please
post back if this does not work!
Hue.
> -----Original Message-----
> From: Louise Pryor [mailto:lists@louisepryor.com]
> Sent: 18 August 2003 12:33
> To: Dirk Markert; Struts Users Mailing List; Hue Holleran
> Subject: Re: DynaActionForms and html:text tags
>
>
>
> On Monday, August 18, 2003 at 12:25:38 PM, Dirk Markert wrote:
>
> DM> Hello Louise,
> DM> what's the action and its mapping you are using to forward to your
> DM> jsp containing
>
> DM> <html:form action="/private/issueLic">
> DM> <html:hidden property="issuer" value="manual" />
>
> On Monday, August 18, 2003 at 12:22:31 PM, Hue Holleran wrote:
>
> HH> How are you accessing your page - if you're calling the jsp
> direct then then
> HH> struts will not have the opportunity to put the bean into
> scope for you?
>
> Thanks. It looks like we are converging on an answer. I am calling the
> jsp direct. From what you say it looks as if I should go via an
> action. What should that action do, or what should its mapping
> contain, to make things work?
>
> --
> Louise Pryor
> http://www.louisepryor.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: DynaActionForms and html:text tags
Posted by Louise Pryor <li...@louisepryor.com>.
On Monday, August 18, 2003 at 12:25:38 PM, Dirk Markert wrote:
DM> Hello Louise,
DM> what's the action and its mapping you are using to forward to your
DM> jsp containing
DM> <html:form action="/private/issueLic">
DM> <html:hidden property="issuer" value="manual" />
On Monday, August 18, 2003 at 12:22:31 PM, Hue Holleran wrote:
HH> How are you accessing your page - if you're calling the jsp direct then then
HH> struts will not have the opportunity to put the bean into scope for you?
Thanks. It looks like we are converging on an answer. I am calling the
jsp direct. From what you say it looks as if I should go via an
action. What should that action do, or what should its mapping
contain, to make things work?
--
Louise Pryor
http://www.louisepryor.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org