JSF: PrimeFaces: JPA: Multiple Persistence Units

Problem

When using multiple JPA persistent units inside the file persistence.xml you can run into troubles when your entities have the same name. A exception message such a follow is an indicator of that there is a problem: “javax.annotation.processing.FilterException: Attempt to recreate a file …”

 

Solution

Set the following property from

<exclude-unlisted-classes>false</exclude-unlisted-classes>

to

<exclude-unlisted-classes>true</exclude-unlisted-classes>
Share

NetBeans 7.4: Exception: com.sun.faces.config.ConfigureListener

Problem

NetBeans 7.4 display an exception, send by Tomcat, that cannot be solved by just stopping Tomcat, cleaning and building the project. This issue happens because NetBeans keeps uploading a previous version of the project from its cache which is not being updated.

Solution For Windows Users

  1. On NetBeans
    1. Stop Tomcat
    2. Clean your project
    3. Exit NetBeans
  2. Go to “C:\Users\[USERNAME]\AppData\Local\NetBeans” (where USERNAME is your windows login username)
  3. Delete folder “Cache”
  4. Open NetBeans again. Build and test your project on the browser.
Share

Notes : C++ – Part 1

(C++ – Part 2) Next >

NOTIFICATION: These notes are published for educational purposes. Using these notes is under your own responsibility and risk. These notes are given ‘as is’. I do not take responsibilities for how you use them.

PDF Content:

  • Struct
  • L-values and r-values
  • Reference
  • Malloc
  • Assertions vs. exceptions vs. special return values
  • Exception handling
  • Run Time Type Information (RTTI)
  • Translation Unit
  • Triangle problem
  • Type Casting – explicit, implicit, and traditional casting
  • Specific casting operators
  • Static_cast, reinterpret_cast, and const_cast
  • type_id
  • One definition rule (ODR)
  • Struct vs classes – class definition
  • Friends
  • Forward declaration / using forward declaration
  • Classes define slope
  • Scope resolution operator
  • Static class members
  • Encapsulation and Abstraction
  • Copy constructors

Cplusplus_1

 

(C++ – Part 2) Next >

Share

Dealing with WebView for Android

In the application Cupid-4-Stupid that I and my partner David W. Corrigan developed, we notice that WebView stopped working properly.
When WebView stopped working as before, two important sections of our application were affected: Date Ideas and Panic Button.

I was getting exceptions such as NullPointerException produced by android.webkit.WebViewDatabase.getInstance() at WebViewDatabase.java.
After fixing this issue, we encounter other exceptions produced by CookieSyncManager.createInstance(Context) and more.

However, after doing some research, we managed to pin point the issue and fixed.

The following is a tutorial about how to create your own browser using WebView and make it work:
We assume that the browser is going to be an activity that will be called from another activity; however, that doesn’t mean that it cannot be your main activity if you wish.

  1. In your AndroidManifest.xml:
    1.  Add the following code before or after the ‘application’ tag:
      <uses-permission android:name='android.permission.INTERNET' />
    2. Next, add your browser activity tag.
      <activity android:name='com.hourglass.applications.BrowserActivity'
          android:theme='@android:style/Theme.NoTitleBar'>
      	<intent-filter>
      		<action android:name='com.hourglass.applications.Browser' />
      		<action	android:name='android.intent.action.VIEW' />
      		<category android:name='android.intent.category.DEFAULT' />
      		<data android:scheme='http' />
      	</intent-filter>
      </activity>
  2. Create the layout for your browser.
    Notice that we identify the root linear layout as ‘linearLayoutRootWebView’ and our WebView as ‘webview’. Both ids are important.

    <?xml version='1.0' encoding='utf-8'?>
    <LinearLayout android:id='@+id/linearLayoutRootWebView' xmlns:android='http://schemas.android.com/apk/res/android'
        androidShockrientation='vertical'
        android:layout_height='fill_parent'
        android:layout_width='fill_parent'
        android:background='@android:color/white'>
    
    	<WebView android:id='@+id/webview'
    	android:layout_width='fill_parent'
    	android:layout_height='fill_parent'></WebView>
    
    </LinearLayout>
  3. In your main activity under onCreate() method, add the following line at the end:
    This is part of the solution to solve the exception created by CookieSyncManager.createInstance(Context).

    CookieSyncManager.createInstance(this);
  4. Here is the most important part, your browser activity:
    First, you should notice that we added CookieSyncManager.getInstance().startSync(); inside onResume() method, and CookieSyncManager.getInstance().stopSync(); inside onStop() method. Again, this is to prevent the exception created by CookieSyncManager.createInstance(Context). Plus, using this method makes the loading of our pages more efficient.
    Second, the method setUpWebView() is the most important part. We tried using webview = (WebView) findViewById(R.id.webview); and other examples; however, replacing the webview provided by the resources by a webview generated by code seems to work and not generate any exceptions.

    package com.hourglassapplications;
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnCancelListener;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.Window;
    import android.webkit.CookieSyncManager;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Button;
    
    public class BrowserActivity extends ActivityWithMenu {
    	private static final String TAG = 'BrowserActivity';
    	final Activity activity = this;
    	private static ProgressDialog progressBar;
    	private ViewGroup viewGroupRootWebView;
    	private View viewToRemove;
    	private WebView webview;
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		this.getWindow().requestFeature(Window.FEATURE_PROGRESS); // Must be called before setContentView
     		setContentView(R.layout.browser);
    		setUpWebView();
    		loadUrl(getIntent().getData().toString());
      	}	
    
    	private void setUpWebView(){
                    // Identify the webview provided by the resources and replace it with a webview generated by code
    		viewGroupRootWebView = (ViewGroup) this.findViewById(R.id.linearLayoutRootWebView);
    		viewToRemove = viewGroupRootWebView.findViewById(R.id.webview);
    		int indexView = viewGroupRootWebView.indexOfChild(viewToRemove);
    
    		webview = new WebView(this);
    		setUpWebViewSettings();
    
    		viewGroupRootWebView.removeView(viewToRemove);
    		viewGroupRootWebView.addView(webview, indexView);
    	}
    
    	private void setUpWebViewSettings(){
    		webview.getSettings().setJavaScriptEnabled(true);
    		webview.getSettings().setBuiltInZoomControls(true);
    		webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
    		webview.setWebViewClient(newWebViewClient());
    		webview.setWebChromeClient(newWebChromeClient());
    	}
    
    	private WebChromeClient newWebChromeClient(){
    		return new WebChromeClient() {
    			public void onProgressChanged(WebView view, int progress){
    				activity.setTitle('Loading...');
    				activity.setProgress(progress * 100);
    				if(progress == 100){
    					activity.setTitle(R.string.app_name);
    				}
    			}
    		};
    	}
    
    	private WebViewClient newWebViewClient() {
    		return new WebViewClient(){
    			@Override
    			public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
    				Log.e(TAG, 'onReceivedError(..., ' + errorCode + ', ' + description + ', '+ failingUrl + ')');
    			}
    
    			@Override
    			public boolean shouldOverrideUrlLoading(WebView view, String url) {
    				view.loadUrl(url);
    				return true;
    			}
    
    			@Override
    			public void onPageFinished(WebView view, String url) {
    				if (progressBar != null && progressBar.isShowing()) {
    					progressBar.dismiss();
    				}
    			}
    
    		};
    	}
    
            private void loadUrl(String strUrl){
                setUpProgressBar();
                webview.loadUrl(strUrl);
           }
    	@Override
    	public boolean onKeyDown(int keyCode, KeyEvent event) {
                    // If there is a web page history, go to the previous page, else follow up the system behavior
    		if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
    			webview.goBack();
    			return true;
    		}
    		return super.onKeyDown(keyCode, event);
    	}
    
    	private void setUpProgressBar(){
    		progressBar = new ProgressDialog(this);
    		progressBar.setCancelable(true);
    		progressBar.setOnCancelListener(progressBarOnCancelListener);
    		progressBar.setMessage('Loading...');
    		progressBar.show();
    	}
    
    	private final OnCancelListener progressBarOnCancelListener = new OnCancelListener() {
    		@Override
    		public void onCancel(DialogInterface arg0) {
    			if (progressBar != null && progressBar.isShowing()) {
    				progressBar.dismiss();
    			}
    
    		}
    	};
    
    	@Override
    	public void onResume(){
    		super.onResume();
    		CookieSyncManager.getInstance().startSync();
    	}
    
    	@Override
    	public void onStop(){
    		super.onStop();
    		CookieSyncManager.getInstance().stopSync();
    	}
    
    	@Override
    	public void onDestroy(){
    		super.onDestroy();
    		webview.destroy();
    	}
    }

Let me know if you encounter a problem.

Share