Avatar of 3XLcom
3XLcom
 asked on

java stringvalue

   public void setUserName(JAXBElement<StringValue> value) {
        this.userName = ((JAXBElement<StringValue> ) value);
    }

how should i call this function
setUserName("example"); is not working :(
i need to send example word to this function thanks
JavaJava EE

Avatar of undefined
Last Comment
3XLcom

8/22/2022 - Mon
cyberkiwi

setUsername(new JABXElement("example"))
3XLcom

ASKER
Not worked unfortunatelly
JABXElement as seems is not known :(
cyberkiwi

Sorry I misspelled

setUsername(new JAXBElement<StringValue>("example"))
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
rockiroads

Are you using some kind of web services? Think you need to setup your xml schema, from which you get java classes.
have a look at this tutorial https://jaxb.dev.java.net/tutorial/
cyberkiwi

Actually there is no simple string constructor for JAXBElement

JAXBElement(QName name, Class<T> declaredType, Class scope, T value)
JAXBElement(QName name, Class<T> declaredType, T value)

Try this:


QName qName = new QName("http://tempuri", "Test");
JAXBElement<String> el = new JAXBElement<String>(qName, String.class, null, "example");
setUsername(el);
3XLcom

ASKER
I've made sth. Like This but it returns null value i think i have so close to solution  :

   public JAXBElement<PmumService.StringValue> getUserName() {
        javax.xml.bind.JAXBElement<PmumService.StringValue> bilgi = null;
        PmumService.StringValue bilgim = new PmumService.StringValue() ;
        bilgim.setV("Pass");
        bilgi.setValue(bilgim) ;
        return bilgi;
    }

In PmumService library :


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StringValue")
public class StringValue {

    @XmlAttribute(name = "v")
    protected String v;

    /**
     * Gets the value of the v property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getV() {
        return v;
    }

    /**
     * Sets the value of the v property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setV(String value) {
        this.v = value;
    }

}
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
3XLcom

ASKER
cyberkiwi it works when it is string but when i change it to stringvalue it is not working
Thank you
3XLcom

ASKER
Please i need help The code given below is worked but the problem is returns null reference for
UName and Pass
javax.xml.ws.Holder<PmumService.IntValue> Bilgi1;
    javax.xml.ws.Holder<PmumService.StringValue> Bilgi2;
     @XmlElementRef(name = "UserName", type = JAXBElement.class, required = false)
    protected JAXBElement<PmumService.StringValue> UName;
     @XmlElementRef(name = "PassWord", type = JAXBElement.class, required = false)
    protected JAXBElement<PmumService.StringValue> pass;
    public void callWebService() {
        PmumService.EVDServis services = new PmumService.EVDServis();
        System.out.print(services.getWSDLDocumentLocation());
        PmumService.LoginMessage LMessage  = new PmumService.LoginMessage();

        PmumService.StringValue bilgim = new PmumService.StringValue() ;
        bilgim.setV("ad");
        System.out.print("bb : " + UName.getName());
        UName.setValue(bilgim);

        PmumService.StringValue bilgim2 = new PmumService.StringValue() ;
        bilgim2.setV("Pass");
        pass.setValue(bilgim2);


        LMessage.setUserName(UName);
        LMessage.setPassword(pass);
        PmumService.IntValue vl = new PmumService.IntValue();
        vl.setV(null);
        Bilgi1.value=vl;
        services.getEVDServisSOAP11PortHttp().login(LMessage, Bilgi1, Bilgi2);
        System.out.print("Son : " + Bilgi2.value);

Open in new window

ASKER CERTIFIED SOLUTION
cyberkiwi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
3XLcom

ASKER
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
3XLcom

ASKER