0

I need to show a couple text fields in Table format but unable to achieve that. VF Page:

<apex:page controller="DynamicVT_cls">
<apex:pageBlock ><apex:form >
    <apex:dataTable value="{!ItemList}" var="It">
        <apex:column headerValue="Product Name" > <apex:inputText value="{!It.Name}"/>  </apex:column>&nbsp;
        <apex:column headerValue="Quantity" > <apex:inputText value="{!It.Quantity}"/>  </apex:column>
    </apex:dataTable></apex:form>
</apex:pageBlock>
</apex:page>

Apex Class:

public with sharing class DynamicVT_cls {

    public String tet { get; set; }

    public ItemClass ItemList { get; set; }

    public class ItemClass
    {
        public String Name{get;set;}
        public String Quantity{get;set;}
        public ItemClass(String Name,String Quantity)
        {
            this.Name = Name;
            this.Quantity = Quantity;
        }
    }
}

Any help is appreciated..

1

The ItemList property is not initialized in your controller. since its null, the table is not rendering the text boxes.

if you initialize the property either in the get part of the property or in the controller constructor, the table will show the text fields.

you can add the below constructor to your controller and you should see a single row of 2 text boxes (for product name & quantity)

public DynamicVT_cls()
{
    ItemList = new ItemClass('',''); 
}

I m not sure about your overall requirement, but I believe you might need to bind the table to a collection of Items rather than a single Item. if so you need to change the property to a list and initialize it accordingly..

0

Try this in VF page ( also try to use apex:inputField instead of inputtext as far as possible, as this preserves the formatting as applicable on field)-

Product Name

  <apex:column>
      <apex:facet name="header">Quantity</apex:facet>
       <apex:inputText value="{!It.Quantity}"/>
  </apex:column>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.