JSF forced page refresh

B

BlackIce

I am trying to force a JSF page to refresh all of its components so
that they will all be empty instead of the original values. I am
trying to come from another page using a JSF hyperlink to reach the
destination page, and when the destination page is reached it should be
cleared of all previous values. Any help would be appreciated.
Thanks
 
D

Danno

BlackIce said:
I am trying to force a JSF page to refresh all of its components so
that they will all be empty instead of the original values. I am
trying to come from another page using a JSF hyperlink to reach the
destination page, and when the destination page is reached it should be
cleared of all previous values. Any help would be appreciated.
Thanks

Create a "creator bean" that clear itsself when you are done submitting

public class AccountBean {
private Account account;

public AccountBean() {
account = new Account();
}
//setters and getters

public void submit() {
//persist to DB
account = new Account();
}
}
 
B

BlackIce

Danno said:
Create a "creator bean" that clear itsself when you are done submitting

public class AccountBean {
private Account account;

public AccountBean() {
account = new Account();
}
//setters and getters

public void submit() {
//persist to DB
account = new Account();
}
}
But how is that going to force the page to create a new view with no
values?
 
D

Danno

BlackIce said:
But how is that going to force the page to create a new view with no
values?

It reflects the backend bean. So there will be no values after you
submit....
Take a look at the submit method I sent.
 
B

BlackIce

Danno said:
It reflects the backend bean. So there will be no values after you
submit....
Take a look at the submit method I sent.

A little more detail and explanation would be helpful. Thanks.
 
D

Danno

BlackIce said:
A little more detail and explanation would be helpful. Thanks.


public class AccountBean {
private Account account;

public AccountBean() {
account = new Account();
}
//setters and getters

public void submit() {
//persist to DB
account = new Account(); //create a new account after
submit
}
}

Well, taking a look at this bean notice the account = new Account()
line in the submit method. That means that after an account is created
via the submit method the bean will hold a blank new account which will
hold no information whatsoever. When you visit the page all the
information will be blank. Another strategy is to remove that
line...


public class AccountBean {
private Account account;

public AccountBean() {
account = new Account();
}
//setters and getters

public void submit() {
//persist to DB
//account = new Account(); //this line is removed
}
}

and just make sure that the AccountBean is of request scope and you
will get the same functionality.
 
B

BlackIce

Thank you for your help Danno but i was able to find an alternate way
of solving the problem. If I load the component tree into a list
becasue they are all attached to a form, I can go through the list of
child elements on the form (which are the elements i want to clear) and
clear each one. I did it this way and it works, but i had to use a
submit button for it to work though. This is fine and has no ill
affects from doing so as opposed to the traditional reset button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top