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
PushkarPushkar 

MVC pattern with custom HTML elements

Hi,

How does the MVC pattern work for visualforce?

If I have a custom HTML element on a visual force page, can I still leverage the power to have the value reflected in the corresponding objet field in the controller.

for. e.g.

<apex: Page customController="MyController">
    <apex: form>
       <apex: PageBlockButtons >
              <apex:commandButton action="{!Save}" value="Save"/>
       </apex: PageBlockButtons>
       <apex: outputLabel value="custom label"/>
       <input id="myInputId" type="text" value="{account.Name}"/>
    </apex: form>
</apex: Page>

public class MyController{
       Account account;
       public MyController(){
             account = [Select Id, Name from Account where ...[some condition]][0];
       }

       public Account getAccount(){
             return account;
       }

       public PageReference Save(){
             /***************************************************************
              If I enter any value in the <input id="myInputId" ... />
             of the page will it be reflected in the account object ?

              **************************************************************/

             return null;
       }
}


Message Edited by Pushkar on 08-08-2008 08:13 AM
jwetzlerjwetzler
You need to use inputField or inputText instead of html elements.  Please go over the examples in the doc and on the wiki, they will help you get started.
PushkarPushkar
I am aware of that, but the thing is, say if I want to apply an auto-complete feature to an input field available from yahoo. It requires that I wrap the input field in a div with a certain class, which, here cannot be done using the apex: Inputfield element. So I would need to replace it with an HTML input element.

Well, adding such features could also be done by using certain other library which may just take the Id of the field. But the question is, what if it is required the other way? Can we build certain apex tags of our own, which would enable us to enhance the available tags or even create some new custom apex tags.. Just a thought!

Pushkar