Dan Ludwig

Greenhorn
+ Follow
since Jun 05, 2004
Merit badge: grant badges
For More
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 Dan Ludwig

ok, it appears that this forum is not a good place to post. so that i don't look like a complete idiot, i thought i'd post a reply. in case anyone is experiencing the same problem, i semi-solved it:

there is a bug in the current struts 1.2.4 release. see the following links:

http://issues.apache.org/bugzilla/show_bug.cgi?id=32401
and
http://issues.apache.org/bugzilla/show_bug.cgi?id=21760

the problem is in org.apache.struts.validator.Resources.getArgs and Resources.getMessageResources (in same class). The validateXXX methods in org.apache.struts.validator.FieldChecks use Resources.xxx methods as helpers. because you can define your own validators in validator-rules.xml, this is a hook into solving the problem.

i got it to work by defining my own MyFieldChecks.validateXXX methods, and creating new MyResources.xxx methods.

if you're trying to do this, it's really quite simple. overload MyResources.getArgs(...), adding an HttpServletRequest argument to the parameter list. Also overload MyResources.getMessageResources(...), adding a String argument to the paramter list.

modify your code in MyResources.getActionMessage(HttpServletRequest, ValidatorAction, Field) to call the new overloaded getArgs, and in that method, when you come to this line:

if (args[i].isResource()) {

... check to see if args[i] has a bundle:

if (!GenericValidator.isBlankOrNull(args[i].getBundle())) {

... and if it does, get the resources for that bundle:

messagesSaver = messages;
messages = getMessageResources(request, args[i].getBundle());
}

... then use the standard helper method to get the message:

argMessages[i] = getMessage(messages, locale, args[i].getKey());

... afterward, be sure to reset messages to its original value:

messages = messagesSaver;

you will also of course need to update your validator-rules.xml file to use your new MyFieldChecks.validateXXX methods.
19 years ago
Just beware of what you're getting into with JSF -- don't dive in just because it's a Sun spec.

I did a long evaluation of jsf, and it has a lot of potential, but the implementations are still in infancy. JSF has a lot more power than struts when it comes to extensibility, but some features just aren't there yet. For example, you can't submit a JSF form using the GET method -- all form submits are POSTs. There are a lot of little nuances like this that surprised me.

The upside to this is that you can create your own tags, components, validators, converters, events, etc, extending JSF to meet your requirements. Just because the features you need might not be in the RI doesn't mean you can't create them. The problem is that you could get so bogged down in JSF details that you could lose track of your application project.

I agree that the power of components is probably the biggest advantage JSF has over struts, but the RI components are basic. You can use the basic components to compose more complex ones, for example using two list-boxes and some action-buttons to create a shuttle component. Oracle is building a lot of components like this into their ADF faces, but it too is relatively new. I chose not to use JSF yet because its DataModel hierarchy didn't have the kind of pagination support I was looking for, although I'm sure that problem will eventually be solved.

So, it depends on your application / project. Just beware that although JSF is a lot like struts, it's not the same, and some things you take for granted in struts might not be available in JSF.

Good Luck,

Dan
19 years ago
that's too bad that nobody posted to my last question, hopefully i'll get a little better response this time...

here's a sample validation snippet from validation.xml:

<form name="formName">
<field property="username" depends="required">
<msg name="required" bundle="com.xxx.projN.Messages" key="user.add.errors.username.required" />
<arg bundle="com.xxx.projN.Messages" key="user.field.username.display" position="0" />
</field>
</form>

I have to specify the bundle attribute because these messages are not in the default bundle. validation happens, and although it retrieves the "user.add.errors.username.required" message properly, it is retrieving a blank string for the argument.

i've actually snooped the source quite a bit, and narrowed it down to a single method:

org.apache.struts.validator.Resources.getMessageResources(HttpServletRequest)

this method is a one liner:

return (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

...where Globals.MESSAGES_KEY resolves to "org.apache.struts.action.MESSAGE", the default bundle key.

what i really need is a method that can handle this:

return (MessageResources) request.getAttribute((String) arg2_bundleName);

i know i could fix this by moving the arg to the actual properties file bound to the default message bundle, but this really goes against the application architecture.

am i stuck with overriding validateRequired, etc? does anyone know if this is a bug, that although I can specify a bundle name for the <arg .../>, it doesn't resolve? would an upgrade from struts 1.2 fix this?

Thanks,

Dan
19 years ago
I think it's great that I can compose validation failure messages using a resource properties file, passing in different resource keys as arguments like so:

<field property="fieldname" depends="required">
<msg name="reqmsg" key="form.add.errors.fieldname.required" />
<arg0 key="form.fieldname.display" />
</field>

..Which has a properties resource that results in the message:

<span class="error-field">Field Name</span> is required.

So, what if I want to use a runtime value as a message argument? Is that possible with the Struts Validator? How is it accomplished? For example, my target message would be something like:

The <span class="error-field">Username</span> <span class="error-value">root</span> is already taken by another user. Please choose a different <span class="error-field">Username</span>.

... The message properties would look something like:

user.add.errors.username.taken=The <span class="error-field">{0}</span> <span class="error-value">{1}</span> is already taken by another user. Please choose a different <span class="error-field">{0}</span>.

But, I can't find any documentation on how to configure validation.xml to pass the argument in from a FormBean property. Am I chasing my tail, or is this possible?

Thanks,

Dan
19 years ago
What's the best (most efficient and portable) way to get "SELECT COUNT(*) FROM TABLE" functionality using CMP & EJB-QL 2.0 without JDBC?

I have this EJB system, using a session facade to front local entity beans, and it will be serving clients from a different web module in the application. One of the primary functions of the web UI is to view tabular data.

I want to paginate this data to maximize speed and efficiency. The client will specify how many rows-per-web-page it wants to display, along with the page-number to be viewed and possibly an order-by parameter. The job of the session facade is to use this client input to determine exactly which rows to return.

The server must take the rows-per-web-page variable passed by the client and then query the database to determine how many total records are available. The session EJB can then calculate the total number of pages to track pagination state. For example, if there are 100 total rows, one client many want to view 10 records per page whereas another client many want to view 20. The first client would have a 10-page chain, whereas the second client's pagination chain would only consist of 5 pages.

It's a simple system, and I've implemented it on other, non-EJB applications. The main problem I'm encountering has to do with querying the persistent store (db) to determine how many total records the UI will be selecting from. Right now I've implemented an EJBLocalHome findAll() method, which returns a Collection of EJBLocalObject stubs. By running the size() method on the Collection, I can determine the total number of records.

I don't like this solution because, as a table grows, the findAll() method will hog more and more resources. I don't want to make the server collect hundreds or thousands of entities when all I want is a single number. I've read about a design pattern (JDBC For Reading) that recommends embedding tabular read logic directly into the session facade, but I'm using CMP and want to declople the EJB layer from the persistence layer & SQL as much as possible. I heard that EJB 2.1 adds the COUNT() aggregate function to EJB-QL, but unfortunately my project is tied to EJB 2.0.

The only other thing I can think of would be to keep track of the number of rows in a table (entities in a home) myself, using another persistent EJB. That way, every time a row is added or deleted, the row-count would be incremented or decremented accordingly.

Has anyone else found a better solution to this problem? What's the best (most efficient and portable) way to get COUNT() functionality using EJB-QL 2.0 without JDBC?
this post might belong in the ejb-forum, but since i'm currently studying for the scbcd exam, i didn't want to sound like a dunce posting it there

the headfirst ejb book briefly mentions using abstract 'super-interface' implementation classes to avoid having to code empty ejbActivate, ejbPassivate, etc. in a Bean class. For example, one can create an abstract class that implements the SessionBean or EntityBean interface, along with container callback methods. By extending this abstract class, one could avoid having to code empty implementations of these 7 methods in a Bean class.

For my own research, I'm trying to implement this pattern. I want to place a reusable abstract class in a jar that can be reused across several other ejb-jar's. However, I'm unaware how jar dependencies must be declared for ejb's, if at all. For example in a WAR file, one can place dependent jar files (like ejb client jars, utility jars, etc.) in the WEB-INF/lib folder. As long as the required jars are there, one need not declare jar dependencies in web.xml.

Will this also work for an ejb-jar file? Could I simply put my abstract-ejb.jar file in the META-INF/lib folder? Or must jar dependencies be declared in the application.xml so that they function properly in the EAR file?
I found some other docs on doing the SHA and MD5 encryption using MessageDigest, and your above example works great if that's how the data is encrypted. I still think an environment entry might be necessary though, to be able to configure the encryption method at deployment time (one which would work with some kind of MessageDigestCryptionFactory) depending on the database.

However, what I'm looking for here is more of an answer to the portability issue. What if the persistent store uses an encryption algorithm other than SHA or MD5? Do I need to become a cipher expert if I want my CMP bean to work with several different database vendors, and work with existing data (that for example I, as the Bean Provider, cannot suggest encryption policies for)?
Everywhere I keep reading "you should [almost] never have to use BMP with EJB 2+ [if you have a realational database]" or some version of that advice.

But I keep wondering, what if some application data is almost guaranteed to be encrypted in the persistent store, using either one- or two-way encryption? For example, MySQL's PASSWORD() function is a fairly common one-way encryption mechanism for passwords, and many other 2-way encryption algorithms can be used to cipher credit card numbers or other legally-sensitive information.

If I want an entity bean to represent objects with sensitive, more-than-likely-encrypted-in-the-persistent-store data fields, what's the best way to approach this? Use a BMP bean that harnesses the ease of using decryption methods in the actual SQL code? Or use a CMP bean wrapped with a session facade (like a DecryptorFactory of some sort) that can make sense out of the encrypted data?

What's the best way to do this and keep the ejb-jar portable across different database implementations? Is there any way to achieve one-way encryption with java? This has been bugging me for a long time. If anyone has any best practices or good ideas, please share, thanks!
Are there any free mock exams for IBM tests 285, 286, etc? If so, where can I find an index of some? I want to get a feel for the types of questions asked before I shell out $10 for a Sample Test from IBM...

Thanks!
... it's such a crude way to do it that i've abandoned this approach altogether. if you're reading this post, don't do what i did!
thanks for the tips,

i actually did find a way to do this, although i admit it's a bit crude:

try {
throw new Throwable();
} catch (Throwable t) {
StachTraceElement[] s = t.getStackTrace();
locate: for (int i=0; i<s.length; i++) {
if (!s.getClassName().equals(this.getClass().getName())) {
// this will execute when the calling class
// is found
break locate;
}
}
}

as long as i define a rule in my application that this method is always called from the client entity with the class name that i need, and no other classes, i think it'll work.

i'd like to hear some opinions on this, i'm sure there are at least a couple...

thanks!
hi,

i'm implementing a sequence block behind a session facade to serve as a primary key generator for other entities (imitating a database auto-increment column). i want to name each sequence according to the entity ejb it serves, without passing a string if possible.

i have the ejbCreate method of each entity bean obtain an instance of the sequence's session facade bean, which issues it a new integral primary key. the session ejb looks up the correct number based on the name of the sequence, so the sequence name needs to be passed from the client entity that is requesting the new primary key doesn't it?

i thought i remembered reading somewhere that a method's client (the class calling the method) can be looked up and referenced without passing the client itself as an argument. if this is possible, i'd like to do that instead, i.e.:

1.) EntityEJB calls the getPrimaryKey() method on a Stateless Session EJB.

2.) getPrimaryKey() *somehow* retrieves a reference to the EntityEJB, even though an instance of it was not passed as an argument.

3.) getPrimaryKey uses this *magic* reference to call getClass().getName() and get the EntityEJB's class name as a String.

4.) getPrimaryKey uses this String to either create a new sequence or findByPrimaryKey and return the next number in the sequence.

i'd rather not hard-code the String name of each sequence into its respective EntityEJB if this can be retrieved automatically. i'd also like to avoid doing a getPrimaryKey(this), since the facade bean will work with different entities and i don't want my entities to polymorph at all.

if anyone knows how i can get the name of the class that called a method, from within the method itself, without passing an instance of the class as an argument, please let me know. Thanks!
I had a hunch that was it, thank you!
hi,

taking John Hunt's mock SCJP exam, am finding a lot of java.awt questions, which i wasn't aware would be on the real exam. i'm mainly a servlet / bean programmer, so i have no familiarity with this package. will it be on the test? if so, why is it not listed in the objectives? if not, is there any particular reason these questions are on John Hunt's mock exam?

Thanks,

sophomore
Ok, I think I understand it a little better now, please someone tell me if I'm wrong:

Mobile overrides the showDevice() method. When the new Mobile is constructed, the Phone (superclass) constructor is called, which in turn calls showDevice(). However, Java uses the overridden showDevice() method from the Mobile subclass when the method is invoked in the Phone constructor. After the Phone constructor runs, the Mobile constructor runs and then the showDevice() method is called a third time on line 11 of the Mobile class file.

What I don't understand is, does the Phone constructor polymorphically mutate into a Mobile when the showDevice() method is called from the Phone constructor? Does that mean that when a subclass calls super(), it will use methods in that super() call polymorphically? I always thought superclass constructors ran independently of their subclasses, but I guess I have an incorrect understanding of how this works.

Oh, and one other thing that threw me about this question -- the showDevice() method in the Mobile subclass accesses a non-static instance variable (device), and then is used in the constructor. I thought constructors couldn't use or access non-static instance members unless they were part of the call to this() or super(). I've read Kathy & Bert's book twice now, why oh why doesn't this make sense to me (third time's a charm I hope...)

Thanks again all,

sophomore