0

I don't know if this is realizable, because i don't have strong knowledge in JavaScript.

I want to use Java variable in Javascript and XHTML code, i have a file path in java variable: applicationDadesVersioBB.rutaFitxerLog which i display as follows in XHTML page in a table as follows:

<tr>
  <th scope="row">#{literalsCore['Entorn.FitxerLog']}</th>
  <td>
     <a href="#{applicationDadesVersioBB.rutaFitxerLog}"  onClick="descarga([[${applicationDadesVersioBB.rutaFitxerLog}]])">#{applicationDadesVersioBB.rutaFitxerLog}</a>
  </td>
</tr>         

until now everything is fine, but what I want to do is once the path is clicked, the file should be downloaded, which i am not able to do with: onClick="descarga([[${applicationDadesVersioBB.rutaFitxerLog}]])

the JavaScript descarga function:

<script type="text/javascript">
    function descarga(file)
    {
        window.location=file;
    }
</script>

I think the problem I have is the conversion of java variable values to javascript values.

I tried to do it changing the onClick="descarga([[${applicationDadesVersioBB.rutaFitxerLog}]])" to onClick="descarga("#{applicationDadesVersioBB.rutaFitxerLog}")"

but no way, any help?

8
  • which i am not able to do with - why? what's the problem? Commented Jul 28, 2016 at 8:43
  • The file path is displayed correctly, but when i click it, i suppose it should calls the descarga function i have in my code to download the file, but it is not working, it does not download the file. Commented Jul 28, 2016 at 8:46
  • What is the definition of descarga ? Commented Jul 28, 2016 at 8:47
  • @AbdennourTOUMI do you mean its implementation ? Commented Jul 28, 2016 at 8:48
  • yes > >implementation Commented Jul 28, 2016 at 8:48

2 Answers 2

1

I'm not sure about what you're trying to do but I remeber a useful "hack" to do that in PHP for example... You have to create a hidden input in your HTML file and set its value to applicationDadesVersioBB.rutaFitxerLog. Then in your click handler you just get the input element thanks to its id for example and you read the value.

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

0

you need quotes around a string

onClick="descarga('[[${applicationDadesVersioBB.rutaFitxerLog}]]')"

4 Comments

i get this error: java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in path at index 20: 0.0.0.0//agd/[[C:Documentumlogslog4j.log]] at org.ocpsoft.urlbuilder.util.Decoder.path(Decoder.java:19) at org.ocpsoft.urlbuilder.AddressBuilder.pathEncoded(AddressBuilder.java:147) at org.ocpsoft.urlbuilder.AddressBuilderPort.pathEncoded(AddressBuilderPort.java:54) at org.ocpsoft.rewrite.servlet.impl.BaseHttpRewrite.getInboundAddress(BaseHttpRewrite.java:88) at org.ocpsoft.rewrite.servlet.impl.HttpInboundRewriteImpl.getAddress(HttpInboundRewriteImpl.java:
i suppose because it's a file i have localy and nor an URL right ?
Ehm... why do you need to download a file that you have locally already?
I have it localy because i am making tests localy before i display my application in a remote oracle weblogic server, then it will not be a local file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.