Struts <logic:notEmpty> not working or bean property not being written properly to JSP?
Solution 1
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;}
Solution 2
I suspect your middleName
is empty string or has spaces. if so try using logic:equal
to match and print some character instead of period, see what happens. If true, then trim the middleName
, before sending it of to JSP.
Matt Shank
Updated on June 05, 2022Comments
-
Matt Shank almost 2 years
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 themiddleName
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.)
-
Matt Shank almost 10 yearsIt doesn't seem like my middle name Strings have spaces. It prints an empty string or nothing at all.
-
Roman C almost 10 yearsNothing at all it can't print, make sure you have a valid characters.
-
Matt Shank almost 10 yearsI think you're on to something. I placed quotes around the printing of the middle name (
"<bean:write name="users" property="middleName"/>".
) and it printed a space.