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
JasonGardnerJasonGardner 

Problem passing value to controller

Hi everybody!

 

I have a big giant questionnaire, and during my save process in my controller, I want to do some error-checking.  I want to make sure fields aren't more than the 255 characters that they should be.  Here's my "code" that I've gotten to work so far:

 

public PageReference save() { string TestLength = 'ThisShouldBeTheFieldFromTheVisualForcePage'; Integer LengthOfField = TestLength.length(); if (LengthOfField>255) {pop up a window saying that it's too big and break out of page} else {save the questionnaire} }

 

This code works fine, but when I try to replace the value 'ThisShouldBeTheFieldFromTheVisualForcePage' with the actual field, as seen in this code:

 

 

string TestLength = qGeneral.Project_Name__c;

it doesn't seem to work.  It errors out on the "Integer LengthOfField = TestLength.length();" line.  And Eclipse gives an error that says "An unexpected error has occured", which doesn't help me at all.  I tried defining the variable beforehand...I tried checking for "null" before this line thinking that it might not like that.  I just can't get it to work, and I'm sure it's something dumb, but I've been beating myself against the wall for awhile now, and I figure I'd come here and listen to someone tell me how stupid I've been to save some time.

 

Any and all help is extremely appreciated.

 

Thanks!

 

-Jason

Message Edited by JasonGardner on 11-03-2009 07:46 PM
arunkarunk

Hi,

 

 

The function seems to be of (Except that it should return something.).

I think the problem lies in the way you are binding the field to visualforce page. (Or someplace else ...)

More code snippets may help .....

 

By the way, You can add the length validation on the field at object level itself. Hope you knew about this.

 

Regards,

Arun 

JasonGardnerJasonGardner

Here's the code where I have the field in my main page:

 

<tr> <td><b>What is the name (or description) of this project?</b></td> <td><apex:inputTextarea cols="100" rows="7" value="{qGeneral.Project_Name__c}"/></td> </tr>

 

My first part of the controller is:

 

 

public QuestionnaireExtension (ApexPages.StandardController stdController) { ID qid = stdController.getRecord().Id; qGeneral = [select Project_Name__c from Questionnaire__c where id = :qid limit 1];

And then the save routine is:

 

update qGeneral;

 

I actually have a TON of fields, and a ton of "update qStorage", "update qShipping", etc.  The reason I had to do things this way instead of using the normal save routine is because I had too many fields and the SQL statements were too long.  By doing it this way, I basically "split" the entire questionnaire up into like 12 pieces.

 

I know that on inputfield you can maxlength things, and that's what I did for a bunch of fields.  But for 6 of my fields, the user wanted a textarea to enter their comments into, so I can't use the inputtext functionality.  If I restrict the fields inside of salesforce.com normally, with my "split" technique, it gives a nasty error (System.DmlException: Update failed. First exception on row 0 with id blahblahblah; first error: STRING_TOO_LONG,) when someone screws up and then when they hit back to try again, it deletes all of their entries for the other questions.  The user wants the error to be dealt with "on the same page".  I thought of putting in some javascript things that get called when "save" is hit and then call my save routine from there after the error checking is complete, but I'd rather have it done all "in" visualforce.

 

Is there another way to add the length validation at another level and have it return a (end user) manageable error?

 

Thanks for your help!

-Jason

Ajay111Ajay111
 

public string getPName() { Questionnaire__c Q =[select Project_Name__c from Questionnaire__c where id = :qid limit 1 ]; string name =Q.Project_Name__c; return name; } public void setPName(String value) { PName=value; } public PageReference AddAccount() { string TestLength = PName; Integer LengthOfField = TestLength.length(); if (LengthOfField>255) {pop up a window saying that it's too big and break out of page} else {save the questionnaire}

 

<apex:inputTextarea cols="100" rows="7" value="{!PName}"/>

 Try this....

 

arunkarunk

Hi,

 

First things first,

 

<tr><td><b>What is the name (or description) of this project?</b></td><td><apex:inputTextarea cols="100" rows="7" value="{qGeneral.Project_Name__c}"/></td> 

</tr>

 

Consider your statement  value="{qGeneral.Project_Name__c}"

You missed the !, the for correct binding the statement shoould be value="{!qGeneral.Project_Name__c}" 

 

 

See if this helps,

 

Regards,

Arun 

JasonGardnerJasonGardner

Thanks arunk, but it was a typo.  The questionnaire works fine except for this part.  I'm going to try the other suggestion (putting everything into functions), and see if that works.  It's only 6 fields, so even if I have to replicate my work six times, it's not too bad.  I'll let everyone know if I can get that suggestion to work.

 

Thanks!

-Jason