How to initialize

I am working on this JSP page (modifying from Servlet), and I need to initialize "item".
item is located where it indicates
CatalogItem item;
I believe I need to indicate this public class called "Catalog" (on the bottom).
How do I go about doing this?
Thank you for your feedback.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="coreservlets.*"%>
<%@page import="java.io.*" %>
<%@page import="javax.servlet.*" %>
<%@page import="javax.servlet.http.*" %>
/// Private Methods
<%!
    private CatalogItem[] items;
    private String[] itemIDs;
    private String title;
%>
<%
    if (items == null) {
      response.sendError(response.SC_NOT_FOUND,
                         "Missing Items.");
      return;
    response.setContentType("text/html");
    String docType =
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
      "Transitional//EN\">\n";
    out.println(docType +
                "<HTML>\n" +
                "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
                "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
    CatalogItem item;
    for(int i=0; i<items.length; i++)
      out.println("<HR>");
      item = items;
if (item == null) {
out.println("<FONT COLOR=\"RED\">" +
"Unknown item ID " + itemIDs[i] +
"</FONT>");
} else
out.println();
String formURL =
"/mseku9_proj/Cart.jsp";
formURL = response.encodeURL(formURL);
out.println
("<FORM ACTION=\"" + formURL + "\">\n" +
"<INPUT TYPE=\"HIDDEN\" NAME=\"itemID\" " +
" VALUE=\"" + item.getItemID() + "\">\n" +
"<H2>" + item.getShortDescription() +
" ($" + item.getCost() + ")</H2>\n" +
item.getLongDescription() + "\n" +
"<P>\n<CENTER>\n" +
"<INPUT TYPE=\"SUBMIT\" " +
"VALUE=\"Add to Shopping Cart\">\n" +
"</CENTER>\n<P>\n</FORM>");
%>
public class Catalog {
// This would come from a database in real life.
// We use a static table for ease of testing and deployment.
// See JDBC chapters for info on using databases in
// servlets and JSP pages.
private static CatalogItem[] items =
{ new CatalogItem
("hall001",
"<I>Core Servlets and JavaServer Pages " +
"2nd Edition</I> (Volume 1)" +
" by Marty Hall and Larry Brown",
"The definitive reference on servlets " +
"and JSP from Prentice Hall and \n" +
"Sun Microsystems Press.<P>Nominated for " +
"the Nobel Prize in Literature.",
39.95),};
public static CatalogItem getItem(String itemID) {
CatalogItem item;
if (itemID == null) {
return(null);
for(int i=0; i<items.length; i++) {
item = items;
if (itemID.equals(item.getItemID())) {
return(item);
return(null);
}> 

There is also this class (I believe it does all the functions)..
How do I incorporate all together to initialize "item" at the JSP?
Thanks.
public class CatalogItem {
  private String itemID;
  private String shortDescription;
  private String longDescription;
  private double cost;
  public CatalogItem(String itemID, String shortDescription,
                     String longDescription, double cost) {
    setItemID(itemID);
    setShortDescription(shortDescription);
    setLongDescription(longDescription);
    setCost(cost);
  public String getItemID() {
    return(itemID);
  protected void setItemID(String itemID) {
    this.itemID = itemID;
  public String getShortDescription() {
    return(shortDescription);
  protected void setShortDescription(String shortDescription) {
    this.shortDescription = shortDescription;
  public String getLongDescription() {
    return(longDescription);
  protected void setLongDescription(String longDescription) {
    this.longDescription = longDescription;
  public double getCost() {
    return(cost);
  protected void setCost(double cost) {
    this.cost = cost;
}

Similar Messages

  • How to initialize a Type Object??

    Hi,
    I have a procedure as below, which has type t_r_rep_data and a table having this type as record, but when I called this procedure, it has ORA-06530 error: Reference to uninitialized composite. Can you tell me how to initialize a type Object?
    Also, is it this the right way to insert a type record into the table, or can I just just INSERT statement?
    Many thanks
    PROCEDURE add_row
    ( in_row_type_ind CHAR,
    in_ordering VARCHAR2
    ,in_record_type VARCHAR2
    ,in_level1_value VARCHAR2
    ,in_level1_description VARCHAR2
    ,in_level2_value VARCHAR2
    ,in_level2_description VARCHAR2
    ,in_level3_value VARCHAR2
    ,in_level3_description VARCHAR2
    ,in_level4_value VARCHAR2
    ,in_level4_description VARCHAR2
    ,in_amount_as_of_date1 NUMBER
    ,in_amount_as_of_date2 NUMBER
    ,io_table IN OUT t_ntr_rep_data
    IS
    l_row_count NUMBER;
    l_row t_r_rep_data;
    BEGIN
    -- ??? not sure where and how to do the initialization bit
    l_row.row_type_ind := NULL;
    l_row.ordering := NULL;
    l_row.record_type := NULL;
    l_row.level1_value := NULL;
    l_row.level1_description := NULL;
    l_row.level2_value := NULL;
    l_row.level2_description := NULL;
    l_row.level3_value := NULL;
    l_row.level3_description := NULL;
    l_row.level4_value := NULL;
    l_row.level4_description := NULL;
    l_row.amount_as_of_date1 := 0;
    l_row.amount_as_of_date2 := 0;
    SELECT COUNT(*)
    INTO l_row_count
    FROM (TABLE(CAST(io_table AS t_ntr_rep_data)));
    l_row.row_type_ind := in_row_type_ind;
    l_row.ordering := in_ordering;
    l_row.record_type := in_record_type;
    l_row.level1_value := in_level1_value;
    l_row.level1_description := in_level1_description;
    l_row.level2_value := in_level2_value;
    l_row.level2_description := in_level2_description;
    l_row.level3_value := in_level3_value;
    l_row.level3_description := in_level3_description;
    l_row.level4_value := in_level4_value;
    l_row.level4_description := in_level4_description;
    l_row.amount_as_of_date1 := in_amount_as_of_date1;
    l_row.amount_as_of_date2 := in_amount_as_of_date2;
    io_table(l_row_count+1) := l_row;
    END;
    --------------------------------------------------

    Simply write a stud which queries the Oracle Dictionary tables which will return Object Type
    Based on the object_name and User_name

  • How to Initialize a workflow from Application using CIS

    Hi,
    I am new to the (Stellent) UCM, And could not find a way to initialize a workflow from CIS, Someone's help is greatly appreciated.
    All i can find in forums about the workflow with in the Stellent Interface. But No one talking about how to initialize or call a workflow and use it from the application perspective.
    Your help is greatly appreciated.
    Thanks In Advance.

    CIS is one of the UCM Java API sets that you can use to connect WCI with the content server - it is on the WCI side of the fence, technically, but help can be found all over.
    If you call the checkin service - typically I use CHECKIN_UNIVERSAL, which is also the service that gets invoked by the ISCSDocumentCheckinAPI checkinFileStream(...) service. If the metadata matches something that triggers the workflow, you will have an item in the workflow queue.
    Be warned - from what I understand, the CPS portlets used a checkin API that does not trigger workflow, even if there is a matching criteria.

  • H:inputText ; How To initialize value Property from back/bean method?

    Hello Guys at Sun Forums.
    I am a newbie at using JSF. and I'm having a bit of a Problem.
    I don't know how to initialize the value property of a h:inputText from a method inside a backing bean that returns a String data type.
    My Method inside the Backing bean is this:
    public String getLastDate()
            Connection con = null;
            Statement stmt = null;
            ResultSet rs = null;
            Date DateCapt = null;
            String DateConv= null;
            try{
                Class.forName("com.sybase.jdbc2.jdbc.SybDrive").newInstance();
                con = DriverManager.getConnection("jdbc:sybase:Tds:localhost/BAN_PRO_SNP", "xxxx", "xxxx");
                if(!con.isClosed()){
                    stmt = con.createStatement();
                    stmt.executeQuery ("SELECT TOP 1 CONVERT(VARCHAR(10), fec_parametro, 103) fec_parametro FROM snp_sei_parametros" +
                    "     WHERE cod_parametro = 'FECHA'" +
                    "     ORDER BY fec_parametro DESC");
                    rs = stmt.getResultSet();
                    while (rs.next())
                                DateCapt = rs.getDate("fec_parametro");
                rs.close();  
                stmt.close(); 
            catch (Exception ex)
                        System.out.println("COULD NOT LOAD THE DRIVER!!!!");
                        System.out.println(ex);
                    DateConv = String.valueOf(DateCapt).toString();
        return DateConv;
    }As you can see the Method returns a String data type, and all I want to know is how put that returned String as the initial value of a h:inputText. when the jsf-jsp page loads.
    Please Help Me.

    You should be able to do
       <h:inputText value="#{bean.lastDate}"/>Where 'bean' is the managed bean name containing
    the method getLastDate().
    When the view is rendered, the getter (getLastDate())
    will be called to display whatever value is returned.

  • How to initialize an adf component before a page loads

    Hi all
    I use JDeveloper 11.1.2.2.0
    I have two pages:
    first page has a link to a second page
    <af:document title="first.jspx" id="d1">
      <af:form id="f1">
        <af:commandLink text="Page 2" id="cl1" action="goToSecondPage" actionListener="#{Bean.handleLinkActionEvent}"/>
      </af:form>
    </af:document>and the second page has an inputText component:
    <af:document title="second.jspx" id="d1">
      <af:form id="f1">
        <af:inputText label="Text" id="it1" binding="#{Bean.inputText}" readOnly="true"/>
      </af:form>
    </af:document>First I load first.jspx and than I click the link. This event is handled in handleLinkActionEvent() method, in which I want to set a value to the inputText component of the second page. But I can't do it, because as expected I get NullPointerException.
    So the question is how to initialize an adf component before a page loads?
    Evgeny Michuk
    Edited by: Evgeny Michuk on Oct 4, 2012 11:30 PM

    Thanks a lot for your replies and links, it gives me some new knowledges.
    I got your approach and achieved the aim for the described situation with tag <f:setPropertyActionListener>:
    <af:commandLink text="Page 2" id="cl1" action="goToSecondPage"
                           actionListener="#{Bean.handleLinkActionEvent}" binding="#{Bean.firstPageLink}">
      <f:setPropertyActionListener target="#{pageFlowScope.text}" value="Hello, World!"/>
    </af:commandLink>and for the inputText component I set the value:
    <af:inputText label="Text" id="it1"  binding="#{Bean.inputText}"
                                  readOnly="true" value="#{pageFlowScope.text}"/>I used request scoped managed bean and it is shared for both pages.
    I understand that I can set a value of some attribute for managed bean
    and use it to set a value for inputText component of the second page,
    but as I understand it is almost the same way as usage of tag <f:setPropertyActionListener>.
    In my real situation on the second page I have a dynamic table, and it's field is read only.
    Structure of this table depends on a link clicked on the first page.
    So I define components for table columns in runtime, it may be outputText, inputDate, goLink and some others.
    And I have to get table through the UIComponent binding to set columns.
    Certainly I can define all needed components for all columns
    and render it according to the column types
    <af:table value="#{Bean.collectionModel}" var="row" id="t1" binding="#{Bean.mainTable}">
       <af:forEach items="#{Bean.columnDescriptionList}" var="column">
          <af:column headerText="#{column.caption}" id="c1">
             <af:outputText value="#{row[column.fieldName]}" id="ot1" rendered="#{column.type == '1'}"/>
             <af:inputDate value="#{row[column.fieldName]}" id="ot2" rendered="#{column.type == '2'}"/>
             <af:selectBooleanCheckbox id="sbc1" selected="#{row[column.fieldName] == '1'}" rendered="#{column.type == 'n'}"/>
          </af:column>
       </af:forEach>
    </af:table>but I think it is not very good.
    Have you any idea?
    P.S. I hope I clearly explained my situation =)
    Evgeny Michuk

  • How to initialize the jndi context?

    Hello!
    install the j2ee sdk 1.4 on a server that has the ip address 211.83.144.48.
    then I deploy a EJB ,but I want to call the method from another pc.
    The problem is that how I initialize the jndi context? How can get the url for "Context.PROVIDER_URL"?
    thks.

    You need to look document of the application server that u are using.
    Because this depends on application servers.

  • How to initialize the array of hashmap???

    how to initialize the array of hashmap??

    What do you mean by "the array of hashmap"?

  • How to initialize the Sample app in Planning 11.1.2.2

    Hi,
    After creating the sample application in Planning 11.1.2.2, how to initialize it.

    log into the application, Administration > Application > Manage applications
    Select the application, click Action > Initialization.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How to initialize the new internal hard disk in LapTop ?

    Folks,
    Hello.
    My LapTop model is HP Pavilion dv4-2045dx entertainment notebook whose host operating system is Windows 7.
    Because the current hard disk capacity is not enough, I need to replace it with a new hard disk with bigger capacity.
    After take out the old hard disk and install "750 GB 7200 rpm Western Digital Scorpio Black 9 mm internal hard drive" into my LapTop, how to initialize the new hard disk ? What is the host Operating System for the new hard disk ?

    Please see the answer in your other thread.
    Which external hard drive supports Oracle Linux 5 on top of VMPlayer ?

  • How to initialize Button Array at "declaration"?

    How to initialize Button Array at "declaration"?
    Button[] b = new Button[2];
    b[0] = "label" ?
    b[1] = "label" ?
    Again,please at declaration not using setText within main program.

    main...
    Button[] btts = {new Button(...),new Button(...), ...)
    that shold be it
                                                                                                                                                                                   

  • How to initialize variable? (ArrayList String [])

    How to initialize this variable correctly, without getting a type safety warning?
    ArrayList<String>[] var = ?
    Thanks & Best regards,
    Kristian
    Message was edited by:
    Kriskra

    I need to use an array in this case... Thanks for
    your advice anyway...And the answer still is arrays and generics don't mix so your request is impossible without ignoring the warning.
    Try@SuppressWarnings("unchecked")
    ArrayList<String>[] var = new ArrayList[10];

  • How to initialize a field-symbols?

    I have field-symbols structure <wa1>, <wa2>.
    1. Supposed <wa1> has been assined value already, how can I copy content of <wa1> to <wa2>?
    2. How to initialize <wa2>?
    Thanks!

    Hi,
    Check this example..
    field-symbols: <fs1>, <fs2>.
    data: v_var1(10), v_var2(10).
    v_var1 = 'ABC'.
    v_var2 = 'DEF'.
    assign v_var1 to <fs1>.
    assign v_var2 to <fs2>.
    write: / 'BEFORE...'.
    write: / '<FS1> - ', <FS1>.
    write: / '<FS2> - ', <FS2>.
    <FS1> = <FS2>.
    write: / 'AFTER...'.
    write: / '<FS1> - ', <FS1>.
    write: / '<FS2> - ', <FS2>.
    CLEAR: <FS2>.
    write: / 'AFTER CLEAR...'.
    write: / '<FS1> - ', <FS1>.
    write: / '<FS2> - ', <FS2>.
    Thanks,
    Naren

  • How to initialize delta for a new data target

    Hi
    I have an ODS from which there are several other targets getting updated thru an export datasource. The delta initialization happend some 6 months back. I now have a new ODS into which i need to load the data from the original  ODS. How can i initialise the delta to my new target without changing the delta initialization of the other targets and continue the delta for all of them together?
    can i use the same initialization for my new target??
    If i do a full update and then a initialise w/o data transfer, will the further delta bring the data from the correct point, is there a possiblity of data loss??
    Regards,
    Sujai

    Hi Ajay,
    the steps are as follows.
    1 delete the initialization. open infopackage >> menu scheduler >> Initialization options for source systems >> delete the request thats there.
    2. Now go to the Update tab of the infopack >> select option Initialize Delta process >> check the option initialize without Data transfer
    3. Goto Schedule tab and start the job.
    here the data targets will be all the targets the infopack loads.
    4. Create a new infopack
    5. goto Data targets tab >> select data targets >> put a check on your new ODS/Cube
    6. Goto Update tab >> select the option Full update
    7. goto menu Scheduler >> select Repair full request >> put a check on Indicate request as Repair Request >> hit OK
    8. Goto schedule tab >> start the job.
    9. Continue with the existing Delta infopack that was load the old ODS/Cubes  and make sure your new ODS/Cube is also cheked for the delta.
    Regards
    Sujai

  • How to Initialize Container Element in BPM..No Payload found

    Hi All,
    How do we initialize a container element in BPM if that container element is a message Interface.
    I am doing exception handling in BPM, so whenever a exception occurs i need to send a mail.
    So in the exception box i have a transformation step and a send step.
    In the transformation step what will be my source message?
    How do i initialize that source message?
    What i have done right now is created a dummy interface(abs) for source and then mapped with the target abs interface.
    When i execute the schenario,in the monitor i find in the Transformation step the following error
    <i>No payload found.</i>
    Regards,
    Sumit

    Hi Pinto,
    I too agreee. Lemme try to explain witha example.
    In my first transformation, MI_MAIL_TEMP_ABS is there along with 3 other interfaces. Each one is getting mapped i can see that in monitoring.
    Now in the exception branch in transformation step,
    i am mapping MI_MAIL_TEMP_ABS to MI_MAIL_ABS.
    Now in the send step im giving MI_MAIL_ABS as the interface name.
    Do you see anything wrong with this?
    <i>>>>>>>>Did you try to do outbound interface -> inbound interface mapping in the exception branch? Just to try to make your scenario work. Then you can investigate further on why the abs message is not being carried away.</i>
    Which outbound interface & inbound are you talking about?
    Regards,
    Sumit
    Message was edited by: Sumit Khetawat

  • How to initialize Datamining Model in process chain ?

    Hello all,
    I need to launch an APD for datamining analysis but i need to initialize the model before each data loading.
    The only way to initialize the model is to write an abap program ?
    No standard process, report or transaction to schedule this step using a process chain ?
    Thanks
    Christophe

    The solution is to use a specific ABAP program using the method RESET_MODEL_RESULTS
    You'll find BW-APD How to Reset a Data Mining Model" in the wiki
    Christophe

  • How to initialize form items?

    Hi,
    I need to create popup window with several forms. As it's popup I don't add it to any component - just create it with "new" operator. The problem is that all popup window's childern are null until I add window to some component. I found out that there is initialize() function that should create all window's children and it does but only childern that are not form's childern.
    In exaple below saveButton and cancelButton will be created after window.initialize() but addPhotosButton not.
    <s:Panel>
         <s:VGroup>
              <mx:Form>
                   <mx:FormItem >
                        <s:Button id="addPhotosButton" />
                   </mx:FormItem>
                </mx:Form>
              <s:Button id="saveButton" />
              <s:Button id="cancelButton" />
         </s:VGroup>
    </s:Panel>
    I need to have all window's children created without adding it but dunno how...
    Could anyone help me, please?

    Since you use MXML file for implementing your form, Flex compiler generates AS3 code which follows normal component lifecyle rules: that is all components are created in createChildren() method when you add the component to the display list. One way to get around this is to implement your form in pure AS3 and create all stuff in the constructor.
    The better approach would be to create isntance of the component, add event listener for CREATION_COMPLETE (you could also use INITIALIZE) event, add your component to the display list. When you receive the event, it is safe to do whatever you need with that component and its children.

Maybe you are looking for

  • Error in creating create Consumer proxy:

    Hi all ,                 while creating create Consumer proxy: in SE80 ,by giving the URL of the webservice i am getitng a error which is Exception occurred in communication framework:Error in HTTP Framework:404conn failedhttp, i am new to this SOA,

  • Empty file picked although file have lot of data in file adapter SAP PI

    Hello All, We are facing the weired behaviour of SAP PI file adapter channel. In without mapping Scenario of 7.31 At some time whole file is archived properly in archive folder but in SAP PI log we can see the file size 0 bytes. And at received side

  • Inventory Management, New Snapshot Scenario

    We are planning to implement the New Snapshot scenario for Inventory Management. This is based on the "How to...." document. As per what is shown in the document, all the 3 extractors feed into the same DSO. However, when I try to create the Update R

  • Probem to adding JCombo in HTable(UTGENT)

    Hello, i want to add jcombo in jtable.accually in my table i add column in run time & every column when i add (evry cell) want to combo. but problem is when i add column that time last column i find every cell have combo,but previous column i lost co

  • Yahoo finance displays futures prices all day, rather than real mrkt prices

    Yahoo finance Dow, S&P, Nasdaq do not show accurate prices on their indeces. This has always been correct for the last 15 yrs