Skip to main content

JSF: variable results with flash, page templates, post-redirect-get

6 replies [Last post]
healeyb
Offline
Joined: 2010-01-26
Points: 0

I don't know if this is just my GlassFish installation gone wrong but I'm getting
some very inconsistent results in my application. I use page templates,
implicit page navigation with faces-redirect=true for post-redirect-get, and ajax.

Because of the problem of communicating across pages when using
post-redirect-get I use, or try to use, flash "scope". Because of the problems
I've been experiencing I've ditched request scope in favour of view scoped
managed beans, as a sort of desperate measure, which has seemed improve
things, most of the time, I think.

The sort of thing I'm trying to do is just pass information from one page to
another, an analogy would be to select a department from page 1, click on the
manage employees button, go to page 2 which shows a list of employees. The
problem I'm experiencing is that sometimes page 2 successfully knows which
department it's supposed to be listing employees for, sometimes not.

I've written a test application consisting of 4 files, index.xhtml, next.xhtml,
template.xhtml & BackingBean.java. the index.xhtml has an input field, you
type some text in which is stored directly in the flash, it also has a
preRenderView event, the listener which puts two other items of data in the flash,
one using .put(), one using .putNow(). You click on a button which navigates to
next.xhtml which displays the values from the flash. A button on next.xhtml
takes you back to index.xhtml.

Here are some results I've got from running this test application. server restart
indicates that I've restarted the glassfish server, re-run that I've closed the
browser window and re-run the project from NetBeans.

<br />
server   re-run    I type            displayed on next.xhtml<br />
restart                in              name1   name2   name3</p>
<p>yes        yes      aaaa           aaaa      fred        blank<br />
                        bbbb           blank      blank     blank<br />
                        cccc           cccc       fred       blank<br />
                        dddd           dddd       fred       bob<br />
                        eeee           eeee       fred       bob<br />
                        ffff               ffff           fred       bob<br />
             yes      aaaa          aaaa        blank    blank<br />
                        bbbb          bbbb        fred       bob<br />
                        cccc          cccc        fred       bob<br />
                        dddd          dddd        fred       bob<br />
             yes     aaaa           aaaa        fred       blank<br />
                       bbbb           bbbb        fred       bob<br />
                       cccc           cccc        fred       bob<br />
                       dddd           dddd        fred       bob<br />
yes        yes    aaaa           aaaa         blank    blank<br />

These are the sort of results I'm getting. Even after a server restart you can't
predict what will happen, it's all over the place.

index.xhtml:

<br />
<?xml version='1.0' encoding='UTF-8' ?></p>
<p>

template.xhtml:

<br />
<?xml version='1.0' encoding='UTF-8' ?></p>
<p>                Template Content</p>
<p>

next.xhtml:

<br />
<?xml version='1.0' encoding='UTF-8' ?></p>
<p>

BackingBean.java:

<br />
import javax.inject.Named;<br />
import javax.enterprise.context.RequestScoped;<br />
import javax.faces.bean.ViewScoped;<br />
import javax.faces.context.FacesContext;<br />
import javax.faces.context.Flash;<br />
import javax.faces.event.ComponentSystemEvent;</p>
<p>/**<br />
 *<br />
 * @author Brendan<br />
 */</p>
<p>@Named(value="backingBean")<br />
@ViewScoped<br />
public class BackingBean {</p>
<p>    /** Creates a new instance of BackingBean */<br />
    public BackingBean() {<br />
    }</p>
<p>    public Flash getFlash() {</p>
<p>        return FacesContext.getCurrentInstance().getExternalContext().getFlash();<br />
    }</p>
<p>    public void setupPage(ComponentSystemEvent cse) throws Exception {<br />
        System.out.println("setupPage");<br />
        getFlash().put("name2", "fred");<br />
        getFlash().putNow("name3", "bob");<br />
    }<br />
}<br />

I'm using Mojarra 2.0.3 from the Glassfish 3.01 release, running on a Windows 7
server. I'd love to know if anyone else can reproduce these inconsistent results
in their environment, and hopefully that I'm not making some sort of elementary
mistake.

What I'd originally set out to do here was reproduce the
dreaded JSF1095 flash error, alas with no success but I
wouldn't be surprised if that problem and this problem
were related in some way.

Regards,
Brendan.

Message was edited by: healeyb

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ed Burns

>>>>> On Mon, 09 Aug 2010 12:21:27 PDT, webtier@javadesktop.org said:

BH> The sort of thing I'm trying to do is just pass information from one
BH> page to another, an analogy would be to select a department from page 1,
BH> click on the manage employees button, go to page 2 which shows a list of
BH> employees. The problem I'm experiencing is that sometimes page 2
BH> successfully knows which department it's supposed to be listing
BH> employees for, sometimes not.

Right, this "master/detail" use-case is exactly the rationale for the
flash scope.

BH> I've written a test application consisting of 4 files, index.xhtml,
BH> next.xhtml, template.xhtml & BackingBean.java. the index.xhtml has an
BH> input field, you type some text in which is stored directly in the
BH> flash, it also has a preRenderView event, the listener which puts two

I'm going to spend the next 30 minutes debugging this and I'll get back
to you.

Ed

--
| edburns... | office: +1 407 458 0017
| homepage: | http://ridingthecrest.com/
| 03 work days until JSF 2.1 Milestone 2

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Ed Burns

>>>>> On Fri, 13 Aug 2010 12:22:07 -0700, Ed Burns said:

>>>>> On Mon, 09 Aug 2010 12:21:27 PDT, webtier@javadesktop.org said:
BH> The sort of thing I'm trying to do is just pass information from one
BH> page to another, an analogy would be to select a department from page 1,
BH> click on the manage employees button, go to page 2 which shows a list of
BH> employees. The problem I'm experiencing is that sometimes page 2
BH> successfully knows which department it's supposed to be listing
BH> employees for, sometimes not.

EB> Right, this "master/detail" use-case is exactly the rationale for the
EB> flash scope.

BH> I've written a test application consisting of 4 files, index.xhtml,
BH> next.xhtml, template.xhtml & BackingBean.java. the index.xhtml has an
BH> input field, you type some text in which is stored directly in the
BH> flash, it also has a preRenderView event, the listener which puts two

EB> I'm going to spend the next 30 minutes debugging this and I'll get back
EB> to you.

Ok, I tried this with the latest Mojarra HEAD running in GlassFish 3.0
FCS.

I am presently uploading the GlassFish 3.0 zip with the Mojarra HEAD
installed into it, as well as a zip of your sample as a maven project,
to this area on java.net

https://javaserverfaces.dev.java.net/servlets/ProjectDocumentList?folder...

When the upload completes, God willing, you'll have something you can
download and run.

I was unable to reproduce the problem with this stack. Can you please
try it and get back to me?

Thanks,

Ed

--
| edward.burns... | office: +1 407 458 0017
| homepage: | http://ridingthecrest.com/
| 03 work days until JSF 2.1 Milestone 2

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

healeyb
Offline
Joined: 2010-01-26
Points: 0

Hi Ed, thanks for taking a look at this. I've got a bit of a problem in that I'm going
to be boarding a flight in about 5 hours time for a weeks vacation. I was just
checking my e-mails prior to leaving for the airport. I downloaded the zip file
but couldn't inspect it with windows zip, do I need the maven assembly plugin?

Sorry but I may not be able to look at this until I get back, any other time I'd have
been right on it.

Regards,
Brendan.

healeyb
Offline
Joined: 2010-01-26
Points: 0

Hi, I'm afraid that I've not used Maven and will need to do some background on
this before I can use the software supplied. I thought there was supposed to
be a pom.xml file, but couldn't locate one. This is something I need to address.

Anyway, I'm about 90% sure I know the general nature of the problem. I was
running glassfish on an AMD 64 bit dual-core chipset (Windows 7) and started to
get a bit paranoid that it was running a bit hot (which it was - 70C), so tried
running on an Intel quad core box (64 bit) instead. Though I thought it unlikely I
wanted to rule out any bizarre hardware problems or anything like that.

I reloaded onto the new box glassfish 3.0.1 (with Mojarra 2.0.2), JDK 6 u21,
NetBeans, everything. The problem was no better even after a clean and build.
This pretty much rules out any configuration or hardware anomalies.
I also tried building with Mojarra 2.1NB with no improvement.

Then I thought to see if I could disable all but one cpu and try again. Miraculously
I then get stable results, so it looks like a lack of thread safety which is less
likely to manifest itself on a single cpu box.

Perhaps this would be worth investigating. I could imagine that even if running on
a multi-cpu sparc unix box that differences in the underlying implementations
(i.e. not intel, not windows), despite the jvm, could change the conditions under
which this problem occurs, or not? Anyway, it's definitely a big problem on a
multi-cpu windows box.

Regards,
Brendan.

Message was edited by: healeyb

Message was edited by: healeyb

healeyb
Offline
Joined: 2010-01-26
Points: 0

I'll just clarify that using view scoped beans does not alter the frequency of
occurrence of this problem, it just seems to help me to get parameters
passed between pages. One other point that could be salient is that my PC
has a dual-core AMD Athlon chipset. Also I'm running the
app server in 64 bit mode, with the -server flag instead
of -client.

Message was edited by: healeyb

Lincoln Baxter, III

Brendan,

I'm not sure if this is correct, or a bug based on the way the JSF API docs
are written, it's probably worth raising to the Expert Group, which I'll do
now that I see someone else has had a similar issue.

There is an alternative in the mean-time, however, if you are not opposed to
using Alpha/Beta software. Seam 3 Faces module provides a flash-scoped
implementation that functions the way it sounds like you expect:
http://docs.jboss.org/seam/3/faces/reference/snapshot/en-US/html_single/...

--Lincoln

On Mon, Aug 9, 2010 at 4:31 PM, wrote:

> I'll just clarify that using view scoped beans does not alter the frequency
> of
> occurrence of this problem, it just seems to help me to get parameters
> passed between pages. One other point that could be salient is that my PC
> has a dual-core AMD Athlon chipset.
> [Message sent by forum member 'healeyb']
>
> http://forums.java.net/jive/thread.jspa?messageID=479727
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

--
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"
[att1.html]