You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Stewart Wachs <St...@trustvesta.com> on 2002/12/17 03:19:23 UTC
Trouble retrieving request parameters...
I found some interesting behavior while trying to write a unit test for a
Taglib...
To retrieve request parameters from inside the Taglib I use
pageContext.getRequest().getParameter("foobar").
While this works when making requests from a web browser, it fails to
retrieve the request parameter that I setup
In my test fixture.
...
request.setAttribute(PROGRAM, Constants.FOO_BAR);
tag.setPageContext(this.pageContext);
int result = tag.doStartTag();
assertEquals(tag.SKIP_BODY, result);
assertNull(pageContext.getSession().getAttribute(SHOPPING_CART));
assertNull(pageContext.getSession().getAttribute(PRODUCT_LIST));
...
However, if I change my Taglib code to retrieve request parameters by using
pageContext.getAttribute("foobar", PageContext.REQUEST_SCOPE) the unit test
passes, but the web browser request fails. Any ideas of what's going on
here?
Re: Trouble retrieving request parameters...
Posted by Erik Hatcher <li...@ehatchersolutions.com>.
You've mismatched "attribute" and "parameter". You probably intend to
call getAttribute in that first line of code rather than getParameter.
Erik
Stewart Wachs wrote:
> I found some interesting behavior while trying to write a unit test for a
> Taglib...
>
>
>
> To retrieve request parameters from inside the Taglib I use
> pageContext.getRequest().getParameter("foobar").
>
>
>
> While this works when making requests from a web browser, it fails to
> retrieve the request parameter that I setup
>
> In my test fixture.
>
>
>
> ...
>
> request.setAttribute(PROGRAM, Constants.FOO_BAR);
>
> tag.setPageContext(this.pageContext);
>
>
>
> int result = tag.doStartTag();
>
>
>
> assertEquals(tag.SKIP_BODY, result);
>
> assertNull(pageContext.getSession().getAttribute(SHOPPING_CART));
>
> assertNull(pageContext.getSession().getAttribute(PRODUCT_LIST));
>
> ...
>
>
>
> However, if I change my Taglib code to retrieve request parameters by using
> pageContext.getAttribute("foobar", PageContext.REQUEST_SCOPE) the unit test
> passes, but the web browser request fails. Any ideas of what's going on
> here?
>
>
>
>
>
>
>
>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>