简体   繁体   中英

JSF2 DataBinding Problem

I have a little issue regarding submit of forms in jsf 2:

In my webapp I got a function that updates entities in my db. This function gets the relative data out of a managed bean.

So, my issue is that changes in my view are not passed to the managedBean. To make that clear for you, here an example:

 public String updateProject() {
  projectService.updateProject(projectData.getProjectDTO());
  return ("overview.xhtml");
 } 

prjectData is my ManagedBean. This one doesn't work! No updates are been made.

 public String deleteProject() {
  projectData.getProjectDTO().setDeleted(true);
  projectService.updateProject(projectData.getProjectDTO());
  return ("overview.xhtml");
 }

Here, when I change a value by code it works! So I guess my values out of the view are not passed to my managedBean.

Where could be a mistake? Is there maybe an action I have to invoke to make the data pass my view to the managedBean?


Answer to Gabor's comment:

My page looks like:

<h:form>
 <h:commandLink action="#{controller.updateProject}" value="Edit" />
 <h:outputLabel for="title" value="Titel" /> 
 <h:inputText id="title" value="#{projectData.projectDTO.title}" />
</h:form>

If I change the title here and press update nothing happens ;-)


My Controller looks like:

@ManagedBean
@RequestScoped
public class Controller {

    @ManagedProperty(value = "#{projectData}")
    private ProjectData projectData;
...

For unknown reason my debug mode in eclipse doesn't work anymore it ignores my breakpoints all the time. I gonna fix that and then I'll check about the instances. Sry -.-

Either projectData or projectDTO is not the right instance as you expect it to be. It's a completely different instance. Aren't you eagerly recreating/overriding beans? Don't you have multiple beans in the scope? Shouldn't it for example be #{controller.projectData.projectDTO.title} ? Shouldn't the projectData instance in the controller be a managed property?

Is your projectData bean also RequestScoped? Try to change to ViewScoped. RequestScoped beans are recreated for each request, also ajax request. And what is scope of projectService?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM