当前位置: 动力学知识库 > 问答 > 编程问答 >

html - How do i include jsp code in tags? See example

问题描述:

Like the topic says; How do I include ordinary jsp code in tags? (In my case liferay tags, but it could as well be html-tags)

Example:

<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"

extended="<% if (noService==false) {

out.print("false");

}

%>">

Test panel

</liferay-ui:panel>

In the example i just want to insert "false" so the expression looks like the following:

<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"

extended="false">

Test panel

</liferay-ui:panel>

This gives me a jasperException.. Im used to PHP where this kind of code-includes are daily meat.

Can someone please point me in the right direction?

Thanks in advance!

网友答案:
<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
    extended="${noService}">
    Test panel
</liferay-ui:panel>

noService must be set in request e.g.:

java:

...

    request.setAttribute("noService", false);

...
网友答案:

You can have (I'm using ELs, as they are much cleaner):

  1. If variable noService is a boolean:

    <c:set var="isExtended"><%=noService ? "true" : "false" %></c:set>;
    
    <liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
            extended="${isExtended}">
        Test panel
    </liferay-ui:panel>
    
  2. If variable noService is a String:

    <c:set var="isExtended"><%="false".equals(noService) ? "false" : "true" %></c:set>
    
    <liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
            extended="${isExtended}">
        Test panel
    </liferay-ui:panel>
    
网友答案:

You can also do this.

<liferay-ui:panel id="panel-c4" title="Service Bulletins" collapsible="true"
extended="<%=String.valueOf(noService)%>">
网友答案:

You need to use a Bean
read this:
http://www.exampledepot.com/egs/javax.servlet.jsp/usebean.jsp.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: