Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!

Maurice Le Chat

Greenhorn
+ Follow
since Jan 20, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Maurice Le Chat

Hi

You're right. "DD" was typo I didn't see at the moment. DATE_FORMAT_STR = "yyyy-MM-dd HH:mm:ss" results in the expected result.

Thanks. More eyes see more, confirmed once again. Nevertheless the outcome of "jan" always due to this typo is very strange and confusing!
9 years ago
Can someone please tell me why the following simple program does not output the expected results:


Output is:
date 1:Tue Jan 17 14:53:15 CET 2012
date 2:Wed Jan 23 11:53:15 CET 2013

From String DATE_STR_1 I would expect December and from DATE_STR_2 I would rather expect August.
However we have Jan for both cases!

Hwo knows about this strange bug?
Thanks in advance.
9 years ago
I have a JEE application running well on Glassfish using JSF2 based on Mojarra. This application shall run on WebSphere8, hence must be prorted. WAS does support MyFaces, but support of mojarra is very poor. So, Mojarra has been kicked out and the application references the ibm myFaces jar. On running the application and calling managedBean methods, MethodNotFounExceptions are thrown. e.g.
javax.el.MethodNotFoundException: /resources/utils/formEditingMenu.xhtml at line 39 and column 39 action="#{cc.attrs.handler.generateDocument('HTML')}": Method not found: ch.commcity.monterosa.web.ProjectHandler@43bda4c.generateDocument()
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:91)
Of course the method exist, as it works perfectly with Glassfish and Mojarra!
Strange is the number between handler and Method ch.commcity.monterosa.web.ProjectHandler@43bda4c.generateDocument() of course the existing method is rather ch.commcity.monterosa.web.ProjectHandler.generateDocument()!
From where this @number is comming?
What configuration may be missing to make it work?
Are the differencies between the 2 JSF2 Implementations really so big?
What could be the reason of the MethodNotFoundExceptio?
Any hint is very apreciated.
10 years ago
JSF
I try to use logger levels below INFO, like FINE, FINER, or FINEST, but only INFO and above is shown in the server.log. Working with Eclipse 3.6 Helios.

I tried all around to set lover levels, without any success.

I have:
parent logger name =
parent log level : INFO
ok, this is the root. for this I made an entry in the logging.properties like ".level=FINE" but nothing changed.

Further I have:

actual logger name: ch.commcity.monterosa.ejb.impl
actual logger level: FINE
is loggable? true

I changed in the constructor of the class the parent log level to: FINEST
and I changed the logging.properties file in the actual jre/lib
Without any success!

Who knows where to change to have loggings below the Level.INFO?

Thanks for any hint!
11 years ago
Of course I tried! I havent seen any surprise! The main intend of this thread is to avoid future surprises by getting deeper knowledge from the community. Please explain what do you mean by surprise!
11 years ago
@Matthiew
You are right of course! I didn't yet think about optimizing. I was surprised by the fact to get a handle (field object) to the private id field I want, simply going through the superclass and being able to use this reference to access the id field in a real object, being an extention of this superclass!

@Jesper @Henry
The above is the point! Please read carefully my description of the situation. The application use JPA. A couple of years ago I would have used Hibernate. Anway it's the same. I know reflection and it's use by tools. The point is:
Java SE API says clearly for getDeclaredFields() " ... This includes public, protected, default (package) access, and private fields, but excludes inherited fields." In fact calling getDeclaredField("id") on th derived class Employee throws NoSuchFieldException! So far no surprise. I wonder the fact it's so easy to circumvent this limitation by getting a field object of the superclass and later manipulating with this same object a previously created object of a derived class!
Though I use the reflection in JUnit only, I would be assured to know if this behaviour is by specification, or by accident! If the latter is true, I would like to know, how others do it, or how the tools (Hibernate, etc.) do it.

Thanks

Maurice
11 years ago
Situation:
The private field id (primary key of DB) ist set by the JEE container and JPA. For this reason no public setter for id shall exist.
To set the id for JUnit tests, reflection is used. To make it a little bit more complicated a class employee inherits from the super class Person. The id field exist in the Person class only.
The following code snippet from JUnit test class works:

Employee empl = new Employee();
try {
// access private field id and set a unique id otherwise set by DB through container
Person pers = new Person(); //ugly workaround, but it works, create dummy super class!
// inherited declared fields are not accessible but:
Field id = pers.getClass().getDeclaredField("id"); // get id ref from super class Person
id.setAccessible(true);
id.setLong(empl, Long.valueOf(i + 1)); // use id ref on employee!
id.setAccessible(false);
} catch (Exception e) {
//handle it
}

Questions:
1.) Though it works, it looks so weird to me, I suspect rather a bug than a feature!
2.) How to do it the clean way?
3.) Who can tell me more about this.

Any background information is welcome.

Cheers Maurice
11 years ago
yes!

But it doesn't help. My jsf page shows an error and doesn't compile, while it worked before.

With regard to url! All Oracle site pages, concerning Java, are full of broken links now, which really doesn't make things easier, if you search a solution to make your pages compile!
11 years ago
JSF
How to reference taglibs now?

declaring:
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

results in:

Can not find the tag library descriptor for "http://java.sun.com/jsf/core"

Where the tag libraries can be found now? We need a place independent of a manufacturer which cut sites off at will!

Thaks for any hint.

Maurice
11 years ago
JSF
Oh, thanks for answering.
From the article about anonymous classes, I deduce, final is just to make clear that the reference can not be modified and there are no further constraints below the hood.

In fact those constraints I'm interesting in, not the superficial behaviour and rules.
Of course, I can open the Java Spec. and read through until I got the answer. The reason of my question, was just to save me from that! If somebody just knows the answer, it is so much easier than reading Java Spec.

13 years ago
I'll not speak about final class variables. I'll not speak about sense of declaring method arguments final. I try to find out side effects of declaring method variables as final. It is about scope, lifetime of those referencies and by this possible memory leaks caused.

We all know:

A variable or reference to a variable declared final can be assigned a value only once. That's fine.
We know too, a variable, or it's reference declared within a method lives for the scope of the method. (Is put on the stack)
Declaring a variable, or better said a reference to a heap Object within a method, which must be passed to a new thread, mostly declared as an anonymous inner class, must be declared final.
So what is the exact mechanism? A copy of the final reference is put on the parameter list of the annonymous class constructor and by this the new thread can access the object on the heap.
What happens to the reference declared final on the method stack?
Either normal reference or reference declared final, on exit of the method scope is gone. But now are they handled identical? Nulled out? Or how does the garbage collector know the heap object can be destroyed if the previously started thread loose scope too?
If the handling of both kind of referencies is identical, why must we declare a reference final if it ist passed to a new thread?

Who can give me more details?
13 years ago
Hi,

Your Help shall be html. That is fine. Me too, I prefere html files for help, mostly!

Look at the following snippet:

This allows you to diplay html - css formatted within a modal help JDialog.

Have fun.

[Edit: put code between [code] and [/code] ubb code blocks]
OK, cool down, JUnit helps a lot!

Your test fails, because your method under test does return nothing (void) hence do not expect to get something back!

But your method sets the Text of a field! Hence go to read back the field with the text set!

You can not access this field? Victory! JUnit helped you to find out this very early and did a very good job. You don't need access to this field but only for test? Think again what you need!

Beside have a look at http://easytesting.org/swing/wiki/pmwiki.php

For automatic testing of UI this extends JUnit in a very powerful manner!

Have fun!
13 years ago
For this kind of purpose JDK includes the ResourceBundle!
look at the following code snippet, which reads a <className>.properties file within the relative dir called resources benath the package dir:
// just be clean on any OS
NL = System.getProperty("file.separator");
ClassLoader cl = Config.class.getClassLoader();
File baseDir = new File(cl.getResource(".").getFile());

// now we now the dir the class Object is actually running in

RUN_DIR = baseDir.getAbsolutePath() + NL;

// could work with Bundles too, but lets use properties

props = new Properties();
ResourceBundle rb = getResourceBundle(Config.class, Locale.getDefault());

// allow comments on the same line within the xx.properties and strip them here

for (String key : rb.keySet()) {
String s = rb.getString(key);
if (s.contains("#")) {
s = s.substring(0, s.indexOf('#')).trim();
}
fill the Properties
props.put(key, s);
}

-----------

ResourceBundle getResourceBundle(Class<?> cls, Locale locale) {
String baseName = classBundleBaseName(cls);
ClassLoader cl = cls.getClassLoader();
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, cl);

// could also be simply ResourceBundle.getBundle(baseName);

return bundle;
}
13 years ago