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
champ_vimalchamp_vimal 

Zipcode field bounds

Hi,

 

I have a field 'Zipcode' to be displayed as plain text (outputtext) on a visualforce page.

 

However, whenever user enters many values the zipcode field gets long and it stretches the visualforce page. Can I have some way to wrap up the Zipcode field and display values on different lines?

 

Thanks,

 

Vimal 

ShikibuShikibu

You'll need an apex controller, I think. The following markup allows raw html to flow from the merge field to the page.

 

 

<apex:outputText value="{!zipCodesHtml}" escape="false"/>

 

The following code replaces newlines in the zipcode field with the html that creates a break to the next line.

 

CustomObject__c myObject;

public String getZipCodesHtml { get { return myObject.zipCodes.replace('\n', '<br/>'); } }

 

Depending upon what's between your zipcodes, you might want the code to replace commas rather than newlines.

 

 

 

indranily81indranily81

 

You can use the following code to break the zipcode into separate lines. Its running in my machine. Let me know if there is any typo error.

 

VF code :

 

<apex:page controller="MyCon">
  
    <apex:pageBlock >
      <apex:form >
         Enter the zipcode :
         <apex:inputtext value="{!zipcode}" id="zipcode"/>
        
         <apex:commandButton value="Submit" action="{!submit}" rerender="zipout" status="status"/>
      </apex:form>
     
      <apex:outputPanel id="zipout">
        <b>Selected zipcode : {!zipcode}</b>
        <br><b>Zipcode length : {!sizeofzip}</b></br>
        <br>Zip codes broken in separate line : </br>
       
        <apex:dataTable value="{!zipholder}" var="zipholder" >
          <apex:column >
             <apex:outputText value="{!zipholder}"/>
          </apex:column>
        </apex:dataTable>
       
       
        <br> If any error: {!errorcode}</br>
             
      </apex:outputPanel>
   
   
    </apex:pageBlock>
   
</apex:page>

 

 

Controller code :

 

public class MyCon {
      
   
    String zipcode ;
    List <String> zipholder = new List<String>{};
    integer sizeofzip;
    String errorcode;
    Integer position = 5;
    integer startzip;
    integer endzip;
   
    Integer flag ;

      
    public PageReference submit() {
        return null;
    }
   
    public Integer getFlag() {
        return flag;
    }

        
    public String getZipcode() {
       
        return zipcode ;
       
    }
   
     public void splitup(String cp_zipcode, Integer position) {
     
      sizeofzip = cp_zipcode.length();
      startzip = 0;
      endzip = startzip + position;
     
     
          
      zipholder.clear();
      try {
          for(integer i = 0 ; startzip <= sizeofzip ; i++) {
            
             zipholder.add(cp_zipcode.substring(startzip, endzip));
             startzip = endzip;
             if((sizeofzip - startzip) >= position) {
              endzip = endzip + position;
             }
             if((sizeofzip - startzip) < position) {
              endzip = endzip + (sizeofzip - startzip) ;
             }
      
          }
      }
      catch(Exception e) {
            errorcode= 'Error Occured';
      }
     
    }

    public void setZipcode(String cp_zipcode) {
        this.zipcode = cp_zipcode;
       
        splitup(cp_zipcode,position);
    }
   
     public integer getSizeofzip() {
        return sizeofzip;
    }
   
     public List<String> getZipholder() {
        return zipholder ;
    }
       
   
     public String getErrorcode() {
        return errorcode;
    }
   
   
    
  
}