+ Start a Discussion
LakshmanLakshman 

How do I bind a visualforce value with apex variable

Hi All,

 

I am trying to bind visualforce value to an Apex class variable. Below is my sample code:

 

<textarea id="editor1" name="editor1">{!apexVariable}</textarea>

<apex:commandButton value="Check" action="{!check}"/>

Below is my Apex class:

 

public class MyClass

{

public String apexVariable{get;set;}

public void check()

{

System.debug(apexVariable+'>>>><<<<');

}

}

 

My question is how do I get the changed value from visualforce page to apex class variable using this html tag?

I know that if I use apex:inputtextarea it will automatically bind it to the desired apex class variable but how to work on simple html tags.

 

 

Regards,

Lakshman

bob_buzzardbob_buzzard

The simple answer is that it doesn't work on regular HTML inputs.  The only way to workaround this would be to have an apex:inputhidden that gets updated via javascript with the value from the textarea.

 

Is there any reason why you want to use standard HTML inputs - the apex versions boil down to these when the page is rendered anyway.

LakshmanLakshman

I am integrating CKEditor with on of my custom object fields. CKEDitor uses only html field <textarea> and then it replaces the inline text value with the changes of user. Basically I want a spell checker to check spelling of my email body so I am using CKEditor use its spell checker functionality.

If you have any work arounds to it please let me know.

 

Regards,

Lakshman

LakshmanLakshman

Bob,

I tried you suggestion but I am not able to get tge inner text of my text area: Lets say for example

<textarea id='editor1' name = 'editor1'> I want this</textarea>

 

now in js I write:

 

var textVal = document.getElementById('editor1').text or value or innerText;

 

and when I do an alert to this variable, I get undefined, dont know WHY?

 

Is there anything which I am missing?

Please let me know your thoughts to this.

Thank you!

 

Regards,

Lakshman

bob_buzzardbob_buzzard

I still don't think you'll need to use a standard text area for this.  I've integrated TinyMCE using apex:inputTextArea in the past.  When the page is delivered to the browser, the apex:inputTextArea will be turned into a standard HTML text area, and presumably ckeditor can work against that.

LakshmanLakshman

Unfortunately it doesnt, I have tried it. I get two text area in my page when I do so.

The problem which now I am facing is that I am not able to set the value of changed text in VFP to the apex class variable using apex:inputHidden.

 

Regards,

Lakshman

bob_buzzardbob_buzzard

I had to specify a styleclass for tinyMCE to recognise the text area as something it needed to take control of 0 is there nothing similar for ckeditor?  According to the ckeditor docs, you can pass in the id of the textarea that you want it to replace.

LakshmanLakshman

Yes you are right we need to pass the id of textarea to use the CKEditor. But I don't know why I am not able to get the changed text from the textarea through JavaScript. I also tried to use CKEditors built in function for this(CKEDITOR.getText()) but it gave me some JavaScript error. Don't know where I am going wrong.

Can you please help me in figuring this out?

Thank you!

 

Regards,

Lakshman

anjisalesforce@gmail.comanjisalesforce@gmail.com

Visual Force Page:

 

<apex:inputText value="{!Variable}

 

 

 

Below is my Apex class:

 

public class MyClass {

public String Variable{get;set;}

public void check()

{

System.debug('--------------'+Variable);

}

}