How do I reference my wrapper class in my prepareshipment method? My goal was to set tNumber and location to = my fields on my shipment object.
In my VF page I want tNumber and Location to display Tracking_Number__c and Location__c during the edit field. I had set location and tnumber like this prior and it worked fine in my vf page but I have more variables i need to set as well and that method would take forever:
public string location{
get {
if( location == null ) location = ship.Location__c;
return location;
}
set;
Current class I Have with wrapper:
public with sharing class shipmentController {
public shipment__c ship {get;set;}
public String shipId {get;set;}
public class shipWrapper{
public String tNumber {get;set;}
public String location {get;set;}
public shipWrapper(Shipment__c ship){
this.tNumber = ship.Tracking_Number__c;
this.location = ship.location__c;
}
}
public shipmentController() {
shipId = ApexPages.currentPage().getParameters().get('shipId');
if (shipid == null) {
ship = new Shipment__c();
return;
}
ship = [select id, location__c, tracking_number__c
from shipment__c
where id = :shipid];
}
public PageReference prepareShipment(ShipWrapper ShipWrapper) {
ship.tracking_Number__c = shipWrapper.tnumber;
ship.Location__c = shipWrapper.location;
update ship;
Edited code:
public with sharing class shipmentController {
public shipment__c ship {get;set;}
public String shipId {get;set;}
public shipWrapper wrapper { get; set;}
public class shipWrapper{
public String tNumber {get;set;}
public String location {get;set;}
public shipWrapper(Shipment__c ship){
this.tNumber = ship.Tracking_Number__c;
this.location = ship.location__c;
}
}
public shipmentController() {
wrapper = new shipmentWrapper(ship);
shipId = ApexPages.currentPage().getParameters().get('shipId');
if (shipid == null) {
ship = new Shipment__c();
return;
}
ship = [select id, location__c, tracking_number__c
from shipment__c
where id = :shipid];
}
public PageReference prepareShipment() {
ship.tracking_Number__c = Wrapper.tnumber;
ship.Location__c = Wrapper.location;
update ship;
VF snippet:
<apex:page controller="shipmentController" showHeader="true"
sidebar="true">
<apex:form >
<apex:pageBlock Title="edit Shipment">
<apex:pageMessages />
<apex:pageBlockSection Title="Shipment Information" columns="2">
<apex:inputText label="First Name" value="{!wrapper.tNumber}"
id="fname"/>
<apex:inputText label="Last Name" value="{!wrapper.location}"
id="lname"/>
</apex:pageBlockSection>