I am seeing very odd behavior where the value of an outjected boolean changes in the
middle of a template, but no assignment was done. I think it has to do with how it is
scoped.
Expected/ Intended Behavior:
The value, newPortfolioForm is toggled based on whether or not a form should be displayed
on a page. It is triggered when the user clicks the "add" button. The field is
EVENT scoped, such that if the user clicks "add" and then decides to do
something other than submit the form, the form will be hidden again (i.e. the action is
cancelled). However, on subsequent requests (i.e. any page refresh), it appears that the
outjected value for newPortfolioForm is null and then changes back to true after a
DataModel from the same SLSB is rendered.
Here is my (simplified) template:
| <html
xmlns="http://www.w3.org/1999/xhtml"
|
xmlns:s="http://jboss.com/products/seam/taglib"
|
xmlns:f="http://java.sun.com/jsf/core"
|
xmlns:h="http://java.sun.com/jsf/html">
|
| <body>
| <s:button value='Add' title='create a new profile'
| action='#{portfolioHandler.addPortfolio}'
| rendered='#{!showPortfolioForm}' />
|
| <s:div rendered='#{showPortfolioForm == null}'>showPortfolioForm is
null</s:div>
| <s:div rendered='#{showPortfolioForm}'>showPortfolioForm is
true</s:div>
| #{portfolios} <br />
| <s:div rendered='#{showPortfolioForm == true}'>showPortfolioForm is
TRUE!!!</s:div>
| <s:div rendered='#{showPortfolioForm == null}'>showPortfolioForm is
null</s:div>
| <s:div rendered='#{showPortfolioForm == false}'>showPortfolioForm is
false</s:div>
| </body>
| </html>
|
And my SLSB:
| @Stateless @Name("portfolioHandler")
| public class PortfolioHandlerImpl implements PortfolioHandler {
|
| @DataModelSelection("portfolios")
| @In(required=false) @Out(required=false)
| private Portfolio portfolio;
|
| @Out private boolean showPortfolioForm = false;
|
| @DataModel List<Portfolio> portfolios;
|
| public void addPortfolio() {
| showPortfolioForm = true; // display the form
| }
|
| public void updatePortfolio() {
| // save method...
| }
|
| // factory and other CRUD methods here...
| }
|
Output after initial page load (OK):
| showPortfolioForm is null
| org.jboss.seam.jsf.ListDataModel@c74f8c4
| showPortfolioForm is false
|
Output after button click (OK - consistent state):
| showPortfolioForm is true
| org.jboss.seam.jsf.ListDataModel@1f65c446
| showPortfolioForm is TRUE!!!
|
Output after page reload (BAD - it changed!!):
| showPortfolioForm is null
| org.jboss.seam.jsf.ListDataModel@35efd6ed
| showPortfolioForm is TRUE!!!
|
Now, I'm not surprised that showPortfolioForm was boxed to a Boolean and is null.
However -- why does the value change after #{portfolios} is referenced?!? Null and false
are close enough as far as boolean logic is concerned that I didn't notice this is
actually happening on the first page load too -- the value is null and then false.
I would submit that this is a bug -- the state within the template is not consistent, even
though none of my code has changed it. There is a similar effect if the scope is set to
PAGE. If the value was re-initialized to false it would be OK, but why is it picking up
the old value even though it is clearly out of scope?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4126347#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...