apex inputText value null in controller - salesforce

I have an input filed that I am attempting to pass the end user's entered input into the SF controller class.
Below is the inputText visualforce code:
<div class="ssa-inputs">
<div class="ssa-input-text">Name: </div>
<div class="ssa-input">
<apex:form>
<apex:inputText value="{!acknowledgeInput}" id="acknowledgeInput"/>
</apex:form>
</div>
</div>
<div class="ssa-btns">
<div class="ssa-btn">
<apex:form>
<apex:commandButton id="acceptHidden" value="Accept" action="{!updatecontact}"/>
</apex:form>
<input type="submit" id="acceptBtn" value="Accept"/>
</div>
<div class="ssa-btn">
<apex:form>
<apex:commandButton value="Decline" action="{!updatecontact}"/>
</apex:form>
</div>
</div>
Below is the SF controller code:
public string acknowledgeInput{get;set;}
public PageReference updatecontact(){
System.debug(LoggingLevel.DEBUG, acknowledgeInput);
// Update contact information
// Redirect to respected PageReference
}
When I try to print out the value in the logs, I receive null.
I feel like this is pretty straight forward and I can't seem to find what I'm missing.
Thanks

You need to have the command button and input text field in the same form.

Related

Apex:Component refresh on page rerender

again, lovely people.
Having an issue with getting an apex:component to refresh when the page reloads, and I can't seem to figure out what to do with it.
We've tried everything from putting the component in an outputPanel and adding that to the rerender attribute, reloading the entire page with an oncomplete, using the window.reload (something like that) function, and even tried forcing a reload with setTimeout.
While I'm able to get the entire page itself to reload, the component never does until you actually go up and click the "refresh" button on the browser.
A demo of the code is below:
<apex:page controller="myController" id="thePage" showHeader="false" sidebar="false" applyHTMLTag="false" standardStylesheets="false" action="{!onStart}">
<apex:composition template="myTemplate">
<apex:define name="header">
<c:myHeader fixed="true" language="{!langPref}" filling="true" timeout="true" /> <!--appStatus="{!app.App_Status__c}"-->
</apex:define>
<apex:define name="sidebar" >
<c:mySidebar id="theSidebar" applicationCurrentStage="{!currentStage}" applicationMaxStage="{!app.Application_Stage__c}" stages="{!appPagesMetadata}" memberSegmentedStages="{!memberSegmentedStages}" stagesToInvalidate="{!stagesToInvalidate}" currentMemberIndex="{!memberIndex}" members="{!members}" application="{!app}"/>
</apex:define>
<apex:define name="contents">
<p>There's totally some stuff in here.</p>
<div class="form-group">
<div class="col-lg-12">
<apex:commandButton action="{!save}" value="{!$Label.Save_Progress}" rerender="thePage" rendered="{!app.Application_Stage__c==NEW_STAGE && !guestUser}" oncomplete="myJS.afterSave({!isSaved},false);" status="blockStatus" />
<!--Functionality to Save and go Next-->
<apex:commandButton action="{!saveAndNext}" value="{!IF(previousStage==app.Application_Stage__c||app.Application_Stage__c==NEW_STAGE,$Label.Save_Next_btn ,$Label.Save_Progress)}" rerender="theForm" oncomplete="myJS.afterSave({!isSaved},true);" status="blockStatus" rendered="{!NOT(guestUser) || NOT(captchaEnabled)}" />
<apex:commandButton action="{!verifyCaptcha}" value="{!IF(previousStage==app.Application_Stage__c||app.Application_Stage__c==NEW_STAGE,$Label.Save_Next_btn,$Label.Save_Progress)}" rerender="thePage" oncomplete="myJS.afterSave({!isSaved},true);" status="blockStatus" rendered="{!guestUser && captchaEnabled}" />
<apex:actionFunction action="{!nextPage}" name="nextPage" status="blockStatus" />
<!--Functionality to Go To Page based on Sidebar preference-->
<apex:actionRegion renderRegionOnly="true">
<apex:outputPanel id="fastRerenderPanel" />
<apex:actionFunction action="{!findPage}" name="goToPage" status="blockStatus" reRender="fastRerenderPanel" oncomplete="redirectToPage();">
<apex:param name="goToPage" id="goToPage" assignTo="{!goToPage}" value="" />
<apex:param name="memberIndexNavigation" id="memberIndexNavigation" assignTo="{!memberIndex}" value="" />
</apex:actionFunction>
<apex:actionFunction action="{!redirectToPage}" name="redirectToPage" status="blockStatus" />
</apex:actionRegion>
<apex:actionStatus id="blockStatus" onstart="myJS.blockScreen();" onstop="myJS.unblockScreen();" />
</div>
</div>
</apex:define>
</apex:composition>
</apex:page>
Thanks again, everyone.

Salesforce: Creating a User Registration Form using VisualFocre

I have below requirement to Create a VF page – ‘Registration Forum’ having
1.Name field
2.Age field
3.Project Unit field
4.Gender as Radio Button with values – M and F
5.Certification as Picklist with Values – PD1, ADM 201, PD2, App Builder, Sales Cloud, Service Cloud
6.2 buttons – save and reset
7.Attachment area – where we can browse and add any document there.
Save Button – A record should get created in one object (Any object u can mention)
Reset Button – Page should not get refreshed, just values get refreshed with blank value.
As I am new to SFDC, could you please help me to get it done?
Thanks
It's hard to tell from your question exactly what you're looking for, but here is a visualforce page that saves to a custom object called Form__c.
To do the save and reset you'll probably need an Apex extension. I'm not sure if your browse documents is for Salesforce documents or local files.
<apex:page standardController="Form__c" >
<apex:form>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!Form__c.Name}" />
<apex:inputField value="{!Form__c.Age__c}" />
<apex:inputField value="{!Form__c.Project_Unit__c}" />
<apex:selectRadio value="{!Form__c.Gender__c}" ><apex:selectOption itemValue="Male" itemLabel="Male" /><apex:selectOption itemValue="Female" itemLabel="Female" /></apex:selectRadio>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi here is the sample code for your asking for form submission.i have create custom object Registration_Forum__c.
Click to see Custom Object Registration_Forum__c Image
<apex:page Controller="VFFileUpload">
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:form>
<apex:pageBlock title="Upload Attachment">
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!saveForm}" />
<apex:commandButton value="reset" action="{!resetForm}" />
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!Registration_Forum.Name}" />
<apex:inputField value="{!Registration_Forum.age__c}" />
<apex:inputField value="{!Registration_Forum.Certification__c}" />
<apex:inputField value="{!Registration_Forum.Project_Unit__c}" />
<apex:selectRadio value="{!Registration_Forum.Gender__c}">
<apex:selectOption itemValue="Male" itemLabel="Male" />
<apex:selectOption itemValue="Female" itemLabel="Female" />
</apex:selectRadio>
<apex:inputFile id="file" value="{!fileBody}" filename="{!fileName}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class VFFileUpload
{
public Registration_Forum__c Registration_Forum{get;set;}
public String fileName {get;set;}
public Blob fileBody {get;set;}
public VFFileUpload() {
Registration_Forum=new Registration_Forum__c();
}
public void saveForm(){
upsert Registration_Forum;
if(fileBody != null && fileName != null && Registration_Forum.id!=null)
{
Attachment myAttachment = new Attachment();
myAttachment.Body = fileBody;
myAttachment.Name = fileName;
myAttachment.ParentId = Registration_Forum.Id;
upsert myAttachment;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'File Upload Success'));
}
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Form Submission Success'));
}
public void resetForm(){
Registration_Forum=new Registration_Forum__c();
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Reset'));
}
}

Update Models after save without refreshing

I'm building a list in my app, which users can add to. Once they add their item and hit the save button, I would like the item they added to appear instantly on the list, and for the input box to clear. Here is my save function in my controller. It works fine when I reload the page but I think there is a way to bind by updating the model through the database. Thank you!
export class QuestionDetailsController {
public question;
public answer;
public id;
public save() {
this.answerService.save(this.answer, this.question.id).then(() => { this.$location.path("$location.path") });//how to update models?
}
constructor(
private answerService: MyApp.Services.AnswerService, private $location: angular.ILocationService, private questionService: MyApp.Services.QuestionService, $routeParams: ng.route.IRouteParamsService)
{
this.question = this.questionService.get($routeParams["id"])
}
And now HTML page
<!--<legend id="qdLegend">{{controller.question.title}}</legend>-->
<h2 id="qdLegend">{{controller.question.title}}</h2>
<hr id="qdhr" />
<div id="questionDiv">
<div class="col-md-7" id="questionBody">
<p>{{controller.question.userQuestion}}</p><br /><br />
</div>
</div>
<div class="col-md-7">
<div id="answerDiv" ng-repeat="a in controller.question.answers">
{{a.userAnswer}} --answered by {{a.userName}}
</div>
</div>
<form ng-submit="controller.save()">
<div>
<div class="form-group col-md-7" id="answerBox">
<label class="control-label" for="textarea">Your Answer</label>
<textarea ng-model="controller.answer.userAnswer" class="form-control" id="textarea1" name="textarea"></textarea>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="button1id"></label>
<div class="col-md-8" id="detailsButtons">
<button type="submit" id="button1id" name="Save" class="btn btn-success">Save</button>
<button id="button2id" name="button2id" class="btn btn-danger">Cancel</button>
</div>
</div>
</div>
</form>
Okay, I don't have a running typescript compiler at the moment, so I'll give you some hints and some untested code here.
public save() {
this.answerService.save(this.answer, this.question.id)
.then(() => {
this.question.answers.push(angular.copy(this.answer));
this.answer = {};
});
}
When the service returns succes you add the answer the the questions list of answers. I use angular.copy() to break the references so you can add multiple answers with no references issues.
After this I just overwrite the object with an empty one.
This is fairly simple. AngularJS docs have an example in the same style.
Here is a simplified plunker showing the action with a javascript controller. This should be no problem for you to get a hold of how it should be done.
As a note to the question, please supply minified examples to make it faster to understand your question.

show a hidden element after user login with angularjs

Iam relatively new to angularjs and jquery mobile.I was asked to do research for my next project on these framework and so Iam trying to achieve certain functionalities.I have created a front page where an element is hidden,this page will be shown initially.Then clicking on login ,the user will be redirected to login page,where he provides username password to log in.Then he will be redirected to the same front page but i want the hidden element to be visible.Can you help me with this.My element is always hidden and I cant figure out what Iam doing wrong.The tag with hi welcome user text must be visible after log in
Here's my html front page
<div data-role="page" id="panel-responsive-page1" data-title="Panel responsive page" data-url="panel-responsive-page1">
<div role="main" class="ui-content">
/**some content **/
<div class="ui-grid-solo" ng-controller="LoginCtrl" >
<p ng-hide="userWelcome">Hi welcome User </p>
</div>
</div>
<div data-role="panel" id="nav-panel">
<ul data-role="listview">
<li>Login</li>
<li>Register</li>
</ul>
</div>
</div>
On clicking login,i will be redirected to login page
<div data-role="page" id="login-form">
<!-- header -->
<div data-role="header" class="backgroundColorPink">
<h1>Login Form</h1>
</div>
<!-- Form Content -->
<div role="main" class="ui-content jqm-content">
<form class="userform">
<h2>Login</h2>
<label for="name">Username:</label>
<input type="text" name="name" id="name" value="" data-clear-btn="true" data-mini="true" ng-model="userDetails.name">
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" data-clear-btn="true" autocomplete="off" data-mini="true" ng-model="userDetails.password">
<div class="ui-grid-a" ng-controller="LoginCtrl">
<div class="ui-block-a">Cancel</div>
<div class="ui-block-b ">Save</div>
</div>
</form>
</div>
</div>
On clicking save,i will isssue a Ajax call and on successful login i will be redirected to the front page,and my login element must be visible.
Hers my controller
angular.module('jQMDemo', [])
function LoginCtrl($scope,$http,$window) {
$scope.userWelcome=true;
$scope.userLogin = function() {
var data={username: $scope.userDetails.name, password: $scope.userDetails.password, callfrom: "Portal"} ;
$http.post('url',data).success(function(data,status) {
alert(data.status);
if(data.status=="success"){
$window.location.href='#panel-responsive-page1';
$scope.userWelcome=false;
}
});
}
}
I might be using the controller wrong or maybe wrong usage of ng-hide..Please help,I cant figure it out
<div ng-show="element.show">
<!--codes-->
</div>
This will show if the element exists in your controller else it
will stay hidden
You can use this, so when you click on the button if everything
is good and the user is logged u create the element and then let the
class controller do the work for you
I achieved the functionality using toggleclass
I added this code in the controller:
$(".userWelcome").toggleClass("show");
And this in my HTML
<div class="ui-grid-solo hide userWelcome backgroundColorPink " >
<p class="alignMiddle ">Hi welcome {{userDetails.name}} </p>
</div>
I was able to get the desired result.If anyone else have any other way to achieve this,Please suggest

sending ids to controller and saving..?

<apex:commandlink action="{!removeline}" onclick="if(confirm('Are you sure?')) " reRender="thePB" target="_top" > <img src="{!$Resource.Red_Cross}" alt="Remove" title="Remove" />
<apex:param name="deleteid" value="{!op.Id}" assignTo="{!deleteid}"/>
</apex:commandlink >
I have cross image in front of every record.on click of that i am sending id to the controller.but the problem is when i click on cross 2 records and then click on delete button only 1 record is deleted.Can anyone suggest me how to save ids(more than 1 record) in controller and delete records on delete click.I am learning salesforce
You can use with the actionFunction and send the ids ​​by javaScript
Something like
<script>
function removelines(){
var deleteIds = ....;
removeline(deleteIds )
</script>
<input type="button" class="btn" onClick="onclick="if(confirm('Are you sure?'))"/>
<apex:actionFunction action="{!removeline}" name="removeline">
<apex:param name="deleteIds" assignTo="{!deleteIds}" value="" />
</apex:actionFunction>

Resources