You need to sign in to do that
Don't have an account?
![Paul.Fox Paul.Fox](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Insert fails if commandLink has rerender attribute
I have created a simple page in Apex that shows my tasks for the day and gives me a place to add a new task.
However, I can't seem to get the commandLink or the form to create a new task if I use the rerender parameter.
This means that when I add a new Task the whole page refreshes, which takes a lot longer than just refreshing the task list.
Here's the snippet from the Apex Page:
Somewhere below this I have a <ul id="openTasks">. If I take off that rerender
Here's the AddTask method in the Controller:
I also need to figure out how to grab the new task subject if anyone wants to help me with that. I can't use the standard edit method because I don't want the standard subject field with the little pop-up box.
However, I can't seem to get the commandLink or the form to create a new task if I use the rerender parameter.
This means that when I add a new Task the whole page refreshes, which takes a lot longer than just refreshing the task list.
Here's the snippet from the Apex Page:
Code:
<apex:form id="AddTask"> <apex:inputText size="40" id="NewTask"/> <apex:commandLink value="Add Task" action="{!AddTask}" rerender="openTasks"/> </apex:form>
Here's the AddTask method in the Controller:
Code:
public PageReference AddTask() { Task newTask = new Task(Subject='xxx',Priority='Normal',Status='Not Started'); string NewTaskSubject = 'Hello'; //Need to change this to get value from field. newTask.subject = NewTaskSubject; insert(newTask); return null; }
I also need to figure out how to grab the new task subject if anyone wants to help me with that. I can't use the standard edit method because I don't want the standard subject field with the little pop-up box.
Message Edited by jwetzler on 10-30-2008 11:12 AM
Here's the pageBlock Table tag
Does your getOpenTasks method actually re-run the query? In other words maybe you want to set your openTasks list to null when your action method is called so the next time getOpenTasks is called it runs your query again.
When you say it doesn't create the task are you saying the create doesn't work, or it's just not showing up in the list?
I'm just speculating here because there isn't enough info for me to really know what's going on.
I cleaned up some of the other code and the commandButton now works even with the rerender.
However, how do I get it to work if someone just presses enter also?
Page:
Relevant Controller Methods:
By the way it's not necessary or recommended for you to have two forms on your page. You should encapsulate everything in one form tag. If you need to control which areas get submitted on a postback you want to look into using actionRegion.
My understanding of forms is that there is no problem with having multiple forms on the page. In fact if they have different functions they should be different forms. Is there something with visualforce that makes unnecessary or even bad?