Beans initialzation using scriplet variable

In the initialisation code , I tried to set up a bean variable which is
          essentially a database connection (java.sql.Connection)... jsp does not
          like it . My code is as follow :
          I already have variable "conn" defined and set in the scrplet. My goal
          is to initialize the bean in such a way that it will go to database and
          fetch the particular patient data using "conn" and patientID.
          <jsp:useBean id="Patient" class="papjsp.databases.PatientBean">
          <jsp:setProperty name="Patient" property="patientId" value =
          patientId />
          <jsp:setProperty name="Patient" property="conn" value = conn />
          </jsp:useBean>
          I get ClassCastException .
          Thanks
          

Try to define your setProperty like this:
          <jsp:useBean id="Patient" class="papjsp.databases.PatientBean">
          <jsp:setProperty name="Patient" property="patientId" value =
          "<%=patientId%>" />
          <jsp:setProperty name="Patient" property="conn" value = "<%=conn%>" />
          </jsp:useBean>
          Cheers
          Sonia WEN
          Chiranjib Misra wrote:
          > In the initialisation code , I tried to set up a bean variable which is
          > essentially a database connection (java.sql.Connection)... jsp does not
          > like it . My code is as follow :
          > I already have variable "conn" defined and set in the scrplet. My goal
          > is to initialize the bean in such a way that it will go to database and
          > fetch the particular patient data using "conn" and patientID.
          >
          > <jsp:useBean id="Patient" class="papjsp.databases.PatientBean">
          > <jsp:setProperty name="Patient" property="patientId" value =
          > patientId />
          > <jsp:setProperty name="Patient" property="conn" value = conn />
          > </jsp:useBean>
          >
          > I get ClassCastException .
          >
          > Thanks
          

Similar Messages

  • Using EL variable in struts bean:message tag(not struts EL tag)

    Is there any work around to use an EL variable inside struts bean:message tag as key:
    I have like this:
    <bean:message key="${bean.keyName}"/>
    which is throwing error , I know this can be resolved by using struts-el tags but i cannot use them for specific reasons.
    I dont want to use bean:define tag to define my 'bean' and then use like this:
    <bean:message key="<%=bean.getKeyName%>"/> (this actually works, but i want to use EL variable)
    Is there any work around to use EL variable and make the message display on the jsp.
    i tried multiple ways like scriplets and jsp:useBean but nothing worked, Please let me know..
    Thanks in advance

    Im pretty sure that EL does not work in the normal struts tag unless its struts-el tag.Have you tried it?
    As I said, in a properly configured JSP2.0 container you can use EL expressions anywhere you could traditionally use a standard runtime expression <%= expr %>.
    What server are you using? What JSP version?
    The Struts-el tags were written so that you could use EL with struts in JSP1.2 containers.
    The c_rt tags were written so you could use runtime expressions with JSTL tags in JSP1.2 containers. Their use was discouraged even then. Now I consider their use absolutely unnecessary.
    Please read this thread: http://forum.java.sun.com/thread.jspa?threadID=629437&tstart=0
    Cheers,
    evnafets

  • How to default bind variable using session variable at run time

    Hi All,
    I have a requirement where all VO queries (multiple VOs) produce only records that meet a certain value.
    For example, I have three tables with 3 VOs and each of them has a one-to-many relationship to another table (let's call it ref table and this table has a field called release). One of the 3 VOs is a parent/master table, and the other two are child tables. I created a VO for master table that linked to the ref table and created a view criteria using the release (use bind variable) field from the ref table. The other child tables have their own VO that has view criteria that also linked to ref table using the release field.
    On the UI page, I created a query component and a table from the master table VO. I also dropped the child table VOs in a tabbed panel which partial triggered by the master table. When I ran a query for a 'release' (hint: ref table value), the table for master table was filled the correct records that meet the criteria. Unfortunately, the child tables were not correct due to the query didn't use the bind variable that filter only records for the same 'release' value as the master table.
    The question is how do I 'default' or dynamically set the bind variable on the child tables based on the selection criteria from the query component. I am thinking to set a session variable from the query and use it in the bind variable in the child table, but not sure how to do it.
    Any suggestion how to do it or better solution to achieve the same effect?

    Hi,
    How about creating a custom AMImpl method, that takes parameters as required, and set the bind variables for all the desired VOs and perform executeQuery on them.
    You could expose this as client interface, and then use the method as parameter form.
    Check this thread for ex.
    Re: Setting Attribute in View Object through Managed Bean
    -Arun

  • Using JSTL variables in JSP or Javascript. Possible ?

    Hi All,
    Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script.
    Example:
    This Works:
    <fmt:set var="test" value="JSTL" />
    <fmt:out value="${test}" />
    But, this gives error:
    <% out.println(test) %>
    And passing the value of variable 'test' to Java Script code also gives error.
    How to use JSTL variables in JSP and in Javascript ?
    Yours,
    Sankar.B

    By default, JSTL variables are kept in servlet
    attributes. Default is to store it in the page
    context. You can make it request/session/application
    scope as required by an attribute of the set tag.Hi there,
    Can anyone advise how to access JSP variables in JSTL?
    Can it be done as the same method through request/session/application scope?
    Thnks...

  • Can I use static variable in EJB?

    Many books suggest developer don't use static variable in EJB,I want to know why?
    I know there isn't any problem if the static varibale is read only
    For writable static varible ,what will happen if I use a static Hashtable for share data
    Help me!Thank you very much!!

    Greetings,
    I know that "EJB business methods are not allowed to
    block on synchronized resources" Just where do you "know" that from?? The EJB 2.0 Specification, at least, is nowhere in agrement with this statement. If it comes from a book I would question the author's reasoning. Contractually, there's no sound basis for this. In the case of Session Beans, they have an expressedly direct and single-threaded association with a client. From a design viewpoint, it certainly seems unnecessary for a bean to "block" its one-and-only client, but to say that it "is not allowed to" do so is without merit. Entity Beans, on the other hand, are concurrently accessible. Yet, with regard to a transactional context being in effect, the container does indeed block on a bean's business methods. For the bean to do so itself is, therefore, unnecessary. Furthermore, the specification explicitly concedes that a "Bean Provider is typically an application domain expert" and "is not required to be an expert at system-level programming." (EJB 2.0 Spec. 3.1.1) From these statements alone it is reasonable to assume the above statement is meritless since the Bean Provider is not expected to even consider synchronization issues when developing a bean.
    But I'm mixed up why we could use "Hashtable" or otherApparently, because your sources are as well...
    collection classes in the EJB ,in these method many
    methods are synchronized In fact, not only "can we use" them but, with respect to multiple-row finders in Entity Beans we are [i]required to use them (or an iteration of them)! Not all Collection classes are synchronized (so called "heavy-weight collections"). As shown above, that the choice of a particular Collection class might be synchronized is of little consequence since a bean designed under strict adherence to the specification ensures that it is never concurrently writeable.
    Could someone provide a good way for this problem?
    Please Help Me!!!Regards,
    Tony "Vee Schade" Cook

  • Sorting an Array using two variables

    Hi,
    I has an ArrayList of objects that have two variables that need to be used to sort the ArrayList.
    Sorting using one variable is fine, but how do I sort once using both variables?
    any ideas would be great
    tks
    Phill

    I have to do this a lot, so I came up with a more reusable solution. I have two Compatator classes, one that permits me to compare two objects based upon a bean property value. Another lets me chain two Comparator objects together. So I create two of the bean comparators and chain them together. Similar code exists in the Jakarta Commons Lang project.

  • JSP/BC4J app: How to get view object row data into a scriplet variable?

    I have a JSP application using BC4J data tags. Within a rowsetiterate tag, how can I get the data value of an attribute for the current row into a scriplet variable?
    Thanks,
    Steve

    Using the <jbo:Row> tag like this:
      <jbo:RowsetIterate .... >
        <%--
         | Establish a scriptable variable "curRow" for the current row
         +-->
        <jbo:Row id="curRow" action="current"/>
        <%
          String foo = (String)curRow.getAttribute("YourAttrName");
        %>

  • Using a variable in communication channel

    Hi,
    I have a lot of Communication Channels looking for files in the same directory. This directory's path will be changed soon and so I assume I'll have to change all my Communication Channels.
    I was wondering whether there was a means of using a variable for the Source Directory in order to just have to change its value where it is defined and not every where it is used...
    Regards
    Yann

    Hi,
    Is this a sender file adapter? or a receiver file adapter?
    You can make a change / make the receiver file adapter's directory dynamic by setting the value during runtime in the mapping.
    Use  this blog and the code in the blog to acheive this,
    /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
    Sender File adapter, I dont think this is possible.
    Regards,
    Bhavesh

  • Error in using System Variable

    Dear all,
             I want to use System Variable 225 ( VAT percent (per VAT code) ) which is used in one of document i.e. "VAT Only Invoice".
    When I used it in my Invoice document the following error occurs:
    Printing Error : Invalid Variable number (RPT -6300)(Field:F_XXX) Variable 'XXX'
    Please help me to use this System Variable in my Invoice.
    Note: I have already read "How To Use the PLD Variables File in Release 2007 A" .pdf file.
    can any one tell the meaning of folowing which is in the sheet "vars utilisation" of PLD_Vars_march2007 xls file
    " it means that this variable can be used only under certain repetitive area exclusive numbers (109, 126, 132, 135, 139, 148, 149, 309, 316, 427, 502, 509, 686)
    Regards,
    Ghazanfar
    Edited by: Ghazanfar Ahmed on Jun 18, 2009 12:16 PM

    Hi,
    It is a special variable available for the VAT summary part, not to be used in the rows but in a separate repetitive area.
    To display the respective VAT rates in each row, create a database field instead: Tax Definition - Rate%. It will populate the VAT percentage for you.
    Regards,
    Nat

  • Error in using a variable in filter condition in an Interface

    Hi All,
    I am using a variable in my interface in a filter condition. I have an EMP table of scott schema and want to pull all the records wiht hiredate date lying between 2 dates, incremental pull.For this I have created 2 variables and using them in the filter condition. I am getting an error inthe interface when I run in a package after declaring and refresing the variables.
    com.sunopsis.sql.SnpsMissingParametersException: Missing parameter
         at com.sunopsis.sql.SnpsQuery.completeHostVariable(SnpsQuery.java)
         at com.sunopsis.sql.SnpsQuery.updateExecStatement(SnpsQuery.java)
         at com.sunopsis.sql.SnpsQuery.executeUpdate(SnpsQuery.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execStdOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.g.y(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)
    Regards,
    Krishna

    Hi Krishna,
    What is the datatype of the Variable lastupdate ?
    In my case
    Variable
    Name : LastUpdateDate
    Datatype : Alphanumeric
    Action : Historize
    Query : select to_char(to_date(sysdate,'DD-MON-YY'),'DD-MON-YY') from sys.dual
    Then in filter I used
    EMP.HIREDATE>to_date('#LastUpdateDate','DD-MON-YY')
    Thanks
    Sutirtha

  • Using a variable as a value in jsp:param

    I was wondering, I have a String variable, vid_1, and want to use a jsp:include and pass that in as one of the parameters. How can I do this? I have to do some testing to make sure vid_1 is valid and set a default if not. It contains a number referring to which video needs to be displayed.
    Is there anyway I can get this value to be used in jsp:param value?
    John

    RahulSharna wrote:
    Well,First thing you haven't pharsed your question properly.
    Anyways as per my understading.
    The first thing is make use of in this case as your defined requirement states you need to make use of variables of both the JSP's which need compile time include not at the runtime.use of
    <%@ include file="url" %>would be more appropriate as you want to use the variable of parent jsp to the child one.
    Anyways if you are thinking to apply a solution using <jsp:include/>
    <jsp:include page="url">
    <jsp:param name="paramName" value="<%=stringVariable>"/>
    </jsp:include>and extract the paramName's corresponding value as a request parameter in other JSP.
    Hope that might answer your question :)
    REGARDS,
    RaHuLRaHul,
    Thanks for the reply. The second example you gave is what I was trying to do. I thought I did exactly what you have there and it was not working. I will check it over again and post back on here when I have a chance.
    For now I was trying to use c:set to save the variable in the request and then using the EL expression ${requestScope.variable} to put it in the <jsp:param> element. I had some things working and others not when I quit. Hopefully tomorrow I can give you a full report and we can get this worked out.
    Maybe my problem is something else? Look at this post of mine:
    http://forum.java.sun.com/thread.jspa?threadID=5236252&tstart=10
    Thanks so much for the help.
    John

  • Using a variable in netsh command to set ip address on NIC

    hi friends
    i wrote an script which gets an input & use that variable to set ip address on NIC. but actually it doesn't set ip address. may you please help me.
    my script contains:
    $VMNumber=Read-Host "please enter your VM number (for example 2)"
    Netsh interface ipv4 set address NIC static 192.168.1.$VMNumber

    1. I do not thing that the use of netsh is a right way.
    2. You will need a table with MAC address in first column and IP address in second to correctly map IP address to computer. MAC addresses are unique identification.
    3. Follow this article including comments and adapt scripts to your task
    http://www.powershellpro.com/powershell-tutorial-introduction/powershell-wmi-methods/
    HTH
    Milos
    hi Milos
    thank a lot for your useful answer.
    but let me say that my need has nothing to do with MAC address.
    in my test lab, i need an script which asks the administrators to enter their VM number & it saves this input as a variable & set is as the last octet in their VM IPV4 Address.
    so can we tell it as a rule that variables we create in powershell, can't be used inside non cmdlets (inside legacy cmd commands) ?

  • Using a variable in a js function argument

    Folks,
    This is very basic, but I still cannot get it...
    I have this js function in an ASP page:function MM_changeProp(objId,x,theProp,theValue) { //v9.0
      var obj = null; with (document){ if (getElementById)
      obj = getElementById(objId); }
      if (obj){
        if (theValue == true || theValue == false)
          eval("obj.style."+theProp+"="+theValue);
        else eval("obj.style."+theProp+"='"+theValue+"'");
    }i don't understand the function, as it was put in automatically by dreamweaver. right now, i am using this onclick event of an image:<div id="apDiv19" onclick="MM_changeProp('apDiv7','','backgroundColor','#FFFF00','DIV')"></div>the #FFFF00 is the color YELLOW. it is being passed to the theValue argument of the js. what i simply want to do is establish a global variable that will house a color string (like #FFFF00), and then use it in the function argument everytime i need the function. something like this:<div id="apDiv19" onclick="MM_changeProp('apDiv7','','backgroundColor',VARIABLE,'DIV')">i do not know how to do two things:
    1) initialize and assign the variable a value, and where to establish it (inside the script tags? in the head? in the body?)
    2) how to use the variable as an argument in the function
    any help greatly appreciated for this novice. thanks!

    ajetrumpet wrote:
    Folks,
    This is very basic, but I still cannot get it...
    I have this js function in an ASP page:This forum is not about ASP nor JavaScript. Please use Google to find an appropriate JavaScript forum.

  • Using a variable in an instance name

    Hey all,
    Simple question:
    I'm trying to use a variable to call on different instance names:
    var picCaller:uint=2;
    material_mc.addChild(pic_""+picCaller+"");
    The code in red is the issue in question.  In this example, I'm trying to add a child called "pic_2", with the number two called from the variable "picCaller"
    Any assistance is greatly appreciated.
    Thanks!

    Just for context, here is what I'm trying to do:
    I have jpegs in my library and I want to add them to the stage when they're needed, so just to add one image, here is the code I have:
    var pic_1=new pic1(0,0);
    var image_1:Bitmap=new Bitmap(pic_1);
    material_mc.addChild(image_1);
    I want to put the above into a loop so that I dont have to repeat those three lines for every image in my library like so:
    var pic_1=new pic1(0,0);
    var image_1:Bitmap=new Bitmap(pic_1);
    var pic_2=new pic2(0,0);
    var image_2:Bitmap=new Bitmap(pic_2);
    var pic_3=new pic3(0,0);
    var image_3:Bitmap=new Bitmap(pic_3);
    var pic_4=new pic4(0,0);
    var image_4:Bitmap=new Bitmap(pic_4);
    var pic_5=new pic5(0,0);
    var image_5:Bitmap=new Bitmap(pic_5);
    var pic_6=new pic6(0,0);
    var image_6:Bitmap=new Bitmap(pic_6);
    var pic_7=new pic7(0,0);
    var image_7:Bitmap=new Bitmap(pic_7);
    the variable "picNum" is the total amount of images that in the library, each one exported as "pic1", "pic2", "pic3" respectively.
    var picNum:uint=7;
    var picCaller:uint=1;
    var  picMC:MovieClip = new MovieClip();
    picMC=this["pic_"+picCaller];
    for (var  i:int = 1; i <= picNum; i=i+1)
         var "pic_"+i = new image_i(0,   0);
         var image:Bitmap = new Bitmap("pic_"+i);
    Thanks so much for your help.

  • Using a variable in SQL to store intermediate results

    I'm new to Crystal Reports, so pardon my ignorance.
    I need to write a SQL statement in Crystal Reports (Ver. 11) that uses results from a query and stores them in a variable for further use in the statement. Something like this:
    DECLARE @my_variable INT;
    SET @my_variable=
    CASE
                    WHEN DATEPART (m,{?Date})<7
                    THEN DATEPART (yyyy,( DATEADD (year,-1, {?Date})))
                    ELSE DATEPART (yyyy,( DATEADD (year,0, {?Date})))
    END
    (Where {?Date} is a date parameter)
    Is it possible to achieve this in the above form or some other form in Crystal Reports?
    Thanks

    Simple answer... When I used the variable, I marked it as a string.  There is an email address setting.

Maybe you are looking for

  • Upgrade to 5.0.2

    Dear Sony I am writing this in the very faint hope that someone at Sony might actually take notice of the feedback being provided by your customers.  It is a very faint hope indeed as Sony's track record in this space is extremely poor.  I am also po

  • Why is only my homepage showing up online and I get an "oops...page not found" error for everthing else?j

    I just setup my site in DW CS4 and upload local files to the remote server.  Why can I type in the homepage - www.ducksinaroworganizers.com - but all other files are "page not found".  I see them in DW in the remote folder side. Please help!

  • How to extract Chinese text from font embedded text PDF?

    This is actually font embedded text PDF (Used: type 1 fonts & custom encoding) and not scanned PDF, however I am unable to extract the "Chinese language" text properly and found only the garbled text when "Copy & Paste" (or save as RTF). Kindly refer

  • Blank external Monitor

    When I connect the laptop to an external Apple Monitor everything works except I get a blank screen. It goes into duo monitor mode and even gives me the preferences and the information in "about this Mac' but the display is blank. Ideas?

  • Anyone else notice on the mini player has 2 rewind buttons?

    When i pause the mouse over the iTunes block (windows 7) on the task bar, you can see the main iTunes window as well as what was always the back, pause/play and next buttons. I'm not sure when it started, but if you look at it, its got back, pause/pl