Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with the State

 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello all,

I am new to JSF .. I have a question...


I have an input text
<h:inputText .... >
and

<h:commandButton ...

I fill in the input text , then I click the command button in order to fill in a table with the result that I bring from the database ...

now the Backing bean I am using is set to "Request" scope ...

the first time I click the action, the table gets populated with the data..

but If I click any where else in the page to refresh it .. the values of the table are lost ...

I know that my question is a silly one ... but please help ...

I tried changing the scope to "Session" and it worked ... but isnt that consuming memory .. it will stay saved in memory ...

is there another way , please explain to me ... I feel that I am missing something ...

appreciate your help any1

thanks in advance ..
 
Rui Azevedo
Greenhorn
Posts: 20
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You lose your values because a request scoped bean is destroyed and reconstructed with each request. Maybe view scope solves your problems, it stays alive as long as you stay on a page.
 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks for the help ... I get it now..

and if I want the values to be preserved over 2 pages, should I use session or what ??
 
Rui Azevedo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For multiple pages, if you are using CDI, conversation scope is probably the most appropriate. Otherwise, you can go with session scope or define a custom scope of your own, but that is not so trivial.
 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks a lot !
 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I hope that I dont disturb you ...

I couldnt find on the net how to create a custom Managed bean scope

can you tell me how ?

Thanks.
 
Rui Azevedo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never done it myself. But maybe you can find some pointers here and here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic