日期:2014-05-17  浏览次数:20631 次

jstl,不能隐藏标签元素
想实现这样的功能:
当用户头像为空的时候,不显示加关注,当用户头像不为空并且为关注的时候,显示添加关注!



目前是这种情况,当用户头像为空的时候,会显示添加关注。


Java code


                  <div class="userPhoto">
                     <a href="#" namecard="true" uid="${user.uid}">
                         <c:choose>
                                  <c:when test="${empty user.mugshot256}">
                                         <img alt="" src="${RESOUCE_STATIC_URL}/images/avatar_64_64.png">
                                  </c:when>
                                  <c:otherwise>
                                        <img alt="" src="${RESOUCE_UPLOAD_URL}/${user.mugshot256}">    
                                    <c:choose>
                                            <c:when test="${user.beenFollowed}">    
                                                <c:set var = "styleFollow"  value="display:none" />                    
                                            </c:when>
                                            <c:otherwise>
                                                <c:set var = "styleFollow" value="" />
                                            </c:otherwise>
                                    </c:choose>
                                      <a class="follow-action blue-button-addnew" title="加关注" style="${styleFollow}" uid="${user.uid}" ><span class="addnew">+</span></a>
                                  </c:otherwise>
                         </c:choose>
                     </a>
                  </div>




本人对jstl不是很熟悉,望大家指点!

------解决方案--------------------
<c:if>呢?用这个
------解决方案--------------------
<c:when test="${empty eq user.mugshot256}">
<img alt="" src="${RESOUCE_STATIC_URL}/images/avatar_64_64.png">
</c:when>


或者
 <c:when test="${user.mugshot256 eq ""}">
<img alt="" src="${RESOUCE_STATIC_URL}/images/avatar_64_64.png">
</c:when>

------解决方案--------------------
取消EL表达式的嵌入看看.
HTML code

 <div class="userPhoto">
                     <a href="#" namecard="true" uid="${user.uid}">
                         <c:choose>
                                  <c:when test="${empty user.mugshot256}">
                                         <img alt="" src="${RESOUCE_STATIC_URL}/images/avatar_64_64.png">
                                  </c:when>
                                  <c:otherwise>
                                        <img alt="" src="${RESOUCE_UPLOAD_URL}/${user.mugshot256}">                                    
                                            <c:if test="!${user.beenFollowed}">    
                                               <a class="follow-action blue-button-addnew" title="加关注" style="${styleFollow}" uid="${user.uid}" ><span class="addnew">+</span></a>
                                            </c:if>                                            
                                  </c:otherwise>
                         </c:choose>
                     </a>