Results 1 to 4 of 4
  1. #1
    khanhnq is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default How can I export elements in array to .xhtml JSF

    Hi all,

    I'm working with simple project using JSF is: Brandi's Bagel House. Everything is OK. And now I want to present elements that the user choice like: Bagel, Topping, Coffee... onto Receipt.xhtml. But I don't know how to do because a data type of selectedToppingNames is an Array.
    Please help!

    Here is my code:

    Index.xhtml:

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
    <title>Brandi's Bagel House</title>
    </h:head>
    <h:body>
    <h2>Brandi's Bagel House</h2>
    <h:form prependId="false">
    <table>
    <tbody>
    <tr>
    <td>
    <fieldset>
    <legend>Bagel</legend>
    <h:selectOneRadio id="#{id.BAGEL}" layout="pageDirection" value="#{indexBean.selectedBagelName}"
    converter="#{bagelConverter}">
    <f:selectItems var="item" value="#{bagelFacade.findAllOrderById()}"
    itemLabel="#{item.items}"/>
    </h:selectOneRadio>
    </fieldset>
    </td>
    <td>
    <fieldset>
    <legend>Topping</legend>
    <h:selectManyCheckbox id="#{id.TOPPING}" layout="pageDirection" value="#{indexBean.selectedToppingNames}"
    converter="#{toppingConverter}">
    <f:selectItems var="item" value="#{toppingFacade.findAllOrderById()}"
    itemLabel="#{item.items}"/>
    </h:selectManyCheckbox>

    </fieldset>
    </td>
    <td>
    <fieldset>
    <legend>Coffee</legend>
    <h:selectOneRadio id="#{id.COFFEE}" layout="pageDirection" value="#{indexBean.selectedCoffeeName}"
    converter="#{coffeeConverter}">
    <f:selectItems var="item" value="#{coffeeFacade.findAllOrderById()}"
    itemLabel="#{item.category}"/>
    </h:selectOneRadio>
    </fieldset>
    </td>
    </tr>
    </tbody>
    </table>
    <div class="Button">
    <h:commandButton action="#{indexBean.compute()}" value="Compute"/>
    <h:commandButton action="#{indexBean.clear()}" value="Clear"/>
    </div>
    </h:form>
    </h:body>
    </html>



    IndexBean.java:
    package web;

    import com.sun.xml.rpc.processor.modeler.j2ee.xml.string;
    import data.entity.Bagel;
    import data.entity.Coffee;
    import data.entity.Topping;
    import data.service.SalesTaxFacade;
    import java.util.ArrayList;
    import java.util.List;
    import javax.ejb.EJB;
    import javax.inject.Named;
    import javax.enterprise.context.RequestScoped;

    @Named
    @RequestScoped
    public class IndexBean {

    private Double subtotal;
    private Bagel selectedBagelName;
    private Topping[] selectedToppingNames; (THIS IS A PROBLEM...)
    private Coffee selectedCoffeeName;
    private Double tax;
    private Double total;
    @EJB private SalesTaxFacade salesTaxFacade;

    public String compute() {

    subtotal = selectedBagelName.getVal() + computeTopping() + selectedCoffeeName.getPrices();
    tax = subtotal * salesTaxFacade.find();
    total = subtotal + tax;
    return "receipt";
    }

    public void clear() {
    selectedBagelName = null;
    selectedToppingNames = null;
    selectedCoffeeName = null;
    }

    //----------------------------------------------------------------------------
    public Bagel getSelectedBagelName() {
    return selectedBagelName;
    }

    public void setSelectedBagelName(Bagel selectedBagelName) {
    this.selectedBagelName = selectedBagelName;
    }

    public Coffee getSelectedCoffeeName() {
    return selectedCoffeeName;
    }

    public void setSelectedCoffeeName(Coffee selectedCoffeeName) {
    this.selectedCoffeeName = selectedCoffeeName;
    }

    public Double getSubtotal() {
    return subtotal;
    }

    public Double getTax() {
    return tax;
    }

    public Double getTotal() {
    return total;
    }

    public Topping[] getSelectedToppingNames() {
    return selectedToppingNames;
    }

    public void setSelectedToppingNames(Topping[] selectedToppingNames) {
    this.selectedToppingNames = selectedToppingNames;
    }

    private Double computeTopping() {
    double acc = 0.0;
    for (Topping eachName : selectedToppingNames) {
    acc += eachName.getVal();
    }
    return acc;
    }


    }

    Receipt.xhtml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    To change this template, choose Tools | Templates
    and open the template in the editor.
    -->
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <head>
    <title>Receipt</title>
    </head>
    <body>
    <h2>Receipt</h2>

    <h:panelGrid columns="3" columnClasses="rightAlign, null, null">
    Bagel :
    <hutputText value="#{indexBean.selectedBagelName.items}"/>
    <hutputText value="#{indexBean.selectedBagelName.val}">
    <f:convertNumber type="currency"/>
    </hutputText>

    Topping:

    <hutputText value="#{indexBean.selectedToppingNames}"/> ( I HAVE PROBLEM IN HERE........... )
    <h:panelGroup/>

    Coffee :
    <hutputText value="#{indexBean.selectedCoffeeName.category}"/>
    <hutputText value="#{indexBean.selectedCoffeeName.prices}">
    <f:convertNumber type="currency"/>
    </hutputText>

    <h:panelGroup/>
    Subtotal :
    <hutputText value="#{indexBean.subtotal}">
    <f:convertNumber type="currency"/>
    </hutputText>

    <h:panelGroup/>
    Tax:
    <hutputText value="#{indexBean.tax}">
    <f:convertNumber type="currency"/>
    </hutputText>

    <h:panelGroup/>
    Total:
    <hutputText value="#{indexBean.total}">
    <f:convertNumber type="currency"/>
    </hutputText>
    </h:panelGrid>
    </body>
    </html>


    This is the Result onto Index.xhtml:
    Bagel
    White
    Whole Wheat

    Topping
    Cream cheese
    Butter
    Peach jelly
    Blueberry jam

    Coffee
    Regular Coffee
    Decaf Coffee
    Cappuccino


    This is the Result onto Receipt.xhtml:

    Receipt
    Bagel : Whole Wheat $1.50
    Topping: [Ldata.entity.Topping;@732859 (PROBLEM IN HERE... HOW TO EXPORT EVERY ELEMENTS HAVE SELECTED?)
    Coffee : Regular Coffee $1.25
    Subtotal : $2.75
    Tax: $0.16
    Total: $2.92


    Thank you... and hope to received posistive feedback from all of you.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: How can I export elements in array to .xhtml JSF

    I gave you two links in the last thread you started. Don't you think you should have gone through them by now?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    khanhnq is offline Member
    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Default Re: How can I export elements in array to .xhtml JSF

    Thank you DarrylBurke...

    Thank you for your ideas... My problem has solved.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,984
    Rep Power
    9

    Default Re: How can I export elements in array to .xhtml JSF

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 3
    Last Post: 11-25-2011, 12:38 AM
  2. sum of elements in array
    By myst in forum New To Java
    Replies: 7
    Last Post: 07-17-2010, 08:36 AM
  3. Export array to .csv file
    By ahwillia in forum New To Java
    Replies: 2
    Last Post: 05-04-2010, 04:58 AM
  4. Export an array to a text file
    By carderne in forum New To Java
    Replies: 32
    Last Post: 10-02-2008, 03:52 PM
  5. Help with array of elements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •