java - How to make database change cause updates to web clients' views -
environment: java ee 7, glassfish 4, mysql 5.7 on linux on arm7 server 512mb ram (app must memory frugal!) application: database-driven java web app served multiple android tablet clients running android 4.0 default browser.
the clients have 2 basic user types: producers , consumers. producers generate tasks displayed on consumers' browsers. when producer creates new task, should show on logged-in consumers' browsers if have tasklist (viewtasklist.jsp) displayed "pending" status. consumers select tasks tasklist , process them (dotask.jsp). when task selected consumer, should flagged "working" on other tasklist displays , not selectable. if consumer has task open clicks cancel button, task status should changed "pending" on tasklists. when task completed, flagged such, , should disappear consumers' browsers displaying tasklist view.
task entity class: (fragment) public class task { private int taskid; private string taskdescription; private boolean iscomplete; private string completerid; // userid of consumer marked complete (foreign key); private boolean islocked; private string lockid; // userid of consumer has task open; . . . }
i learning java ee programming, , not proficient in jpa , jsf yet, understand basic concepts. i've seen here , elsewhere, think comet and/or jquery/ajax may me solve this, don't know how use either of those. need basic guidance in how have database updates cause changes consumers' displays, without consumers requesting changes. part of solution adding 1 or more triggers mysql database?
you need implement polling model here. on gui implement script should make server call every n seconds bring latest data , show on gui, on server side need code can bring data , generate response.
to implement polling can set function invoked after x time.
window.setinterval(dbcallfunction, x);
once function invokes, make server call, return results, can set again function interval.
there lot of javascript libraries can solve you, recommend using jquery, here link
cheers !!
Comments
Post a Comment