I am creating app in JSF. I want that when I click on submit button, then it should call the same page, but show edit button instead of submit button. How can I do that?
Asked
Active
Viewed 638 times
1 Answers
1
Let the action method set a boolean property in a @ViewScoped
bean to toggle the buttons and return null
or void
to return to the same view. Let the view conditionally render the submit and edit buttons based on the boolean.
Basically,
private boolean editmode;
public void submit() {
editmode = true;
}
public boolean isEditmode() {
return editmode;
}
With
<h:commandButton value="Submit" action="#{bean.submit}" rendered="#{not bean.editmode}" />
<h:commandButton value="Edit" action="#{bean.edit}" rendered="#{bean.editmode}" />
Unrelated to the concrete question, this is however a quite strange requirement. Shouldn't the "Submit button" in your question actually be an "Edit button" and the "Edit button" in your question actually be a "Save button"? That'd make more sense.

BalusC
- 1,082,665
- 372
- 3,610
- 3,555
-
In my app, I've implemented the same as like your answer with session scope. can be session scope right instead of ViewScoped ? – vels4j Jan 07 '13 at 11:47
-
1@vels: The session scope is not the right scope to hold view scoped data. If you put view scoped data in session scope and the enduser opens the same view multiple times in the same session (in multiple browser windws/tabs) then it would interfere with each other! See also http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope – BalusC Jan 07 '13 at 11:49