This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

crazyk crazy

Greenhorn
+ Follow
since Sep 23, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by crazyk crazy

Sorry! I did not get you and I do not find this link to be working-purple mooseages
6 years ago
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().toString());
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().toString());
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());

}
6 years ago
Scenario:
I am trying to unmarshall the Acord XML(Insurance standard XML) to Java-Acordform and then trying to map the Acordform object to a one more formbean-Policformbean in order to display the values in the JSP where user can edit the values.Again I have to marshall the Java object values to XML.There is an XSD available for this Acpord XML.Suing XMLSpy I have created XSD from XML.Using XJC I have created the java objects from XSD. Since Acord being a complex XML and the structure of the generated Java object is not straight forward I have created Policformbean.Using Policformbean , I am tring to display the values in the JSP.

Issue:
I am facing few issues while setting the acordform to Policformbean.May I know if using JAXB is the best approach for me to display the XML element values when Acord XML is used? If anyone has worked on JAXB conversion from Acord XML to Java object values, please guide me.

Thanks in Advance.
6 years ago
Scenario: On click of a 'Submit' button I have unmarshalled the XML to Java and then displaying the Java objects(created a formbean and mapped the JAXB java Objects to this formbean- PolicyForm and using this formbean to display in JSP) in the JSP.This is working fine.

Issue: I have one more button -Calculate on the same page with in the same form of Submit button. On click of the 'Calculate' button I need to get the acordform values which was unmarshalled during the click of Submit button. Here I am not able to get the acordform values instead I am getting the new object of acordform.

When I have googled I see- Struts 2 doesn't have thread-safety issues as "Action objects are instantiated for each request". Please let me know here when I am sending the request again is the Action object- acordform being instantitaed everytime? If yes, how can I avoid this ? Since I need the acordformobject values even in the next request too.

Action Class:
public class RateAction extends ActionSupport implements
ServletRequestAware,SessionAware {

/* ... */

// ACORD xml form bean
private ACORD acordform = new ACORD();

//To display the values in the JSP
private PolicyForm policyForm;

public ACORD getAcordform() {
return acordform;
}

public void setAcordform(ACORD acordform) {
this.acordform = acordform;
}

public String doSubmit() {
/*...Unmatshalling from XML to Java -acordform is done..*/
}

public String doRateSubmimt()
{
/*..trying to get the acordform values which are being set
previously in doSubmit() method...*/
}
}

Struts.xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/" >

<action name="fileUploadAction"
class="com.main.common.action.RateAction" >
<interceptor-ref name="fileUpload">
<param name="allowedTypes">text/xml</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="params"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="basicStack"/>
<result name="success">First.jsp</result>
<result name="input">First.jsp</result>
</action>

<action name="submitAction" class="com.main.common.action.RateAction" method="doSubmit">
<result name="success">First.jsp</result>
</action>
<action name="rateAction" class="com.main.common.action.RateAction" method="doRateSubmit">
<result name="success">First.jsp</result>
</action>
</package>

JSP:

<s:form id="rtr" action="fileUploadAction" method="POST"
enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<s:file name="uploadFile" label="Upload Request XML" />
<s:submit value="Submit" action="submitAction" onclick="displayDetails();" />
<s:hidden name="submitSuccess" />
<s:submit value="Calculate" action="rateAction" />
</tr>
</table>
</s:form>
6 years ago