While using struts’ html tags I noticed that I couldn’t use the EL expressions with them. EL - Expression language that lets you access bean values using simple dot operators, instead of having to use scriptlets <%…%>. We normally give EL expressions enclosed with ${…}. So for e.g. if you want to access strName property of Customer bean which is placed in session, then EL expression - ${sessionScope.mycustomer.strName} would retrive the value of Customer bean’s strName property. This will work only when you follow java bean specification, i,e, the class should be serializable, must have getXXX(), setXXX(), isXXX() methods.
Sorry for digressing, but I thought it would be better to let the newbies know what is EL tags. Ok, so I tried to use EL expression with the html:multibox tag (I’d taken a iteration, didn;t show here. I wanted to generate unique ids for each checkbox generated.) -
<html:multibox styeId=�${count} />
…the expression ${count} didn’t evaluate. <input type=”checkbox” id=”${count}”>
Ok…so solution is….to be able to use the EL language with struts tag library, I’ve to use the struts EL tag library. So replace below -
<%@ taglib uri=”/WEB-INF/taglib/struts-tiles.tld” prefix=”tiles” %>
<%@ taglib uri=”/WEB-INF/taglib/struts-html.tld” prefix=”html” %>
<%@ taglib uri=”/WEB-INF/taglib/struts-bean.tld” prefix=”bean” %>
With
<%@ taglib uri=”/WEB-INF/taglib/struts-tiles-el.tld” prefix=”tiles” %>
<%@ taglib uri=”/WEB-INF/taglib/struts-html-el.tld” prefix=”html” %>
<%@ taglib uri=”/WEB-INF/taglib/struts-bean-el.tld” prefix=”bean” %>
…and you should be able to use the EL language, provided you have the struts-el.jar jar in WEB-INF/lib folder of your web app.
To understand the struts-el tag library, follow the link - http://struts.apache.org/1.2.x/userGuide/building_view.html#struts-el
I’m borrowing this from the above link -
” Although the Struts-EL tag library is a direct “port” of the tags from the Struts tag library, not all of the tags in the Struts tag library were implemented in the Struts-EL tag library. This was the case if it was clear that the functionality of a particular Struts tag could be entirely fulfilled by a tag in the JSTL. It is assumed that developers will want to use the Struts-EL tag library along with the JSTL, so it is reasonable to assume that they will use tags from the JSTL if they fill their needs.”
So you need to be aware that not all struts tags would be available when you use the struts-el tag library. In short, whenever you can use JSTL tags, use it. Most probably you’ll only ever need to use the struts html tag library.