Ask Experts Questions for FREE Help !
Ask
    crazy287's Avatar
    crazy287 Posts: 3, Reputation: 1
    New Member
     
    #1

    Sep 23, 2013, 06:32 AM
    Setting dynamic list of different type of objects to a Java form bean
    Scenario:

    I am trying to map the JAXB Java object- 'Coverage' to a Java form bean-'CoverageForm'. I have a List -'coverageList' of Coverage objects.In the Coverage object, I have a list of content objects 'cov.getContent()' of type JAXBElement, Limit,Deductible. I need to set the cov.getContent() list values to a form bean-'CoverageForm'

    Issue:
    cov.getContent() list is dynamic.So for each Coverage object, cov.getContent() can be of size 5 or 3 or anything. How can I set the dynamic list of different objects-'cov.getContent()' to a form bean object-'CoverageForm' ? The below code of Action class do not show the expected result. I have tried to hardcode the index value but it throws ArrayIndexoutOfBoundExeception because in each Coverage object the cov.getContent() can be of size 5 or 3 or anything. If you see I need to set the limit.getFormatInteger() to LowLimit and HighLimit of CoverageForm while looping.How can I achieve this?Please suggest me.

    To get an idea of the XML elements structure-'coverageList' structure is-

    <Coverage>
    <CoverageCd>BI</CoverageCd>
    <CoverageDesc>Bodily Injury Liability</CoverageDesc>
    <Limit>
    <FormatInteger>100000</FormatInteger>
    <LimitAppliesToCd>PerPerson</LimitAppliesToCd>
    </Limit>
    <Limit>
    <FormatInteger>300000</FormatInteger>
    <LimitAppliesToCd>PerAccident</LimitAppliesToCd>
    </Limit>
    </Coverage>
    <Coverage>
    <CoverageCd>PD</CoverageCd>
    <CoverageDesc>Property Damage-Single Limit</CoverageDesc>
    <Limit>
    <FormatInteger>50000</FormatInteger>
    <LimitAppliesToCd>PropDam</LimitAppliesToCd>
    </Limit>
    </Coverage>
    <Coverage>
    ... "CoverageDesc","CoverageCd" are attributes of JAXBElement class.

    public class Limit {

    @XmlElement(name = "FormatInteger")
    protected int formatInteger;
    @XmlElement(name = "LimitAppliesToCd")
    protected String limitAppliesToCd;
    }

    public class Deductible {

    @XmlElement(name = "FormatInteger")
    protected int formatInteger;
    @XmlElement(name = "DeductibleTypeCd")
    protected String deductibleTypeCd;
    }

    public class Coverageform {

    private int vehId;
    private String coverageCd;
    private String coverageDesc;
    private int lowLimit;
    private int highLimit;
    private int deducitble;

    }

    Action class:

    for(int I=0; I<vehicleList.size();i++)
    {
    List coverageList=((Pers) vehicleList.get(I)).getCoverage();

    for (int j=0; j<coverageList.size();j++)
    {
    Coverage cov= (Coverage)coverageList.get(j);

    System.err.println("cov--"+cov);


    //for( Object o: cov.getContent()){
    if( cov.getContent().get(0) instanceof JAXBElement)
    {
    System.err.println("o is JAXBElement");
    JAXBElement jaxbele= (JAXBElement)cov.getContent().get(0);
    coverageForm.setCoverageCd(jaxbele.getValue().toSt ring());
    System.err.println("coverageForm.getCoverageCd()--"+coverageForm.getCoverageCd());
    }
    if( cov.getContent().size()>1 && cov.getContent().get(1) instanceof JAXBElement)
    {
    JAXBElement jaxbele1= (JAXBElement)cov.getContent().get(1);
    coverageForm.setCoverageDesc(jaxbele1.getValue().t oString());
    System.err.println("coverageForm.getCoverageDesc()--"+coverageForm.getCoverageDesc());
    }
    if (cov.getContent().size()>2 && cov.getContent().get(2) instanceof Limit)
    {
    System.err.println("o is Limit");
    Limit limit= (Limit)cov.getContent().get(2);
    coverageForm.setLowLimit(limit.getFormatInteger()) ;
    System.err.println("coverageForm.getLowLimit()--"+coverageForm.getLowLimit());
    }
    if ( cov.getContent().size()==4 && cov.getContent().get(3) instanceof Limit)
    {
    Limit limit1= (Limit)cov.getContent().get(3);
    coverageForm.setHighLimit(limit1.getFormatInteger( ));
    System.err.println("coverageForm.getHighLimit()--"+coverageForm.getHighLimit());
    }
    if (cov.getContent().size()==5 && cov.getContent().get(4) instanceof Deductible)
    {
    System.err.println("o is Deductible");
    Deductible ded= (Deductible)cov.getContent().get(4);
    coverageForm.setDeducitble(ded.getFormatInteger()) ;
    System.err.println("coverageForm.getDeducitble()--"+coverageForm.getDeducitble());
    }

    coverageFormList.add(coverageForm);
    System.err.println("coverageFormList.size--"+coverageFormList.size());

    }

Check out some similar questions!

What type a bean do I need to support 30 open foot span [ 0 Answers ]

My shop has outgrown it's spray booth (protective coatings) and I need to build a new one. The booth will be approx 12 high, 23 deep and 30 side to side (i.e. opening) and needs to be a clear span, devoid of supports as well as no supports within the structure.. In an area approx 10x3 at the...

Choosing a value in validating list and dynamic change in other cells [ 1 Answers ]

Say in sheet 2 I have name, age, sex, address. And tn sheet 1 on choosing a name Ram in column B in list box(data validation) I should see dynamic text in Column C, D, E with Age, sex and address info respectively. After sometime in column B if I choose Sita then her info should change in C, D ,E....

Mini bean bag type baby.can't remember the name! [ 1 Answers ]

I had this toy when I was about 6 or 7 years old around 1992ish... they were mini bean bag babies about the size of a Barbie baby. They had plastic heads and beanie bodies... I had a merry-go-round, a swing, and a cradle with it I believe... probably more but I don't remember. I used to love...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.