我有一个包含某些字段的表单,例如public class NotifyFragment extends Fragment {
public NotifyFragment() {
// Required empty public constructor
}
private WebView webView;
private ProgressBar pb;
private ConnectivityManager cManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_notify, container, false);
webView = (WebView)view.findViewById(R.id.notifywebView);
pb = (ProgressBar)view.findViewById(R.id.notifyprogressBar);
cManager = (ConnectivityManager) getActivity().getSystemService(getActivity().CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cManager.getActiveNetworkInfo();
if (nInfo == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("No Internet Connection")
.setTitle("Oops!!")
.setIcon(R.drawable.caution);
builder.setCancelable(false);
builder.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
webView.loadUrl("https://docs.google.com/document/d/12u6jzoY8zB11valB2FwMyrf0HcWDnOvCkokzggNu1bA/edit?usp=sharing");
}
});
AlertDialog alert = builder.create();
alert.show();
}else {
webView.loadUrl("https://docs.google.com/document/d/12u6jzoY8zB11valB2FwMyrf0HcWDnOvCkokzggNu1bA/edit?usp=sharing");
}
//getActivity().getWindow().requestFeature(Window.FEATURE_PROGRESS);
getActivity().getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//Make the bar disappear after URL is loaded, and changes string to Loading...
pb.setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if (progress == 100) {
pb.setVisibility(View.GONE);
} else {
pb.setVisibility(View.VISIBLE);
}
}
});
webView.setWebViewClient(new mywebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://docs.google.com/document/d/12u6jzoY8zB11valB2FwMyrf0HcWDnOvCkokzggNu1bA/edit?usp=sharing");
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "download");
DownloadManager dm = (DownloadManager) getActivity().getSystemService(getActivity().DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getActivity(), "Downloading File", Toast.LENGTH_SHORT).show();
}
});
return view;
}
public class mywebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event){
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return onKeyDown(keyCode, event);
}
}
和<p:inputText>
,我试图阻止用户导航回上一页,而不清除表单字段或请求新页面,
提到this SO问题,我试图实现过滤器:
<p:selectOneMenu>
我甚至在字段中添加了@WebFilter("/*")
public class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
//if (!req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
res.setHeader("Expires", "0"); // Proxies.
//} removed the condition, to double check
chain.doFilter(request, response);
}
,并在页面中添加了元数据:
但是每次按下前进/后退按钮,他都会返回旧表格(带有旧值)。 它适用于Firefox,但不适用于谷歌浏览器。 我错过了什么吗?