Re: How to make submit button only work if connection is available?

2020-01-19 Thread Mark Struberg
FTR, I now did the following trick. Of course this could be enhanced with 
multilinguality etc. But it works for me.

function submitIfOnline() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("HEAD", "index.http", false); // synchronous
try {
xmlHttp.send();
if (xmlHttp.status == 200) {
return true;
}
} catch (e) {
// nothiing to do;
}

alert("No connection available, please try again later!");
return false;
}



plus



The index.http heck is a convention I use in all projects.
Works so far.

LieGrue,
strub



> Am 19.01.2020 um 17:32 schrieb Thomas Andraschko 
> :
> 
> Hi,
> 
> I never needed something similar but i would do it the same.
> Maybe there are nicer ways, i would try to Google about it first.
> 
> 
> Mark Struberg  schrieb am So., 19. Jan. 2020,
> 16:34:
> 
>> Hi folks!
>> 
>> I'm right now designing a small only survey form with JSF-2.3. The problem
>> is that the survey should gather information from a cellar. And often there
>> is no WiFi nor mobile connection in those rooms. Thus it should not loose
>> data if the user presses the 'Save' button and the connection is not
>> available.
>> 
>> How to do this best?
>> 
>> I thought about an onclick which checks the connection via a ping to a
>> servlet (just returning true) and only then do a jsf.js submit(). If the
>> connection is not present it will present an alert() stating the user
>> should try later when he again has a connection.
>> 
>> Are there some better ways to do this?
>> 
>> txs and LieGrue,
>> strub
>> 
>> 



Re: How to make submit button only work if connection is available?

2020-01-19 Thread Thomas Andraschko
Hi,

I never needed something similar but i would do it the same.
Maybe there are nicer ways, i would try to Google about it first.


Mark Struberg  schrieb am So., 19. Jan. 2020,
16:34:

> Hi folks!
>
> I'm right now designing a small only survey form with JSF-2.3. The problem
> is that the survey should gather information from a cellar. And often there
> is no WiFi nor mobile connection in those rooms. Thus it should not loose
> data if the user presses the 'Save' button and the connection is not
> available.
>
> How to do this best?
>
> I thought about an onclick which checks the connection via a ping to a
> servlet (just returning true) and only then do a jsf.js submit(). If the
> connection is not present it will present an alert() stating the user
> should try later when he again has a connection.
>
> Are there some better ways to do this?
>
> txs and LieGrue,
> strub
>
>


How to make submit button only work if connection is available?

2020-01-19 Thread Mark Struberg
Hi folks!

I'm right now designing a small only survey form with JSF-2.3. The problem is 
that the survey should gather information from a cellar. And often there is no 
WiFi nor mobile connection in those rooms. Thus it should not loose data if the 
user presses the 'Save' button and the connection is not available.

How to do this best?

I thought about an onclick which checks the connection via a ping to a servlet 
(just returning true) and only then do a jsf.js submit(). If the connection is 
not present it will present an alert() stating the user should try later when 
he again has a connection.

Are there some better ways to do this?

txs and LieGrue,
strub