Widerberg
Widerberg

Reputation: 1138

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.. I´m used to PHP where this kind of code-includes are daily meat.

Can someone please point me in the right direction?

Thanks in advance!

Upvotes: 1

Views: 959

Answers (4)

Prakash K
Prakash K

Reputation: 11698

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>
    

Upvotes: 2

Sandeep Nair
Sandeep Nair

Reputation: 3660

You can also do this.

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

Upvotes: 1

user832497
user832497

Reputation:

<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);

...

Upvotes: 3

choop
choop

Reputation: 921

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

Upvotes: 0

Related Questions