I have following request scoped
Spring bean with @postconstruct
method init()
:
@Component
@Scope("request")
public class editUserBB {
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
private UserDto user;
@Autowired
private IUserService userService;
@PostConstruct
public void init() throws IOException {
String id_string = params.get("id");
Long id = Long.parseLong(id_string);
user = userService.getUserById(id);
}
public String save(){
// save to database
return "user?faces-redirect=true&id=" + (long)user.getId();
}
}
And userEdit.xhtml
with h:form
and commandButton
:
<h:commandButton value="Save" action="#{editUserBB.save()}" />
However, after the save button is clicked the init()
method is called once again annulling all the changes made to the UserDto
object before I can save it to the DB. So what am I doing wrong?
And I just tested, the init()
method is called even before save()
, which I also don't understand..