uoxton wrote:
> hello,
>
> with hopes that somebody will respond this time...
>
> I have a javabean that controls the language of a site, with a property
> 'language' that gets set by an url parameter when I instantiate the bean:
>
> <jsp:useBean id="text" class="TextBean" scope="session">
> <jsp:setProperty name="text" property="language" value="<%
> request.getParameter("language") %>" />
> </jsp:useBean>
>
> the property takes one of two values - "eng" for english and "por" for
> portuguese.
>
> this works fine if the user doesn't intend on switching back once he
> sets a language, but after the bean is instantiated I can't set the
> property to another value. I've tried using
>
> <jsp:setProperty> outside the <jsp:useBean> open and close tags, and
> I've tried having a separate jsp page be called, which would set the
> property and then forward the request back, following the shopping cart
> example of the jsp book (addtocart.jsp, chapter 8), but none of these
> seem to work. the value remains the same.
>
> it seems to me it'd be pretty straightforward to change properties of
> bean with a session scope... what am I doing wrong?
Chapter 8 and addtochart.jsp looks like a reference to the JSP book
I wrote (JavaServer Pages, O'Reilly) so let's see if I can help
you.
First, you can avoid the expression in setProperty like this:
<jsp:setProperty name="text" property="language" />
Since the property and the parameter has the same name, this
works the same way as in your example (assuming the parameter
has a value other than an empty string).
Second, if you in fact are basing this on the examples in my
book, I suggest that you look at Chapter 11 instead. There I
describe a bean and a set of custom actions that handles i18n
with the features you seem to want.
Finally, since you create your bean in the session scope,
a setProperty within the body of a useBean action element
is only executed the first time, when the bean is created.
But if you place it outside of the useBean body, it's executed
every time the page is accessed. You said you tried this, so
maybe there's some other problem.
For instance, the page you see could be a version cached by
the browser. Try to change the caching setting for your browser
to see if it works better. Also see Chapter 12 for ideas about
how to control caching from the JSP page.
You may also want to scrutinize your bean code to make sure
that it really handles a new language value as it should.
Adding a few println() calls here and there to see which method
is actually called may help.
Hope this helps,
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com