I think the following should do you <img src="${imageUrl}" alt="Author photo" height="<c:out value="${DATA_PHOTO_HEIGHT}"/>" width="<c:out value="${DATA_PHOTO_WIDTH}"/>" />
On 6/22/07, Johnny Kewl <[EMAIL PROTECTED]> wrote:
Hi Nikola, never done it, but I think you have to override the resolver. ie instead of the standard resolver, which looks for standard properties or custom classes declared thru XML.... yours will tie to a class in your app. Managed to find an ok article.... maybe its enuf for you to find the relevent code in spring, and steal it ;) http://today.java.net/pub/a/today/2006/03/07/unified-jsp-jsf-expression-language.html ----- Original Message ----- From: "Nikola Milutinovic" <[EMAIL PROTECTED]> To: "Tomcat Users List" <users@tomcat.apache.org> Sent: Friday, June 22, 2007 10:46 AM Subject: How to write this elegantly in JSP/EL > Hi all. > > This is not really TC related, but more JSP and EL question, but I thought > I'd ask. > > I would like to have an elegant way of using constants from Java classes > in EL. This is a relatively good illustration of what I am talking about. > Take, for instance, a Spring controller. It has a method where the > programmer can bind objects to model-and-view, which basically binds it to > a request or session scope. It is very similar to a plain Servlet doing > "request.setAttribute( "name", value )". > > public class SomeController extends SimpleFormController { > > public static final String DATA_PHOTO_WIDTH = "photoWidth"; > public static final String DATA_PHOTO_HEIGHT = "photoHeight"; > > ... > > protected referenceData( ... ) { > > ... > > modelAndView.put( DATA_PHOTO_WIDTH, photoWidth ); > modelAndView.put( DATA_PHOTO_HEIGHT, photoHeight ); > > ... > > } > > ... > > } > > > And then in JSPF or JSP: > > > > <img src="${imageUrl}" alt="Author photo" height="${photoHeight}" > width="${photoWidth}" /> > > > Notice that the EL variable name is the same as that constant. So, I have > 2 places to keep in synch. If I wrote that in a scriptlet, it would be > correct, from the point of "do not duplicate code": > > > > <%= request.getAttribute( > com.libris4you.books.maintenancepanel.AuthorTabController.DATA_PHOTO_WIDTH > ) %> > > Now, how could I do the same in EL? > > > Something like (tongue in cheek): > > width="${=com.libris4you.books.maintenancepanel.AuthorTabController.DATA_PHOTO_WIDTH}" > > Did I miss something crucial in EL? > > Nix. > > > > > > ____________________________________________________________________________________ > Get the Yahoo! toolbar and be alerted to new email wherever you're > surfing. > http://new.toolbar.yahoo.com/toolbar/features/mail/index.php > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]