简体   繁体   中英

JSF + REST WebApp running on Apache Tomcat 7

I have a simple JSF WebApp with a backend service running on Tomcat 7.0.34

If you have a JSF ManagedBean responsible for processing the data model for rendering UI Components, how can the backend service to notify JSF of changes to the data model?

I am basically trying to figure out how to get hold of a reference to the ApplicationScoped JSF ManagedBeam from the backend service, but doesnt appear to be possible?

I would like to avoid using a polling meachanism where the ManagedBean polls the backend service to detect changes to the datamodel.. I have tried using CDI and Spring IoC where attempts have proved to be unsuccessful.

I can provide example code if required..

Thanks

I would advise against this. It would make more sense that your managedbean would add some sort of listener implementation to your service, and be notified that way. In a proper design, your backend service does not know your managed bean exists.

If you still want to do this, the trick is to have Spring manage your jsf managedbeans, instead of jsf itself. Then you can just inject the (application scoped!) managed bean into your service.

To use spring for your beans, you need to add the Spring resolver to your faces-config.

<el-resolver>
  org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>

Perhaps not what you are looking for, but you could have a method in your datamodel go and calculate a hashvalue over your data model - and store that value in a table that is not included in the hash calculation.

If the datamodel changes, then a stored procedure in the backend should update the hash.

While you would like to avoid using a polling mechanism, you now have a value that you would like to know has changed. Similar to @Joeri's answer, your model and controller should be decoupled - because you may have multiple controllers in the future.

If you had an application scoped bean that periodically checks the hash - would it not give you what you need?

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