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
philanthropyphilanthropy 

java.lang.IllegalArgumentException error

I'm trying to create a simple app while learning visualforce/apex. I'm creating a table of movies available to rent and want to have a button for each movie allowing you to rent that movie and passing the movie name to a method that will remove one from the inventory. I'm still working on it but I'm getting a java.lang.IllegalArgumentException error when I click the button and not sure where im going wrong. I'm sure there's probably an obvious error in my approach but any help would be great! 



 

Here's a code snippet of the column containing the rent button:

 

<apex:column headerValue="Rent Movie">
    <apex:commandButton action="!Rent" value="Rent {!movie_item.name}">
        <apex:param name="id" value="{!movie_item.name}" />
    </apex:commandButton>
</apex:column>

 

 

here's my apex code in my controller extension:

 

public class MovieRentalExtension {

    private final Movie__c movie;

    public MovieRentalExtension(ApexPages.StandardSetController controller) {
        this.movie = (Movie__c)controller.getRecord();
    }
   
    public void Rent() {
        Id id = System.currentPageReference().getParameters().get('id');
        // rent movie code
       
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The command button action needs merge syntax I'd say:

 

action="{!Rent}"

 

All Answers

bob_buzzardbob_buzzard

The command button action needs merge syntax I'd say:

 

action="{!Rent}"

 

This was selected as the best answer
philanthropyphilanthropy

Thanks for the help Bob!

 

I've continued to stumble through trying to figure this out and I'm stuck again. Let me know if the way I'm going about it even makes sense. I'm trying to assign MovieRented to be the movie that they've selected, then decrement the inventory by 1.

 

public class MovieRentalExtension {

    private final Movie__c movie;
    private Movie__c MovieRented;
   
    public MovieRentalExtension(ApexPages.StandardSetController controller) {
        this.movie = (Movie__c)controller.getRecord();
    }
    
    public PageReference Rent() {
        MovieRented = [SELECT name, Total_Inventory__c
        FROM Movie__c
        WHERE name = :ApexPages.currentPage().getParameters().get('id')];   
        MovieRented.Total_Inventory__c=MovieRented.Total_Inventory__c-1;
        update MovieRented;
        return null;
        
    }
}

 

VF:

<apex:column headerValue="Rent Movie">


    <apex:commandButton action="{!Rent}" value="Rent {!movie_item.name}">
        <apex:param name="id" value="{!movie_item.name}" />
    </apex:commandButton>


</apex:column>

 

bob_buzzardbob_buzzard

You'll need to have a rerender attribute to pass the parameter back to the controller.  I'd also use the assignTo attribute rather than interrogating the url, and finally its better to use an id to identify a record as that will be unique:

 

public class MovieRentalExtension {

    private final Movie__c movie;
    private Movie__c MovieRented;
    public idToRent {get; set;}
   
    public MovieRentalExtension(ApexPages.StandardSetController controller) {
        this.movie = (Movie__c)controller.getRecord();
    }
    
    public PageReference Rent() {
        MovieRented = [SELECT name, Total_Inventory__c
        FROM Movie__c
        WHERE id = :idToRent ]; 
        MovieRented.Total_Inventory__c=MovieRented.Total_Inventory__c-1;
        update MovieRented;
        return null;
        
    }
}

 

<apex:column headerValue="Rent Movie">


    <apex:commandButton action="{!Rent}" value="Rent {!movie_item.name}" rerender="{!tableIdHere}>
        <apex:param name="idToRent" value="{!movie_item.id}" assignTo={!idToRent}" />
    </apex:commandButton>


</apex:column>

 replacing tableIdHere with the component id of the table from the page.

Julia GomezJulia Gomez
I was able to create my online movie (http://www.cinecalidad.plus) page through java. It can help you very well in the whole subject of automation and graphics.