Accessing a jsp:usebean from javascript...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brice Laurencin

    #1

    Accessing a jsp:usebean from javascript...?

    My code is like that :

    <jsp:useBean id="vConf" type="cat.eur.t b.eleccard.data types.Config[]"
    scope="session" />
    <jsp:useBean id="equNo" type="java.lang .Integer" scope="session" />

    <script language="javas cript">
    function submit_form()
    {
    var equ = vConf[equNo].getEqu();
    (...)
    }

    The problem is that both vConf and equNo are not known. I tried with
    <%=...%>
    and it is still inaccessible.

    It is correct ? can I do it ? Where I am wrong ?
  • kaeli

    #2
    Re: Accessing a jsp:usebean from javascript...?

    In article <667582b1.04010 70451.20890db3@ posting.google. com>,
    brice_laurencin @yahoo.fr enlightened us with...[color=blue]
    > My code is like that :
    >
    > <jsp:useBean id="vConf" type="cat.eur.t b.eleccard.data types.Config[]"
    > scope="session" />
    > <jsp:useBean id="equNo" type="java.lang .Integer" scope="session" />
    >[/color]

    The bean is interpreted by the server (servlet engine). The browser sees
    no such thing. View the HTML source to see what the browser sees.
    Javascript, as you are using it, runs on the client, well after the
    server is done. It cannot call bean methods.
    [color=blue]
    > <script language="javas cript">
    > function submit_form()
    > {
    > var equ = vConf[equNo].getEqu();[/color]

    If you want the value of that method in a js variable, assign it at run
    time.
    var equ = <%= vConf[equNo].getEqu() %>;
    If the above method returns a string, put it in quotes.
    var equ = "<%= vConf[equNo].getEqu%>";

    The above assumes both beans are written properly and their methods
    return what is expected. If you aren't sure, ask in
    comp.lang.java. programmer

    --
    --
    ~kaeli~
    To steal ideas from one person is plagiarism; to steal from
    many is research.



    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Accessing a jsp:usebean from javascript...?

      Brice Laurencin wrote:
      [color=blue]
      > <jsp:useBean id="vConf" type="cat.eur.t b.eleccard.data types.Config[]"
      > scope="session" />
      > <jsp:useBean id="equNo" type="java.lang .Integer" scope="session" />
      >
      > <script language="javas cript">[/color]

      The "language" attribute is deprecated since
      HTML 4, but the "type" attribute is required:

      <script type="text/javascript">
      [color=blue]
      > function submit_form()
      > {
      > var equ = vConf[equNo].getEqu();
      > (...)
      > }
      > [...]
      >
      > It is correct ?[/color]

      No.
      [color=blue]
      > can I do it ?[/color]

      Possibly.
      [color=blue]
      > Where I am wrong ?[/color]

      You are using client-side JavaScript here. Client-side code cannot
      access server-side code (directly). JavaServer Pages generates content
      temporarily in the server's memory by replacing markup in the file
      (check out "view-source:") and sends that composed data to the client
      which interprets it. You can only access the *replaced* content with
      client-side scripting through the DOM of the UA, unless the server-side
      application provides an API for server-side JavaScript.


      PointedEars

      Comment

      Working...