You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/01/07 17:44:35 UTC

How do I get a form's name within ?

I'm looking to do some enhacements to Erik Hatcher's LabelTag.  Currently,
it gets a form's name with the following code:

ActionMapping mapping =
    (ActionMapping) pageContext.getAttribute(
        Globals.MAPPING_KEY,
        PageContext.REQUEST_SCOPE);
String formName = mapping.getAttribute();

However, this only works if there is a mapping the request scope.  I've run
into a couple NPE on pages that are forwarded to using an ActionForward -
and the form still renders (without the LabelTag).  So I'm wondering how I
can get the form's name if I'm within an <html:form>?

After looking at FormTag.java, is this the best way?

String formName = (String) pageContext.getAttribute(Constants.BEAN_KEY,
PageContext.REQUEST_SCOPE);

Feel free to send me a link to CVS to view the source for a class there.

Thanks,

Matt


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do I get a form's name within ?

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Matt - that seems like a reasonable change to me, although maybe its 
even more robust to find the parent form tag and call the getBeanName() 
method there?

I haven't had a chance to try the change to see how it affects my 
project yet though.

I'm confused on why your ActionForward action doesn't have a form bean 
associated with it though.  How does the <html:form> tag know what form 
to use then?

	Erik

On Tuesday, January 7, 2003, at 11:44  AM, Raible, Matt wrote:
> I'm looking to do some enhacements to Erik Hatcher's LabelTag.  
> Currently,
> it gets a form's name with the following code:
>
> ActionMapping mapping =
>     (ActionMapping) pageContext.getAttribute(
>         Globals.MAPPING_KEY,
>         PageContext.REQUEST_SCOPE);
> String formName = mapping.getAttribute();
>
> However, this only works if there is a mapping the request scope.  
> I've run
> into a couple NPE on pages that are forwarded to using an 
> ActionForward -
> and the form still renders (without the LabelTag).  So I'm wondering 
> how I
> can get the form's name if I'm within an <html:form>?
>
> After looking at FormTag.java, is this the best way?
>
> String formName = (String) pageContext.getAttribute(Constants.BEAN_KEY,
> PageContext.REQUEST_SCOPE);
>
> Feel free to send me a link to CVS to view the source for a class 
> there.
>
> Thanks,
>
> Matt
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>