I'm beginning on bug fixes for a program with which I have little familiarity. I've changed a section of code on one of the JSPs. I need it to print names with either of the two following formats (depending on whether or not the middle name property exists):
LastName, FirstName M.
LastName, FirstName
I believe my code should print the middle initial and the period if and only if that property exists, but for each name in the list, it prints:
LastName, FirstName .
It prints either no middle initial or a middle initial that is an empty string, followed by the period.
The relevant code is as follows:
<html:link styleClass="recordLink" action="/secure/admin/users?actionMethod=details" paramId="userId" paramName="users" paramProperty="userId">
<bean:write name="users" property="lastName"/>,
<bean:write name="users" property="firstName"/>
<logic:notEmpty name="users" property="middleName">
<bean:write name="users" property="middleName"/>.
</logic:notEmpty>
</html:link>
Why is the <logic:notEmpty>
tag not working? Could the middleName
property be determined to be non-empty if the property doesn't exist? Is there something wrong with my syntax?
I've also tried to use JSTL tags, but I could not get it working in OC4J (Error: "http://java.sun.com/jsp/jstl/core" is not a registered TLD namespace.)
The tag logic:notEmpty
evaluates to true because your middle name string has spaces. You should get rid of spaces before returning it to the tag. Better do it in the form bean like
public String getMiddleName() { return middleName != null? middleName.trim(): middleName;}