Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Darren Briaris

Greenhorn
+ Follow
since Jul 19, 2006
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 Darren Briaris

Newbie question!

I have a simple jsf page that currently binds the form items to a session managed bean. On submit of the page, the session bean is then persisted to the database.

I have a concern if the page is used to edit existing data in the session bean, and the user decides to cancel the update, how do I stop this being in the session?

Is there a best practice for this in JSF? Should I have all form fields binding to a backing bean object and only then , on submission of the form, update the session bean?

I need to cater for the fact that a page may be updated via a address lookup button (for example) which will populate some of the values on the form.

Any help appreciated!
11 years ago
JSF

Originally posted by vu lee:
You'll need to collect more data to detect what the issue is, where it occurs, and under what condition it occurs. The two previous posts suggested to put a try-cach block and disable friendly message.
1. put a try -- catch(Throwable t) around the block where you invoke the save method.
try{
...
...
savedOK = _UWDataSource.savePolicyHolderMotor(phMotor);
...
...
}catch(Throwable t){
//collect data.
}

2. You could collect more data by writing a test program using HttpConnection to invoke the servlet and print client side error msg.

3. Write a POJO test to detect whether savePolicyHolderMotor() alone does not cause any issues. In this test, just repeatedly calls savePolicyHolderMotor() a few times.

Once you have collected all the data, post them so people could eyeball to see what happened.



With regards to point 1, I have tried this and the catch block is not reached when the error occurs.

The problem only seems to manifest itself when using Internet Explorer. Firefox seems to be OK.

It also only seems to happen when a third party calendar javascript control is used on the page, rather than just typing a particular date in...

It seems bizarre that this causes the problem I am seeing but I will bo some more investigation...

Thanks again for everybodys help..
15 years ago
Clutching at straws a bit now. The problem I am having occurs, as stated previously, on the second submit. As part of the first submit the savePolicyHolderMotor() method is throwing a DiscusException (one of my own exceptions)in order to indicate an error code. Could this be causing the problem when the second submit tries to call the savePolicyHolderMotor() method?

I have added another test method that just returns a string and called this immediately before the troublesome line and it runs with no problems but the savePolicyHolderMotor() line still drops out immediately afterwards (on the second run).

Really getting confused by this now I have run the app off my local machine on a proper websphere server and get the same problem still , so it is not unique to my local setup.

Thank sin advance for any help offered!
15 years ago
Just a little bit more info... I seem to be able to reproduce the error constantly:-

It occurs on the second time submitting information from the page. The first submit works OK but the subsequent submit fails.
15 years ago

Originally posted by William Brogden:

from a browser sounds like one of those accursed "friendly" error messages that is concealing the real cause. In MS Internet Exploder you can turn off "friendly" error messages from the internet options dialog.

Bill



I have removed the 'friendly messages' on IE but still get a page not displayed. It appears to me the the thread on the server is juts 'dying' for no apparent reason. Nor error codes. no exceptions...

The browsers request is thus lost and no response received from the server.
15 years ago

Originally posted by Rahul Bhattacharjee:
To my best of knowledge server designs are failsafe.Due to some exception in the servlet you might get a 503 error , but its very unlikely that the complete server would crash.

If you are confident about the statement that is causing the problem , then I would suggest you to keep the statement within a try and catch (Throwable t) and then do a t.printStackTrace() , so that you will have an idea about what is happening , when it crashes.



I have a try catch block around the statement and it does not get hit by the code. I changes this to add your try./catch statement and this does not get hit either.
It seems that if I have a debug statement in the called method it seems to go into the code OK. Without this it just 'disappears' and the browser gets no response...
15 years ago
I am not sure where to put this post but have chosen here as the code is within a servlet. The following problem is intermittent:-

  • When I am running Websphere in run mode, the browser gets a 'page cannot be displayed error'
  • When running in debug with no breakpoints, the browser gets the same message but the server stops itself (with no errors in the log files)
  • Sometimes the code runs fine and I can step through in debug fine. Other times debug also fails when stepping over




  • I have a form that is submitted and goes into a servlet to be processed.

    It reaches a point where the following line is run:-



    at this point the browser gets a page can not be displayed message and my test websphere server stops. It does not reach the system out line in the following code:-



    There are no error messages on the server log.

    _UWDatasource is an object that is created in the init() of the servlet.

    I am struggling to find out what the problem may be... any help appreciated!
    15 years ago

    Originally posted by Paul Clapham:
    A web application with servlets and JSPs? Then if at all possible, configure a connection pool in your application server (Tomcat, Weblogic, whatever it is). They all support that as far as I know. Then just use JNDI to get a connection from the pool. You shouldn't be writing that sort of logic yourself unless there's a good reason that you can't use the server's connection pool.



    Thanks for the advice. I seem to be doing a lot of things the wrong way! I will look into using the Websphere app server connection pooling.

    Thanks again.
    15 years ago

    Originally posted by Bear Bibeault:


    As a general design principle, you should never create a singleton class unless you can write a 7-page dissertation justifying its existence.



    Fair enough! I'll drift off that idea!! So back to my plan of having an instance of each data access class created by each servlet - I think my worries about the sync'd code are unfounded because only one servlet will run the sync'd code and that servlet will use the same instance of the data access class thus the sync'd code will only be running in one instance??

    I sometimes have a real problem getting my head around the 'theory' of objects / instances etc...
    15 years ago
    This is quite a basic question and may well be in the wrong forum but forgive me for that. I am going to struggle to explain my question but I will give it a go.

    I have a servlet and jsp application and I am making sure that the data access code is seperated into its own classes. My question is what is the correct way to access the data classes from the servlets?

    Do I have each servlet create an instance of the data access class and then call the various methods on that instance (the data access class will get its connection to the db from a connection pool singleton class)?

    Or do I have the data access class as a singleton class and access the methods within that as static methods from within the servlets?

    If I have code in the data access class that I want to run syncrhonised to ensure it is only ever run once at anyone time, having mulitple instances of the data access class will mean that this synchronised code wont work properly as each instance can run at the same time?

    I hope some of that makes sense!

    I have real trouble getting my head around the im
    15 years ago
    I originally had this logged in the beginners forum but the ideas have dried up there so I thought I would try here. I hope this is not againist the rules but only my second post so if it is i apologise in advance.

    Here is my problem:-
    I have a java program packaged into a jar file. There is also a properties file I wish to distribute with the jar file (but not in the jar file). When I run the program it cannot find the resourcebundle. I get the error :-

    Caused by: java.util.MissingResourceException: Can't find bundle for base name c
    om.das.comp.stuff.messages, locale en_GB

    The jar file is in a directory on my local machine (say c:\whatever) and I am running the jar file from within that directory. Where should I put the properties file so it can be found?? I have pointed the classpath(in the manifest file) to include the C:\whatever directory and the .jar file itself and it still does not work.

    (It will work with the properties file in the jar file but that is what I want to avoid.)
    Any help greatly appreciated!
    15 years ago
    Just an update. I have fixed the "NoClassDef" error when using the maifest file within the jar file by adding the main jar to the manifest classpath entry.

    So that is sorted just the properties file causing the problem now..
    15 years ago

    Originally posted by Jesper Young:
    How are you running the jar? By using java -jar myjarfile.jar?

    When you run a JAR file like that, the CLASSPATH environment variable or the "-classpath" (or "-cp") parameters are not used. The classpath comes from the manifest file in the JAR instead. So it doesn't work to set the CLASSPATH environment variable to "C:\whatever" if you run your JAR with the "-jar" option.



    I am running the jar as you outlined above. If I have the manifest file in the jar file I have trouble running the program - "Exception in thread "main" java.lang.NoClassDefFoundError:"

    If I have a manifest file in the folder I am running the program from , this seems to work but gives me the error I originally posted.

    I think I am just getting myself more and more confused!



    My manifest file looks as follows:-

    Manifest-Version: 1.0
    Main-Class: com.das.stuff.prog.ProgramName
    Class-Path: jt400.jar c:/whatever

    Is this right? If not what should it be if the jar file is in the "c:\whatever" folder and I am running the program in that folder?

    Thanks for the help so far but I am finding this frustrating!
    15 years ago

    Originally posted by Chengwei Lee:
    Try putting the properties file into your JAR.



    That does work but I wanted the properties file available outside the jar so it can be changed without changing the jar file.

    I assume this is possible?
    15 years ago
    I have a java program packaged into a jar file. There is also a properties file I wish to distribute with the jar file (but not in the jar file). When I run the program it cannot find the resourcebundle. I get the error :-

    Caused by: java.util.MissingResourceException: Can't find bundle for base name c
    om.das.comp.stuff.messages, locale en_GB

    The jar file is in a directory on my local machine (say c:\whatever) and I am running the jar file from within that directory. Where should I put the properties file so it can be found?? I have pointed the classpath to include the C:\whatever directory and it still does not work.

    Any help greatly appreciated!
    15 years ago