I have a string list in my controller
public List<String> m_lstChosenCloneOptions{get;set;}
with the following code in the page
<apex:selectCheckboxes value="{!m_lstChosenCloneItems}" layout="pageDirection">
<apex:selectOptions value="{!CloneOptions}" />
</apex:selectCheckboxes>
There are 3 options and I default all of the to checked by putting the keys into m_lstChosenCloneItems. It works because the page displays with all the items checked. I also have a button that when clicked starts a cloning process. However, the first line in the controller is a System.Debug(m_lstChosenCloneItems); and it displays as empty. I'm not sure how at the final line of the constructor the list is filled with the options but just clicking the button right after the page loads, the list is empty.
Update: I added the type above it is a public list.
Here is the button and controller:
<apex:commandButton value="Clone Project" action="{!cloneProject}" rerender="messagepanel"/>
public void cloneProject()
{
System.Debug(m_lstChosenCloneOptions);
}
FYI I was able to "fix" this by adding a javascript that grabs the checkboxes and passes in their values to an apex:param. But I'm still curious why the binding with the list isn't working. Maybe the function being void is the issue?
Related
I am using VS code. Trying to render a button with a button click event. The code is as below
<apex:page controller="OnAuthorizeController">
<apex:form>
<apex:commandButton value="Get token" action="{!getToken}" />
</apex:form>
</apex:page>
public with sharing class OnAuthorizeController {
public void getToken(){
string str = 'dummy code'; // break point here is never triggered
string str2 ='dummy code2';
}
}
I am trying to debug the codes inside a button-click event. Generated Apex debug logs and tried to debug but the breakpoints are only getting hit in the page load event. Once the page is rendered, it is impossible to debug the code inside the button click event. Trying to debug as described in this 4 mins video https://www.youtube.com/watch?v=dNBsYLfI1nk
I tried all the possible googling to debug the apex code with VS code. I expect to debug the code inside a button click event in apex page
I've got a form that fills a table in my database. Now i've added a dropdown to that form where the you can choose a user that should be associated to the rest of the form input. But im still unable to associate the dropdown to the user_id in the table.
I hope i made my issue clear,
The code that i just in my controller was :
public function store(PartRequest $request)
{
Project::find(Input::get('project'))->parts()->create($request->all());
return redirect('parts');
}
where my dropdown had classname:project
I am trying to pass a static resource URL, via the apex:param tag. The code I have so far is:
VisualForce:
<apex:selectList value="{!SelectedFamily}" onchange="renderGallery();" size="1" label="Product Family">
<apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScripts();">
<apex:param value="{!URLFOR($Resource.NoImage)}" assignTo="{!noImage}"/>
<apex:param value="{!URLFOR($Resource.NoImageThumb)}" assignTo="{!noImageThumb}"/>
</apex:actionFunction>
<apex:actionFunction name="renderScripts" rerender="scriptPanel">
</apex:actionFunction>
<apex:selectOptions value="{!Family}" />
</apex:selectList>
Controller:
public string noImage{ get; set; };
public string noImageThumb { get; set; }
My understanding of apex:param was that I would now be able to call the controller variables after the re-render had occurred and they would be populated with the static resource URL. But unfortunately I keep getting null.
Anyone have any idea why it isn't working?
It works if you provide names for your params --- Visualforce won't process params in this context unless they're named.
<apex:actionFunction name="renderGallery" rerender="gallery" oncomplete="renderScripts();">
<apex:param name="noImg" value="{!URLFOR($Resource.NoImage)}" assignTo="{!noImage}"/>
<apex:param name="noImgUrl" value="{!URLFOR($Resource.NoImageThumb)}" assignTo="{!noImageThumb}"/>
</apex:actionFunction>
If this doesn't work for you right away, please post the rest of your Visualforce code so that we can see where "gallery" and "scriptPanel" are in relation to your apex form tag --- getting rerender to work correctly is notoriously tricky, and entirely dependent on the hierarchical position of the DOM elements getting rerendered. To guarantee that gallery and scriptPanel successfully rerender, put them in separate outputPanels outside the apex form tag, like this:
<apex:outputPanel id="scriptPanel">
Selected Family: {!SelectedFamily}<br/>
</apex:outputPanel><br/><br/>
<apex:outputPanel id="gallery">
No Image: {!noImage}<br/>
No Image Thumb: {!noImageThumb}<br/>
</apex:outputPanel><br/><br/>
#MatthewKeefe, there's absolutely no reason why {!URLFOR()} can't be used as an extension variable --- it compiles to text (e.g. '/resource/123718923'), so Jim's solution here is actually pretty interesting, as it saves him from having to do a SOQL query on the StaticResource object in his controller.
{!URLFOR($Resource.NoImage)} is not meant to be used as a controller/extension variable. It is a direct reference to the static resource (no controller/extension required).
I would recommend you use output panels with a rendered property bound to an Apex variable that is controlled by the action function. That way you could show or hide each version of the image by showing or hiding the output panel.
Alternatively, you may want to look into using JavaScript Remoting for something like this.
I have a Vf page which shows a list in a apex:repeat tag. All the fields displayed are apex:inputfield. There are 2 fields
quantity__c
Change__c
I want to validate, if the quantity has changed then i want the change field should
be filled/mandatory. Can i do this validation at VF level?
Any other way of accomplishing this?
Thanks
Update: Here is code i am using as suggested by LaceySnr. I can see the apex message is thrown in the debug log but its not visible in Vfpage
for (integer i=0;i<List_FinalStdItems.size();i++)
{
system.debug('inside loop to check quantity is changed');
ItemSet.add(List_FinalStdItems[i].id);
system.debug('New quantity'+List_FinalStdItems[i].quantity__c +' old quantity'+MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c);
// system.debug('old quantity'+MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c);
if (MapStdItemsOldMap.get(List_FinalStdItems[i].id).quantity__c!=List_FinalStdItems[i].quantity__c)
{
system.debug('This quantity for item '+List_FinalStdItems[i].Name+ ' has changed');
if(List_FinalStdItems[i].Inventory_Change_Reason__c==null || List_FinalStdItems[i].Inventory_Change_Reason__c=='')
{
system.debug('This quantity for item '+List_FinalStdItems[i].Name+ ' has changed and Reason for change is empty');
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Reason for change not entered for changed Quantity'));
error=true;
}
}
}
01:04:55.541 (541902000)|SYSTEM_METHOD_ENTRY|[151]|ApexPages.addMessage(ApexPages.Message)
01:04:55.541 (541985000)|VF_PAGE_MESSAGE|Reason for change not entered for changed Quantity
01:04:55.542 (542008000)|SYSTEM_METHOD_EXIT|[151]|ApexPages.addMessage(ApexPages.Message)
Edit
<apex:outputpanel id="mess">
<apex:pageMessages />
</apex:outputpanel>
.
.
.
<apex:actionFunction name="save" action="{!Save}" rerender="mess"/>
You could do this through javascript directly, or you could use <apex:actionSupport> with the onChange event to refresh the second field, but to be honest I think the simplest and most robust way would be to just do the validation in the controller before saving a record.
Edit
I assume you have an <apex:pageMessages/> tag in the page, make sure you're rerendering it — i.e. if you're not doing a whole page refresh, put the messages tag in an output panel and specify that <apex:outputPanel> in the rerender attribute for your action.
Edit II
Is your action definitely returning a null Pagereference? Otherwise what you have looks correct. Are there any page blocks etc. between your action function and the output panel? If so you may need to drill down through an id hierarchy.
I have an MVC2 page that includes the following
Left Image
Right Image
When I save this page, I should be able to look at Request.Files to get the two file referenced. But the list is empty.
On the other hand, if I look at Request.Form, the two fields (for BackFile and FrontFile) are present.
Now, this portion of the form is part of the form that is partially updated when other selections on the form are made.
When I have had javascript references in such cases, I have had to also update the javascript references whenever I did a partial update of the page.
But there is no javascript reference to the "input" buttons. Still, I'm wondering if somehow, the "system" is losing the connection between the fields and their buttons and consequently not associating the input fields with files.
I don't know how to get around this.
Specifically is there a way I can proceed by using the values in Request.Form to do the uploads?
First: You cannot use the values from the Request.Form
Second: Did you change the enctype of the form as below:
<form action="home/upload" enctype="multipart/form-data" method="post">
<input type="file" name="uploader"></input>
<input type="submit" value="Save"></input>
</form>
Thrid: I you have a form as above you can create an action method in the controller like below
public class HomeController
{
[HttpPost]
public ActionResult UploadPictures(int id, HttpPostedFileBase ProductPhotoFileUpload)
{
//handle file save
return View();
}
}
Forth: The partial update should not matter