This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!

Mikey Warren

Ranch Hand
+ Follow
since Jun 15, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mikey Warren

A colleague has pointed out that

The javadoc warns you about setting a date and then changing the day of the week or something
like that.

So changing the order of the statements so that the setTime is is done last results in consistent results
18 years ago
The following code calculates a week number of 17 when run on "JDK 1.3.1", and 18 for "J2RE 1.4.2_03" on my PC -

Any ideas why that should be ?

thanks Mike
18 years ago

I've just downloaded the free version of XMLBuddy eclipse plugin and it seems great for editing XML files,
except that I can't find out how to get it to validate XML files against XSD files (XML Schemas) - everything seems to be geared around using DTDs, although the website seems to suggest that it can handle schemas.

Anyone else had this problem ?
Looks over complicated to me - but I wouldn't count my self as a database expert, so perhaps I'm missing something.

Couldn't you just have two tables ?
One with panel id as the primary key and all the things that go with a panel, like name, modified date etc.
One with two columns, "panel id" and "contained panel id" that would give you all the panels contained in each panel.

Also not sure what "panel entry" table is for.
Not sure about "the scenario where every page has a 'Translate' button", but the code above could be used in a select language action to change the language to one chosen by the user at any point, all subsequent pages would be in the chosen language.I'd guess translating the current page without rerunning the code that generated it would require code outside the scope of struts to cache results - but I've only just started looking at Struts, so don't really know.
I'd also be interested in any tips on i18n as we're going to be i18nning our app at work soon. Not sure if we're going to use Struts, I'd quite like to, but it would be a lot of work for an existing webapp.It might be easier for us just to use message tags and properties files.
I had thought that the following code would set the locale of the whole webapp, but have just tried it out and it works per user session, so thanks to Rick for that.
18 years ago
Feel I'm being picky now, but just incase it helps anyoe else, the minlength of 5 set in validation.xml won't allow user to log on (as "user" is less than 5 characters long obviously) - so change the minLength, or the username of user, in loginBean.
18 years ago
Sorry - just showing off now, but I've just worked out to swap languages dynamically.
First create properties files for additional languages (e.g. for German), then in the execute method of an Action class you can set the language to German as follows, and the tags such as <bean:message> will use the German version. The Sun website has a trail on internationalization which gives a lot more detail, but I thought this might be of use to anyone just wanting to get going quickly with multiple languages in struts.
18 years ago
Just tried running through the examples in the two articles linked to at the top of this forum - they're very good as a quick introduction to getting a simple struts app. running.

- but I had a problem getting the 1.1 version working with the javascript validation. First the xml file should be "validation.xml" not "validations.xml" as its referred to in the article.
Second (I suppose this was my fault - but others may make the same mistake) the struts-config.xml file needs to refer to version 1.1 in the doctype (not 1.0). If you're just following the instructions then its easy not to notice this.
18 years ago
Thanks for the reply.
I was hoping that changing languages didn't mean just replacing the properties file with one for a different language - think I need to do a bit more reading up on that subject.
Think I agree with you on the advantages of Struts, I was just interested in peoples opinions. It certainly seems preferable to what we've currently got which is JSPs with lots of Java code handling submits and presentation of data.
18 years ago
I've just been learning the basics of Struts, and am thinking of suggesting its use where I work - we currently use a couple of inhouse 'frameworks' for templating HTML and loading/saving from database but I think Struts might help simplify our JSPs. Before suggesting it I thought I'd try summarising how it works to make sure I understood, and also try it out to see what potential problems might be. Since I'd gone to the effort of summarising it, I thought I'd post it here for any comments on what I've got wrong, and hopefully to help other newbies.
So heres my Quick Summary of Struts :
Struts is a framework for the development of web applications using JSPs.
A Servlet (class "org.apache.struts.action.ActionServlet") is configured in web.xml, with parameters specifying things like where the struts XML config file is. Also in web.xml this servlet is normally mapped to URL "/do/*".
JSPs are written using custom tags provided by Struts (obviously standard JSP code will work to, but the tatg help simplify the JSPs). Forms in JSPs map to Struts actions.
For each action (e.g. login, create user, submit score , etc. ) an Action class needs to be created extending "org.apache.struts.action.Action" and implementing the following function:

Also for each action a form class is created by extending ActionForm, this is a bean with getters and setters corresponding to the fields in the form on the JSP and a validate function which provides oportunity to check for missing fields, or format of data entered etc.
Signature of validate method:

In Struts 1.1 an alternative to creating a form class is to configure a dynamically generated form class, and also to employ client side javascript validation automatically generated from the config.
In the struts XML config file, forms and actions are configured.
The "Action" Servlet acts as the controller in the MVC pattern, the validate function of appropriate form class is called (if configured), if validation is OK then the approriate action object is used to handle the request via the execute method, otherwise the JSP with the form on is redisplayed with errors shown. The execute method interfaces with the "Model" - the main "business logic" of the application which probably interfaces with a relational database to do whatever it needs to do. Any errors encountered are added to an ActionErrors object and saved in the request, so they can be displayed.
Then an Action forward object that will be returned needs to be created based on the results of the action and config in the Struts Xml file - e.g. forward to display a list of users, or to display errors. The Struts framework then forwards the request to the appropriate URL based on the Action Forward object - normally a JSP, which acts as the "View" in the MVC, possibly displaying errors stored in the request.
This description has just covered the normal core functionality, Struts provides other stuff, and can also be configured to behave differently.
======================= End of summary
Problems With Struts
As I've only just started experimenting with Struts its a bit early to be sure of what the problems are, but anyway here goes:
  • Properties file will quickly get very big and unmanageable.
  • Language selection using properties file :- Ideally I'd like to make language selection dynamically by user, not by swapping properties files. Perhaps I'm missing something.
  • Yet another thing for developers to have to learn - not sure about this, its probably easier to learn Struts than work on a JSPs which submit to them selves with loads of Java scriptlets
  • Its too generic/complex/heavyweight - notice a few posts suggesting this, but again, not sure that I agree

  • OK - Thats it any comments welcome!
    [ March 25, 2004: Message edited by: Mikey Warren ]
    18 years ago
    Thanks to JavaRanch for the forums and mock exam.
    Aswell as using Servlets and JSPs at work, I used the Manning SCWCD Study Kit book to concentrate on the exam topics and learn about tag libraries.
    I was a bit worried earlier in the week as I only got 55% on the JPlus exam simulation that came with the Manning book, but some last minute revising did the trick. The Exam Quick Prep section at the back of the book is very good and helped at lot.
    By the end of the week I was getting 80%+ in the JPlus exams and 92% on the JavaRanch mock. I'm not sure if I would say it was easier than the programmer exam - I find remembering loads of XML tag names and method/interface names doesn't come naturally.
    Anyway good luck to anyone else taking the exam, and hats off to those that have already done it
    18 years ago
    Suprised no ones mentioned solareclipse.
    Although it doesn't do code completion, which is what I really miss, and the syntax highlighting is a bit hit and miss, its what I use at work, and the best we've found so far.
    I would consider paying $30 for MyEclipse if it did code completion on JSPs, just had a quick look at their website and couldn't see if would or not.
    Think we tried colorer, but decided solareclipse was better (seem to remember that colorer doesn't let you use spaces instead of tabs, amongst other things).
    Ideally I'd like an HTML/JavaScript/JSP editor that worked in the same way as the main Java editor for Eclipse, and provided code completion for HTML and JavaScript which I always end up having to reach for manuals for when I'm forced to work on JSPs, and for free - but suppose thats asking too much - be interesting to see how the various plugins develop over time.
    Just to let you know that I've had a quick scan of the J2EE spec. - and you're right.
    I'm still a bit confused though - Servlets and JSPs are part of J2EE - but am I right in thinking that a web application that just uses JSPs and Servlets, and an application server like, say Tomcat, (and not a J2EE server like Websphere) is not a J2EE application?
    Having written the question down I think perhaps the answer is that it can be said to be a J2EE app.,although Tomcat doesn't implement EJB Containers - ?
    In the end I suppose it doesn't matter what the exact definition of J2EE application is, as long as we know what each other is talking about.
    OK - thanks, I did have a feeling that there was some confusion about what actually comprises J2EE.
    I will have a look at the spec. to help clarify things for me.
    Whilst EJBs isn't all that J2EE is, I think that from Suns J2EE tutorial , and books based on J2EE (like SAM's J2EE in 21 days) it does seem to me to be an essential part, but perhaps I should read the spec. before digging a bigger hole for myself.