Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

myfaces-impl-1.1.3 instantiates the request scope bean

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
myfaces-impl-1.1.3 instantiates the request scope bean every request (like it suppose to), however it doesn't retain any state information about the bean even though t:saveState tag is specified.
When I use myfaces-impl it works just fine.
Here is how i use the bean.

Bean.java
---------------
private String value = "";
private int number = 0;
public Bean() {

}


getValue() {
return value;
}


setValue (String v) {
value = v;
.
.
.
initBean (int n)
number= n;
}


page.jsp
------------
<f:view>
<%
int number = req.getParameter ("number");
if (number != INVALID_VALUE) {
//if value wasn't invalid then init the bean

FacesContext facesCtxt = FacesContext.getCurrentInstance();
VariableResolver variableResolver = facesCtxt.getApplication().getVariableResolver();
Bean myBean = (Bean) variableResolver.resolveVariable(
facesCtxt, "Bean" );

myBean.initBean (number);
}
%>


<t:saveState id="Bean" value="#{Bean}">
.
.
.
.

</f:view>

faces-config.xml
-------------------------
<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config>
.
.
.
<managed-bean>
<managed-bean-name>Bean</managed-bean-name>
<managed-bean-class>com.mypackage.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
.
.
.
</faces-config>

Thanks in advance,

Elliot
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you doing...



 
Elliot Khazon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Application has some jsf and non-jsf pages on it. when the transition is done from a non-jsf page to jsf page a number is passed to initialize all the DB persistent objects. Basically the non-jsf page has a table with things to edit and every entry in the table has an id (number). When user clicks on the item to edit the request is sent with this parameter via URL string. The receiving page (jsf page) extracts the parameter and initilizes the model with data from database. The way it used to work before is that all the initilized objects in the bean were retained using the state tag. However now it is not.
 
Elliot Khazon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To expand on the issue: the reason why is because the value is collected by a javascript function which then posts to the form (that is a form inside jsf file)
 
I was born with webbed fish toes. This tiny ad is my only friend:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic