[英]Using JSP tags efficiently for null value from java code
<% Object domName = request.getAttribute("domainName");
String documentationLink = UMRACM.getDomainDocumentationMap().get(domName);
%>
<td><a href="<%=documentationLink%>"target="_blank"
id="domainName_<s:property value="#rowstatus.index"/>"><s:property value="domainName" /></a></td>
好吧,我已经使用这种语法将href
打印为documentationLink,但我认为这不是一种有效的方法,因此使用`代码需要一些帮助。
有没有更好的方法来执行代码的逻辑部分。
如果我得到的话
documentationLink = null
如何使标签不可点击
<% Object domName = request.getAttribute("domainName");
String documentationLink = UMRACM.getDomainDocumentationMap().get(domName);
%>
这样做^^^到您的服务器端。 并将检索到的documentationLink
放入session
或request
范围。 像这样:
Object domName = request.getAttribute("domainName");
String documentationLink = UMRACM.getDomainDocumentationMap().get(domName);
request.setAttribute("documentationLink",documentationLink);
我可以看到,你使用的是Struts-tags
。 因此,删除您的scriptlet并尝试使用Struts2
使用的标记。 像这样,
<td>
<s:if test="%{#request.documentationLink != null}">
<a href="<s:property value="#request.documentationLink"/>"target="_blank"
id="domainName_<s:property value="#rowstatus.index"/>"><s:property value="domainName" />
</a>
</s:if>
<s:else>
<s:property value="domainName" />
</s:else>
</td>
使用CSS制作lable unfoable的一种方法
HTML
<a href="link.html" class="not-active">Link</a>
CSS
.not-active {
pointer-events: none;
cursor: default;
}
如果您的documentationLink
为null,那么您需要在分配给href
之前对其进行测试。
示例代码
<% if(documentationLink != null){%>
<a href="<%=documentationLink%>"target="_blank"
id="domainName_<s:property value="#rowstatus.index"/>"><s:property value="domainName" /></a>
<%}else{%>
<a href="<%=documentationLink%>" style="opacity: .5;
pointer-events: none;">"target="_blank"
id="domainName_<s:property value="#rowstatus.index"/>"><s:property value="domainName" /></a>
<%}%>
你可以尝试这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.