Win a copy of The Career Toolkit this week in the Jobs Discussion forum!

Wally Hartshorn

Ranch Hand
+ Follow
since Jan 30, 2003
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 Wally Hartshorn

Does the lack of responses indicate that more information is needed, or does it indicate that what I posted looks correct so I must be doing something stupid elsewhere?
I have an existing JPA/Hibernate application. I'm adding a new table to the database and am adding a one-to-many link from an existing table.

However, when I try to access the records from the new table via that one-to-many relationship, I get no records returned.

In the Absence class for the new table, I have these lines:


In the Employee class for the existing table, I have these lines:


In another class, I'm doing this:


I don't get an error, but I don't get any records, either. When I check the log, I find that the call to absence.size() returned 0.

I get exactly what I expect when I try this query:


What am I doing wrong?
Suppose I have a class (Dog), a subclass (Poodle), and a Dog object that I want to use to create a Poodle object.

One way to do that would be something like this:


Having to explicitly list all of the fields of the Dog object to set them in the Poodle object feels wrong. Is there a better way to do this?
9 years ago
Suppose that you have a time of day in the form of a string, such as "12:15 PM". You want to be able to add some arbitrary amount of minutes to that time to get a new time string. You don't care about the date, only the time (so you don't care whether "11:30 PM" plus 60 minutes rolls over to the next day).

What would be the best way to write a function to handle this? (No, it's not a homework assignment.)

My guess is to pass the time string to the SimpleDateFormat parse() function to get a Date object, then use that to initialize a GregorianCalendar object, then perform the math, then reverse the process to get the new time string, such as "12:45 PM".



I don't expect execution time to be a factor, but the conversions to a Date object, then to a GregorianCalendar object, and then back to a Date object feel somewhat annoying.

Is there a better way to do this?

The only other way I can think of to do it would be to convert the time string into minutes since midnight, do the math, and then convert back. I suspect that would be even more annoying.
10 years ago
How can I initialize a complicated JavaScript data structure from Java?

I have a JavaScript data structure that, if hard-coded, would look something like this:


WorkSchedule.js looks like this:


However, the specific values will be pulled from a database by my Java code, which would then initialize the JavaScript data structure. Unfortunately, I don't know how to do that.

In the past, I would place values in hidden fields and then initialize variables from those hidden fields. However, this involves a far more complicated data structure (hashes, arrays, objects, etc).

How could I do this? (I'm using Java 5 and JavaServer Faces, if that matters.)

Thanks!
11 years ago
JSF
ListBean is the backing bean (request scope) for a list of links to items. The constructor can take quite awhile to run (e.g. 30 seconds).

ItemBean is the backing bean for an individual item. The constructor runs quite quickly (e.g. 1 second).

A user goes to the List screen, and the ListBean constructor runs and generates a list of links to items. The links were created by t:commandLink tags.

The user clicks on an item in the list to view the item's details.

The ListBean constructor runs again, taking 30 seconds to do so, even though we don't actually want to do anything with the ListBean.

Finally, the ItemBean constructor quickly runs and the item details are displayed.

How can I avoid the unnecessary running of the ListBean constructor? I have "immediate='true'" on the t:commandLink tags, but of course that doesn't prevent the constructor from running.

I'm guessing my only real option is h:outputLink, but so far as I know I can't specify a method to be run the way I can with t:commandLink, nor can I attach an actionListener to it.

I suppose another possibility is to change the ListBean to session scope, but then I need to modify my logic to ensure that the bean is refreshed when the list screen is displayed.

Any ideas?
12 years ago
JSF
Consider this bit of JSF code:

In the above example, the boolean method isFirstTest() is called. If it returns false, we don't want to output either of the child outputText values. If it returns true, then we want to output the first child outputText value ("Hello"), and we might or might not want to output the second child outputText value ("World"), depending upon the result of the call to isSecondTest().

If the first test returns false, I don't want the second test to be performed at all, because it will result in an error. However, what seems to be happening is that the second test being called (triggering the error), even though the it is on a child of an element that is not being rendered.

This seems like incorrect behavior on the part of JSF. Since child elements aren't supposed to be rendered if the parent element isn't rendered, what is the point of performing the rendered test of the child element? Am I misunderstanding something?

(I'm using MyFaces and Tomahawk 1.1.5.)
12 years ago
JSF
(I'm not sure where to post this question, since I suspect this is more a web browser issue than a Java issue. If anyone knows of a different forum (i.e. not Big Moose Saloon) where this would be more likely to get a response, please let me know!)

If I access my Java webapp using Firefox or Opera, it works fine. If I access the webapp using Internet Explorer 6 or 7, it works fine only if I get there by IP address.

However, if I access the webapp by the DNS name using Internet Explorer, the JSESSIONID cookie is silently rejected. I've set all security and privacy settings to the most permissive levels with no effect. I've told IE to prompt me whenever a cookie is offered, but I'm never prompted. I've created a P3P privacy policy, but that doesn't matter.

I installed SmartSniff to watch TCP packets on my PC. I can see the Set-Cookie header come in, so I know that the server is sending it and the PC is receiving it. In IE, if I do View >> Web Page Privacy Policy, I see the message "Based on your privacy settings, no cookies were restricted or blocked."

This is very frustrating. As I said, it works fine if I access it by IP address or using Firefox or Opera. It is only IE accessing the site by name that has problems.

One postscript on the P3P privacy policy: I've created it, and I can view the summary in IE, but for some reason the Compact Policy doesn't show up when I access the site by IP address and tell IE to prompt me about cookies. (When IE prompts you about a cookie, you can select "More Info" to view the cookie. The Compact Policy field there is empty.) I don't know whether that matters, since IE will accept cookies from numerous other sites that do not have privacy policies.

One last bit of information: This is an intranet application, so the web server is on our own network.

Tomcat 5.5.26
Java 1.5.0_15
MyFaces 1.1.5
IE 6/7
Windows Server 2003 SE SP2
Windows XP Pro SP2
12 years ago
I just undeployed a webapp I am developing and saw this error in the catalina.log file:


The webapp appears to have been undeployed successfully, but I'm a bit worried about this error message. I've been having some symptoms that I suspect might indicate a memory leak or some failure to free a resource, and I'm wondering whether this error message might be related.

Does anyone have any ideas about what this might mean and/or how to investigate it further?

This happened while running Tomcat 5.5.26, JVM 1.5.0_15, and Windows XP.
12 years ago
(For those just joining this thread: If the user clicks "Save", certain validations are optional, but if the user clicks "Submit", all validations must pass.)

I can do the check as part of the method being executed as a result of clicking the "Submit" button, but because we're no longer in the validation phase at that point, there's no way for me to add a FacesMessage to the FacesContext (so far as I know).

Is there no way for a custom validation method to determine which button was clicked on the form? If nothing else, the FacesContext must know what action is to be performed after validation is complete. Is there any way to get access to this information?

Anyone have any ideas?
13 years ago
JSF
I have a form with numerous input fields (laid out like a spreadsheet) and 2 buttons, "Save" and "Submit".

When the user clicks "Save", a hidden field at the end of the form triggers a custom validator, which examines the values in the input fields. It adds up the values in each column, comparing them to the expected total for that column. Any columns that have values must be correct. Any columns that are empty are ignored.

When the user clicks "Submit", I would like the same validations to run. However, at that time, empty columns would trigger validation errors.

My problem is that I can't figure out how the custom validator can determine which button was submitted, "Save" or "Submit".

The "Save" button has an action of "#{myForm.save}", while the "Submit" button has an action of "${myform.submit}". As a result, different methods are run when the buttons are clicked, but by then it is too late to do any further validation, right?

Any ideas?
13 years ago
JSF
I'm trying to use JNDI Realm for the first time and I think I'm pretty close. It allows me to login, authenticating me to our LDAP server, but then I am denied access because it thinks I don't have the right roles. I don't know whether my role search is configured improperly or whether I'm specifying the role incorrectly or what.

Presumably the thing to do would be to check the log to see what sort of problem it has encountered, but I'm unable to figure out how to enable logging of JNDI Realm messages.

In my webapp's context.xml, I have:


Every example I've seen has that 'debug="99"', but I've never seen an explanation of what it actually does. Does that turn on debug log message? Or turn them off? I've tried changing it to other values (1 and 0), but have seen no change in behavior.

My log4j.properties file looks like this:


Do I need to add/change a line in there to enable logging of JNDI Realm messages?
13 years ago
Is there an easy way to convert an array of Floats to an array of floats?

The only way I've come up with is to loop through the array of Floats and assign each value to the corresponding position in the array of floats.



That seems rather pointless. However, trying to do something like this doesn't work:


Am I missing something easier?
13 years ago
I just want to emphasize that I'm trying to do this stuff within a normal backing bean. Will FacesContext.responseComplete work within such a situation, or does it need to be in some sort of listener or navigation handler?
13 years ago
JSF

Originally posted by Ravindra Rawat:
You can try the following:




Well, shoot, that looks very promising, but it doesn't seem to work. I thought perhaps the order of the statements was simply reversed, so I swapped them, but it still wouldn't work. My webapp simply refuses to stop trying to call getters for properties in mainPage.jsp.

In Sun's Life Cycle of a JavaServer Faces Page, the section about the "Apply Request Values Phase" states:

At this point, if the application needs to redirect to a different web application resource or generate a response that does not contain any JavaServer Faces components, it can call FacesContext.responseComplete.



That sounds like exactly what I'm trying to do -- redirect to another outcome -- but JSF seems to be ignoring me. I'm stumped.

Any other ideas?
13 years ago
JSF