tag:blogger.com,1999:blog-53168237641327574582024-02-20T13:51:18.729-08:00Fortega IT SolutionsThis is the blog of blaBart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5316823764132757458.post-70450080502784709552014-03-20T05:43:00.003-07:002014-03-20T05:52:14.751-07:00ADF - Throwing a validation exception from a view row objectIn ADF, you can easily add method validators on Entity level. However, sometimes this is not enough. If your validation logic is complex (for instance: if you need all other rows to validate against, for some kind of special uniqueness constraint), this is not enough.<br />
<br />
You can throw a general exception from the setter of your attribute in the view object, but that is not enough, because this will look different (no 'red' field, and a different style of exception on the screen).<br />
<br />
To solve this, you will need to throw an '<span style="font-family: Courier New, Courier, monospace;">AttrValException</span>', as shown below:<br />
<br />
<span style="font-family: inherit;">General method in the view row base class.</span><br />
<br/>
<div style="border:1px solid gray; margin-top:5px; padding:5px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Final static String RESOURCE_BUNDLE_NAME = "my_resource_bundle";</span><br />
<span style="font-family: Courier New, Courier, monospace;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">protected void throwValidationException(String message, String attrName) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> PropertiesBundleDef resBundle = new PropertiesBundleDef(this.getViewDef());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> resBundle.setPropertiesFile(RESOURCEBUNDLE_NAME);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> throw new AttrValException(MetaObjectBase.TYP_VIEW_OBJECT, resBundle, message, getViewObject().getFullName(), attrName);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
</div>
<br />
Setter of view row object:<br />
<br/>
<div style="border:1px solid gray; margin-top:5px; padding:5px;">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public void setMyCode(String value){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> if(/* your validation logic */){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">throwValidationException("myCodeValidationErrorMsgKey", "MyCode");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> setAttributeInternal(MY_CODE, value);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="font-size: x-small;">}</span> </span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
</div>Bart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.com0tag:blogger.com,1999:blog-5316823764132757458.post-35847582988421795222013-01-03T06:00:00.000-08:002013-01-03T06:01:06.952-08:00ikwileenspel.beDe beste gezelschapsspellen voor de beste prijs: <a href="http://www.ikwileenspel.be/">www.ikwileenspel.be</a><br />
<br />
Vanaf nu verkopen we dus bord- en kaartspellen. Neem maar eens een kijkje op onze website :-)Bart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.com0tag:blogger.com,1999:blog-5316823764132757458.post-54292501174488113132011-06-27T06:33:00.000-07:002011-06-27T06:33:31.167-07:00Eclipse startup - eclipse.core.internal.dtree.ObjectNotFoundExceptionAfter killing the eclipse process and restarting my pc, Eclipse was not able to startup anymore.<br />
<br />
In my log file (workspace_dir\.metadata\.log), I saw following exception:<br />
<br />
<div style="background-color: #555555;"><div><code><span style="font-size: small;"> </span></code>org.eclipse.core.internal.dtree.ObjectNotFoundException: Tree element 'mypckg/myClass.class' not found.<br />
at org.eclipse.core.internal.dtree.AbstractDataTree.handleNotFound(AbstractDataTree.java:257)<br />
at org.eclipse.core.internal.dtree.DeltaDataTree.getData(DeltaDataTree.java:585)<br />
at org.eclipse.core.internal.dtree.DataDeltaNode.asBackwardDelta(DataDeltaNode.java:50)<br />
at org.eclipse.core.internal.dtree.DataDeltaNode.asBackwardDelta(DataDeltaNode.java:47)<br />
at org.eclipse.core.internal.dtree.DataDeltaNode.asBackwardDelta(DataDeltaNode.java:47)<br />
at org.eclipse.core.internal.dtree.DataDeltaNode.asBackwardDelta(DataDeltaNode.java:47)<br />
at org.eclipse.core.internal.dtree.DataDeltaNode.asBackwardDelta(DataDeltaNode.java:47)<br />
</div></div><div><span class="Apple-style-span"><br />
</span></div><div>After some research I tried to delete the workspace_dir\.metadata\.plugins\org.eclipse.core.resources\.snap file, which solved the problem. Don't ask me why. You can tell me why if you know :-)</div>Bart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.com2tag:blogger.com,1999:blog-5316823764132757458.post-56334174795325903052011-05-09T12:32:00.000-07:002011-05-09T12:40:40.817-07:00PrimeFaces inplace wrapped around editor<span class="Apple-style-span">In Primefaces, there is a <p:inplace> component, which is a nice component to use for inline editing,</span><br />
<span class="Apple-style-span">and a <p:editor>, which is an input component with rich text formatting capabilities.</span><br />
<span class="Apple-style-span"><br />
</span><br />
<span class="Apple-style-span">But the two didn't really match. If one uses a <p:inplace> wrapped around a <p:editor>, the editor does not work as it is supposed to. The problem is that the editor is not designed to work in a container which is initially hidden. And that's just the behavior you depend on when you want to use an inplace component.</span><br />
<span class="Apple-style-span"><br />
</span><br />
<span class="Apple-style-span">However, with this little trick, you can use an inplace component wrapped around an editor. The editor has a 'lazy' property. If you set this to true, you can initialize the editor at the moment it is shown:</span><br />
<br />
<div style="background-color: #555555;"><div><code><span style="font-size: small;"> <h:form id="formWithInplace"></span></code><br />
<code><span style="font-size: small;"> <p:inplace id="inplaceid"></span></code><br />
<span style="font-size: small;"><code> <p:editor value="#{editorBean.value}" saveListener="#{editorBean.save}"<br />
lazy="true" widgetVar="editorWidget"/><br />
</p:inplace></code></span><br />
<span style="font-size: small;"><code> </h:form></code></span></div></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><span class="Apple-style-span">So now we have an inplace wrapped around a lazy editor. The only thing we have to do now, is initialize the editor when the inplace is clicked (and the editor is shown). As the inplace does not have an 'onclick' parameter, we will use jQuery and the id of the inplace component:</span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span"><br />
</span></span><br />
<div style="background-color: #555555;"><div><code><span style="font-size: small;"> <script type="text/javascript"><br />
jQuery(PrimeFaces.escapeClientId('formWithInplace:inplaceid')).click(</span></code></div><div><code><span style="font-size: small;"> function(){<br />
editorWidget.init();<br />
}</span></code></div><div><code><span style="font-size: small;"> );</span></code></div><div><code><span style="font-size: small;"> </script></span></code></div></div><span class="Apple-style-span"><span class="Apple-style-span"></span></span></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: Georgia,serif; font-size: 16px;"><br />
</span></span></div>Bart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.com0tag:blogger.com,1999:blog-5316823764132757458.post-2904871759074390082011-04-15T11:24:00.001-07:002011-05-09T03:34:26.137-07:00Seam 3 / Weld alternative for @Startup annotation<span class="Apple-style-span">In Seam 2, if you wanted a seam component to be initialized when the application was started up, you could use the @Startup annotation.</span><br />
<div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span">In Seam 3 (or better: weld), this annotation is not supported. If you want a bean to be started up when the application starts up, you could write a method which observes an event:</span></div><br />
<div style="background-color: #555555;"><div><code><span class="Apple-style-span" style="font-size: x-small;"> </span>public class BeanToBeInitializedAtStartup {</code></div><div><code><span class="Apple-style-span"></span><span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;"> </span></span></code></div><div><code><span class="Apple-style-span" style="white-space: pre;"> p</span>ublic void onStartup(@Observes @Initialized WebApplication webApplication){</code></div><div><code><span class="Apple-style-span"></span><span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;"> </span>//do nothing, bean will be initialized when application is started</span></code></div><div><code><span class="Apple-style-span"></span><span class="Apple-style-span"> }</span></code></div><div><code><br />
</code></div><div><code><span class="Apple-style-span"> }</span></code></div></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><span class="Apple-style-span">However, this means you will need such a method for every bean, which is a lot more of overhead than the simple @Startup annotation.</span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span"><br />
</span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span">A solution for this is to use a simple helper class, which initializes all beans which implement some interface you define yourself:</span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span"><br />
</span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span">First, you will need an interface. This interface does not require any methods.</span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span"><code></code></span></span></div><br />
<div style="background-color: #555555;"><div><code><span class="Apple-style-span"><span class="Apple-style-span" style="font-size: x-small;"> </span>public interface Startup { </span><span class="Apple-style-span">}</span></code></div><div></div><code><span class="Apple-style-span"></span></code></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><span class="Apple-style-span"></span></span><br />
<div style="font-size: medium;"><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span">Next, all of the beans you want to be initialized should implement this interface</span></span></span></span></div><div><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span"><code></code></span></span></span></span></div></div><div><br />
<div style="background-color: #555555;"><div><code><span class="Apple-style-span" style="font-size: x-small;"> </span> public class BeanToBeInitializedAtStartup implements Startup { }</code></div><div><code><span class="Apple-style-span"></span></code></div></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span">That looks a lot better! Now of course you need some helper class, which initializes all beans which implement the Startup annotation:</span></div></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><code></code></span></div><div style="background-color: #555555;"><div><code><span class="Apple-style-span" style="font-size: x-small;"> </span>public class BeanStartupHelper {</code></div><div><code><br />
</code><br />
<code> public void onStartup(@Observes @Initialized WebApplication webApplication, </code><br />
<code> BeanManager beanManager) {</code></div><div><code> </code></div><div><code> </code><br />
<code> for(Bean bean : beanManager.getBeans(Startup.class)){</code></div><div><code><span class="Apple-tab-span" style="white-space: pre;"> </span> CreationalContext context = beanManager.createCreationalContext(bean);</code></div><div><code><span class="Apple-tab-span" style="white-space: pre;"> </span> beanManager.getReference(bean, Startup.class, context);</code></div><div><code><span class="Apple-style-span"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span></code><br />
<code><span class="Apple-style-span"> </span><span class="Apple-style-span" style="font-family: 'times new roman'; white-space: pre;"> </span></code></div><div><code> }</code></div><div><code> }</code></div><div><code><span class="Apple-style-span" style="font-size: x-small;"></span></code></div></div><div><span class="Apple-style-span"><br />
</span></div><div><div><div><span class="Apple-style-span">The BeanStartupHelper is actually also a bean, and as you can see, this bean contains a method which observes the initialization of the webapplication. A reference to the BeanManager object is injected as a parameter of this method. We use the BeanManager object to create the beans we need, which are all beans which implement the Startup annotation.</span></div></div></div><div><span class="Apple-style-span"><br />
</span></div><div><b><span class="Apple-style-span">Result</span></b></div><div><span class="Apple-style-span">There is a clear separation between the beans themselves and the implementation of the startup method. The only thing needed for your beans is the fact that they need to implement a Startup interface. You only need one method which observes the initialization of your application, in which all 'startup' beans will be initialized!</span></div><div><span class="Apple-style-span"><br />
</span></div><div><span class="Apple-style-span"><span class="Apple-style-span" style="font-family: Georgia,serif; font-size: 16px;"><br />
</span></span></div><div></div>Bart Lamberigtshttp://www.blogger.com/profile/05705541002076545077noreply@blogger.com5