1

I'm trying to pass a parameter to flex:

<embed name='costsProject' src='CostsOfProject.swf' height='800%' width='600%' 
    pluginspage='http://www.adobe.com/go/getflashplayer'
    flashVars='projectId=#{cep_TBModelBean.projectId}'/>

But I get this error:

[ServletException in:../pages/gestioncep/viewTB/viewTBContent.jsp] javax.servlet.jsp.JspException: org.apache.jasper.JasperException: /pages/gestioncep/viewTB/testCost.jsp(14,163) #{...} is not allowed in template text'

When I write flashVars='projectId=292', it's ok and I get the result.

How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
senior
  • 2,196
  • 6
  • 36
  • 54
  • Which version of JSF do you use? It is a JSP exception. Try `${...}` instead of `#{...}` – Piotr Gwiazda Oct 23 '12 at 08:19
  • @PiotrGwiazda it's a JSP exception because it can't generate the jsp page. It will depend how OP prepares the data to define if it can use JSTL to solve this problem. For more info, read [JSTL in JSF2 Facelets… makes sense?](http://stackoverflow.com/a/3343681/1065197) – Luiggi Mendoza Oct 23 '12 at 08:33

2 Answers2

0

That's because the <embed> tag is not a JSF tag, so you can't use it directly. It would be better to have a <h:inputHidden> that holds the project id value and use Javascript to update your flashVars tag attribute using JavaScript.

<script type="text/javascript">
    function setupFlex() {
        var projectId = document.getElementById('hidProjectId').value;
        var flexObject = document.getElementsByName('costsProject')[0];
        flexObject.flashVars = 'projectId=' + projectId;
    }
</script>

<body onload="setupFlex()">
    <!-- note: the <h:inputHidden> is outside a form -->
    <h:inputHidden id="hidProjectId" value="#{cep_TBModelBean.projectId}" />

    <embed name='costsProject' src='CostsOfProject.swf'
        pluginspage='http://www.adobe.com/go/getflashplayer' height='800%' width='600%'
        flashVars=''/>
</body>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
0

The #{} in template text is indeed not allowed in legacy JSP, but only in its successor Facelets.

If you can guarantee that the managed bean is already created and present in the scope at that point (e.g. by having a JSF component referencing the very same managed bean before the <embed> tag), then you can just use ${} to access it, which is allowed in template text in JSP. The key point is that the ${} will not autocreate the managed bean when it's not present in the scope yet, but it can access its properties without trouble.

<h:someComponent ... value="#{cep_TBModelBean.someProperty}" />

...

<embed name='costsProject' src='CostsOfProject.swf' height='800%' width='600%'
    pluginspage='http://www.adobe.com/go/getflashplayer'
    flashVars='projectId=${cep_TBModelBean.projectId}'/>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555