In PHP, I commonly would do something like this:
foreach(array('street','town','county','postcode') as $e) {
echo $address[$e] . '<br/>';
}
It’s concise and easy to work with. Is there any way of doing this in EL? I’m having trouble finding a good way to do it cleanly.
There’s nothing like that in standard JSTL/EL, but you could use JSTL
fn:split()to split a single delimited string to an array:(provided that
${address}points to aMapwith the given values as keys or a Javabean with the given properties)Or if the
${address}is indeed aMapwhich contains only those keys already, you could also just loop over theMapitself:(the map key can in the above example be printed by
${entry.key}; also note that you needLinkedHashMapin order to maintain insertion order)