function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bharat004.is091.3910779915252478E12bharat004.is091.3910779915252478E12 

Talking username password administator values from page and should create a XML with these fileds and display in Page by clicking submit button. Please help .

<apex:page controller="Xmlretrive" >
    <apex:form >
        <apex:outputText >Enter the username:
            <apex:inputText id="s1" value="{!userName}" />
        </apex:outputText><br/>
        <apex:outputText >Password :
            <apex:inputSecret id="s2" value="{!password}"  />
    </apex:outputText><br/>
        <apex:outputText >auth :
            <apex:inputText id="s3" value="{!auth}" />
        </apex:outputText>           
        <apex:commandButton value="Click here to submit" action="{!submit}" reRender="attributes1,attributes2,attributes3" /><br/>
        <h1> <apex:outputText id="attributes1" value="{!userName }" /></h1>
        <h1> <apex:outputText id="attributes2" value="{!password }" /></h1>
        <h1> <apex:outputText id="attributes3" value="{!auth}" /></h1>              
        <apex:commandButton value="submit"  reRender="submit"  onclick="{!xmlOutput}"/>
                     
        <apex:actionFunction name="Method1" action="{!getXml}"  reRender="submit"/>
         <apex:outputText id="submit" value="{!xmlOutput}" >{!Xml} </apex:outputText>
                 
    </apex:form>
</apex:page>

public class Xmlretrive{

    public String xmlOutput { get; set; }
    String simple='bharath';
   
    public String auth { get; set; }

    public String password { get; set; }
        
    public String userName {get; set;}
                    
    public PageReference submit() {
                  if (userName == null) {
                         userName = 'Write here';
                   } else {
                         userName = userName ;
                         password = password ;
                         auth=auth;
                      }
                     
        return null;                         
    }
     public String getXml() {
          XmlStreamWriter w = new XmlStreamWriter();
          w.writeStartDocument(null, '1.0');
          w.writeProcessingInstruction('target', 'data');
          w.writeStartElement('', 'attrs', 'http://www.sap.com/rws/bip');
          w.writeNamespace('', 'http://www.sap.com/rws/bip');
         
          w.writeStartElement('', 'attr', 'http://www.sap.com/rws/bip');
          w.writeAttribute(null, null, 'name', 'userName');
          w.writeAttribute(null, null, 'type', 'string');
          w.writeCharacters(simple);
          w.writeEndElement();
          
          w.writeStartElement('', 'attr', 'http://www.sap.com/rws/bip');
          w.writeAttribute(null, null, 'name', 'password');
          w.writeCharacters('bowrsbo4');      
          w.writeEndElement();
        
          w.writeStartElement('', 'attr', 'http://www.sap.com/rws/bip');
          w.writeAttribute(null, null, 'name', 'auth');
          w.writeAttribute(null, null, 'type', 'string');
          w.writeAttribute(null, null, 'possibilities', 'secEnterprise,secLDAP,secWinAD,secSAPR3');
          w.writeCharacters('secEnterprise');      
          w.writeEndElement();
         
          w.writeEndElement();                
          w.writeEndDocument();
          String xmlOutput = w.getXmlString();
          w.close();
          //System.debug(xmlOutput);
          return xmlOutput ;
        }      
 
}
Best Answer chosen by bharat004.is091.3910779915252478E12
bharat004.is091.3910779915252478E12bharat004.is091.3910779915252478E12
Thank u ankit :) it works great with format.

All Answers

Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi,

Try the below modified code:

-------------- Vf page -------------------
<apex:page controller="Xmlretrive">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Click here to submit" action="{!submit}" reRender="output" />

            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1">
                <Apex:pageBlockSectionItem>
                    <apex:outputLabel>Enter the username :</apex:outputLabel>
                    <apex:inputText id="s1" value="{!userName}" />
                </Apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel>Password :</apex:outputLabel>
                    <apex:inputSecret id="s2" value="{!password}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel>Oauth URL</apex:outputLabel>
                    <apex:inputText id="s3" value="{!auth}" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>

        <apex:outputPanel id="output">

            <apex:pageBlock id="chkoutput" title="Output" rendered="{!displayxml}">
                <apex:pageBlockButtons location="top">
                    <apex:commandButton value="View XML" reRender="DisplayXML" />
                </apex:pageBlockButtons>
                <apex:pageBlockSection columns="1">
                    <Apex:pageBlockSectionItem>
                        <apex:outputLabel>User Name</apex:outputLabel>
                        <apex:outputLabel>{!userName }</apex:outputLabel>
                    </Apex:pageBlockSectionItem>
                    <Apex:pageBlockSectionItem>
                        <apex:outputLabel>Password</apex:outputLabel>
                        <apex:outputLabel>{!password}</apex:outputLabel>
                    </Apex:pageBlockSectionItem>

                    <Apex:pageBlockSectionItem>
                        <apex:outputLabel>Oauth URL</apex:outputLabel>
                        <apex:outputLabel>{!auth}</apex:outputLabel>
                    </Apex:pageBlockSectionItem>
                </Apex:pageBlockSection>

            </apex:pageBlock>
        </apex:outputPanel>




        <apex:outputPanel id="DisplayXML">
            <apex:outputPanel rendered="{!displayxml}">
                <apex:outputText value="{!Xml}"></apex:outputText>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
</apex:page>




--------------- Apex class code -----------------
public class Xmlretrive {
    public String xmlOutput {
        get;
        set;
    }
    String simple = 'bharath';
    public String auth {
        get;
        set;
    }
    public String password {
        get;
        set;
    }
    public String userName {
        get;
        set;
    }
    public boolean displayxml {
        get;
        set;
    }
    public Xmlretrive() {
        displayxml = false;
    }
    public PageReference submit() {
        displayxml = true;
        if (userName == null) {
            userName = 'Write here';
        } else {
            userName = userName;
            password = password;
            auth = auth;
        }
        return null;
    }
    public String getXml() {
        XmlStreamWriter w = new XmlStreamWriter();
        w.writeStartDocument(null,
            '1.0');
        w.writeProcessingInstruction(
            'target', 'data');
        w.writeStartElement('', 'attrs',
            'http://www.sap.com/rws/bip'
        );
        w.writeNamespace('',
            'http://www.sap.com/rws/bip'
        );
        w.writeStartElement('', 'attr',
            'http://www.sap.com/rws/bip'
        );
        w.writeAttribute(null, null,
            'name', 'username');
        w.writeAttribute(null, null,
            'type', 'string');
        w.writeCharacters(username);
        w.writeEndElement();
        w.writeStartElement('', 'attr',
            'http://www.sap.com/rws/bip'
        );
        w.writeAttribute(null, null,
            'name', 'password');
        w.writeCharacters(password);
        w.writeEndElement();
        w.writeStartElement('', 'attr',
            'http://www.sap.com/rws/bip'
        );
        w.writeAttribute(null, null,
            'name', 'auth');
        w.writeAttribute(null, null,
            'type', 'string');
        w.writeAttribute(null, null,
            'possibilities',
            'secEnterprise,secLDAP,secWinAD,secSAPR3'
        );
        w.writeCharacters(auth);
        w.writeEndElement();
        w.writeEndElement();
        w.writeEndDocument();
        String xmlOutput = w.getXmlString();
        w.close();
        //System.debug(xmlOutput);
        return xmlOutput;
    }
}

Thanks
Ankit Gupta
bharat004.is091.3910779915252478E12bharat004.is091.3910779915252478E12
Thank u ankit :) it works great with format.
This was selected as the best answer