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
vanessa veronvanessa veron 

Get value into pageBlockTable

Hello...

I tried to get a value into pageBlockTable and to delete the line table (a job)... but the job isnt deleted.
Why??

Thank you
public String strJobName {get;set;}

//CONSTRUTOR:
global Class() {strJobName='';}

public void deleteJob() {
if(strJobName != '')
{
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: strJobName];
    System.abortJob(idJobDel[0].id);
   }
   else
{
system.debug('NOT NAME');
}
}

PAGE:

          <apex:actionfunction name="callDeleteJob" action="deleteJob" rerender="pbBlockTable">
              <apex:param name="JobName" value="" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column><apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}')"/> </apex:column>
                  
              </apex:pageBlockTable>

Best Answer chosen by vanessa veron
EnreecoEnreeco
Try at first to use this method is get if a string is blank (is more secure):
if(!String.isBlank(strJobName))
instead of
if(strJobName != '')
And try this:
<apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;"/>

If no "action" is set for the commandButton, there will be a postback that "cancels" the "callDeleteJob" call. in this way (the "return false;" in the onClick) you are sure that only the callDeleteJob callback is working.
Hope this helps

--
May the Force.com be with you


All Answers

EnreecoEnreeco
Try at first to use this method is get if a string is blank (is more secure):
if(!String.isBlank(strJobName))
instead of
if(strJobName != '')
And try this:
<apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;"/>

If no "action" is set for the commandButton, there will be a postback that "cancels" the "callDeleteJob" call. in this way (the "return false;" in the onClick) you are sure that only the callDeleteJob callback is working.
Hope this helps

--
May the Force.com be with you


This was selected as the best answer
vanessa veronvanessa veron
Thank you ForceLogic! IT WORKED...
but the page isn't refreshed:

Why??? I used  oncomplete="refreshPage();"

The code:

APEX:

public void deleteJob() {

if(!String.isBlank(strJobName))
{
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: strJobName];
    System.abortJob(idJobDel[0].id);
}
else
{
system.debug('NOT Job Name');
}
   }

---------------------------------------------------------------------------------------------------------

PAGE:

<script>
function refreshPage(){
    location.reload(0);
    return false;
}

</script>

          <apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="pbBlockTable">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Nom de la Tâche" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Status" value="{!ac.State}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                <apex:column >

                <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" oncomplete="refreshPage();"/></apex:column>
                  
              </apex:pageBlockTable>



EnreecoEnreeco
If you want the page reload you can use remove the "rerender" attribute in the apex:actionFunction component and it should rerender the page
vanessa veronvanessa veron
I used:

<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="pbBlockTable">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
EnreecoEnreeco
If have to remove the rerender attribute
<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" >
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>

vanessa veronvanessa veron
I removed rerender="pbBlockTable" but after the job isnt   deleted...
EnreecoEnreeco
Oh you're right, the rerender is necessary to pass the parameter and make a succesfull callbak.
The rerender will rerender only the "pbBlockTable", but sometimes I found a bug that made the pabeblockTable not rerendering.
To bypass this, I create an <apex:outputPanel id="aNewPanel"/> that contains the apex:pageBlockTable and the rerender will be with this component.
Try this
vanessa veronvanessa veron
I tried, but the page isnt refreshed:

<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="pbBlockTable">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:outputPanel id="aNewPanel">
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column >
                <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" oncomplete="refreshPage();"/></apex:column>
                  
              </apex:pageBlockTable>
              </apex:outputPanel>

EnreecoEnreeco
<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="aNewPanel">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:outputPanel id="aNewPanel">
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column >
                <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" oncomplete="refreshPage();"/></apex:column>
                  
              </apex:pageBlockTable>
              </apex:outputPanel>

vanessa veronvanessa veron
Thank you, but the page isnt refreshed!!! =s

I used:
<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="aNewPanel">
EnreecoEnreeco
Maybe because you are rerender all the content and the oncomplete isn't invoked.
Try this:
<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="aNewPanel">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:outputPanel id="aNewPanel"></apexOutputPanel>
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column >
                <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" oncomplete="refreshPage();"/></apex:column>
                  
              </apex:pageBlockTable>
Or else you can rerende the whole form:

<apex:form id="theForm">
<!-- here is another content -->
<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="theForm">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>

          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Name Job" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column >
                <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" oncomplete="refreshPage();"/></apex:column>
                  
              </apex:pageBlockTable>

<!-- here is another content -->
</apex:form>


EnreecoEnreeco
With the second choise the whole page content is rerender (you don't see the page loading)
vanessa veronvanessa veron
I tried the 2, but the page isnt refreshed sorry!
vanessa veronvanessa veron
The oncomplete="refreshPage();" is a good option for refresh a page???
EnreecoEnreeco
are u having javascript errors?
vanessa veronvanessa veron
The fonction JS to refresh page:

<script>
function refreshPage(){
    location.reload(0);
    return false;
}
</script>
EnreecoEnreeco
Your browser JS console is throwing errors?
vanessa veronvanessa veron
No!
EnreecoEnreeco
Mybe you simply have to query again the jobRecords list after you delete a job so you will see the new list when the actionFunction rerenders.
vanessa veronvanessa veron
Thank you so much....
I will try this after...

I have to go now!!!!
THANK YOUUUUUUUU!
EnreecoEnreeco
U're welcome!
vanessa veronvanessa veron
Hiii

I'm still having the same problem and I added a new button also not run the action that I desire.

Help me!

<apex:column >
                    <apex:commandButton value="M" action="{!modifier}"/>
                </apex:column>

vanessa veronvanessa veron
Hello!!!

It work now...

I used: oncomplete="refreshPage(); into actionfunction declaration

<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="panelRefresh" oncomplete="refreshPage();">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
But the modify dont work!!!
EnreecoEnreeco
Oh I got confufed either: this is the right solution!
Bye
Enrico
vanessa veronvanessa veron
I have another actionfunction into PageBlock, but the method dont work!

...the code:

<apex:actionfunction name="callDeleteJob" action="{!deleteJob}" rerender="panelRefresh" oncomplete="refreshPage();">
            <apex:param value="" name="ParamNom" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:actionfunction name="callModify" action="{!modifier}" >
            <apex:param value="" name="ParamModify" assignTo="{!strJobName}" />
          </apex:actionFunction>
          
          <apex:outputPanel id="panelRefresh"></apex:OutputPanel>
          <apex:pageBlockTable value="{!jobRecords}" var="ac" id="pbBlockTable">
              <apex:column headervalue="Nom de la Tâche" value="{!ac.CronJobDetail.Name}"/>
                <apex:column headervalue="Expression" value="{!ac.CronExpression}"/>
                
                <apex:column >
                    <apex:commandButton value="X" onClick="callDeleteJob('{!ac.CronJobDetail.Name}'); return false;" />
                </apex:column>
                
                 <apex:column >
                    <apex:commandButton value="M" onClick="callModify(); return false;"/>
                </apex:column>
                  
              </apex:pageBlockTable>

APEX::

public void modifier(){

PageCreer();

}


public void deleteJob() {

if(!String.isBlank(strJobName))
{
    idJobDel= new List<CronTrigger>();
    idJobDel= [SELECT  Id FROM CronTrigger where CronJobDetail.Name =: strJobName];
    System.abortJob(idJobDel[0].id);
}
else
{
system.debug('NOT Job Name');
}
   }


public PageReference PageCreer() {
    return Page.BBBBPage2;
}