-
Dec 3rd, 2010, 11:34 AM
#1
Seeking understanding for why beans in EL must be parameterless
So I have had a few questions for a while now and have never fully understood the reasons some things work the way they do. Because I respect the opinions of many this forum I thought I would get some of your thoughts on the best way of handling certain situations.
1. Why can you not have parameters method calls in beans in EL? I have read a lot about this and it seems this was enforced because of some higher general priniciple that I do not understand. Anyone have any thoughts on this?
2. If indeed, parameters should not be used how am I supposed stuff like the following:
2a. Let's say I was setting up a website where I wanted to translate some text on a page. This page is dynamically created and in order to get back the correct translation I need to use 3 pieces of information: the locale, the id, and the default text (if no translation is found). Because I could have multiple locales on the same page I can't just put the locale in the parameters.
Answer: I could have a static method declared in a tld and then call that like ${myfn:translate(myLocale, messageId, "default text")} (Aren't static methods as a general rule bad?) Thoughts?
Answer: I could set up some nested maps like translatorMap[myLocale][messageId]['default text'] but that too seems like a poor way of handling it.
Answer: I wish I could just put my bean in the application context and call ${translator.translate(myLocale, messageId, "defaultText")} but you can't have parameters in EL. Why?
2b. What if I am creating some text in a jsp page based on id. I want to use that id to check an see if I have more information available from the database, if it is there then make the text a link if not then don't make it a link.
Answer: Do all the checking before hand. That seems like a simple answer but this logic needs to happen on a lot of the pages on our website and each of these pages change a lot and it seems like it would be a maintenance nightmare.
Answer: Again I could use static methods or maps.
Answer: I wish I coul just do something like this textBean.displayText(textId) and then my logic could happen in there.
Final thoughts:translator and textBean are singleton bean in my application context. I initialize them when the server starts up. Perhaps I am missing something obvious on a normal clean way of doing things as mentioned above. I have already got both examples working using the static methods and maps so its not an issue of figuring out where a bug is. I just want to get some of your thoughts on what the best ways are to handle situations like this.
-
Dec 6th, 2010, 10:58 PM
#2
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules