Apex Class Extension: Updating related field using standard controller - class

I am relatively new to Apex:
Im trying to save a related field via my visualforce page, the apex class currently in use returns this error:
Update failed. First exception on row 0 with id 000000000000000; first error: INVALID_ID_FIELD, record id cannot be empty key: []
Error is in expression '{!save}' in component in page masseditcontact: Class.ContactExt.save: line 28, column 1
What I have tried so far is to refer to the field on my visualforce page - Contact.Account.Organization_Size__c - however when I try and update it with the save method in my class it seems to throw the error above.
public class ContactExt {
public Contact record {get; set;}
public String city {
get {
return record.Account.Organization_Size__c;
}
private set;
}
public ContactExt(ApexPages.StandardSetController controller) {
record = (Contact)controller.getRecord();
}
public PageReference save(){
update record
//try{
//update record;
//}
//catch (QueryException e)
//{
//record = new Contact();
//}
return null;
}
}
Visualforce markup
<apex:page standardController="Contact" extensions="ContactExt" recordSetVar="unused" sidebar="true" showHeader="true">
<apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme4d' || contains($CurrentPage.URL, 'lightning.force.com')}">
<apex:stylesheet value="{!URLFOR($Resource.SLDS221, 'assets/styles/salesforce-lightning-design-system-vf.min.css')}" />
<apex:stylesheet value="{!$Resource.MassEditCSS}" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"></link>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"></link>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</apex:outputPanel>
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:includeScript value="{!$Resource.LightningMassEditJS}" />
<apex:includeScript value="support/api/42.0/interaction.js"/>
<apex:includeScript value="support/console/42.0/integration.js"/>
<div class="mass-update-mass-edit" id="mass-update-mass-edit">
<div role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open" id="cancel-modal">
<div class="slds-modal__container">
<div class="slds-modal__header">
<button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="closeCancelModal();">
<svg class="slds-button__icon slds-button__icon--large" aria-hidden="true">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="{!URLFOR($Resource.SLDS221, '/assets/icons/utility-sprite/svg/symbols.svg#close')}"></use>
</svg>
<span class="slds-assistive-text">Close</span>
</button>
<h2 id="header43" class="slds-text-heading--medium">Return</h2>
</div>
<div class="slds-modal__content slds-p-around--medium">
<p>Are you sure you wish to return?</p>
</div>
<div class="slds-modal__footer">
<button class="slds-button slds-button--neutral" onclick="closeCancelModal();">No</button>
<button class="slds-button slds-button--brand" onclick="goBack();">Yes</button>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open" id="cancel-modal-backdrop"></div>
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first.
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:outputPanel rendered="{!$User.UIThemeDisplayed == 'Theme4d' || contains($CurrentPage.URL, 'lightning.force.com')}">
<apex:commandButton value="Save" action="{!save}" status="lightningSavingStatus" reRender="table" styleClass="slds-button slds-button--neutral slds-button--brand" />
<apex:commandButton value="Return" onclick="openCancelModal();" styleClass="slds-button slds-button--neutral" reRender="table" />
<apex:actionStatus id="lightningSavingStatus" >
<apex:facet name="start" >
<div id="spinning" class="slds-spinner_container">
<div class="slds-spinner--brand slds-spinner slds-spinner--medium" role="alert">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</div>
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
<apex:outputPanel rendered="{!$User.UIThemeDisplayed != 'Theme4d' && !contains($CurrentPage.URL, 'lightning.force.com')}">
<apex:commandButton value="Save" action="{!save}" status="savingStatus" reRender="table" />
<apex:commandButton value="Return" action="{!cancel}" onclick="return confirmCancel()" />
<apex:actionStatus id="savingStatus" >
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="a" id="table">
<apex:column headerValue="Name">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Phone">
<support:clickToDial number="{!a.Phone}" entityId="{!a.Id}"/>
</apex:column>
<apex:column headerValue="Mobile Phone">
<apex:inputField value="{!a.MobilePhone}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!a.Email}"/>
</apex:column>
<apex:column headerValue="Title">
<apex:inputField value="{!a.Title}"/>
</apex:column>
<apex:column headerValue="Account">
<apex:inputField value="{!a.AccountId}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputField value="{!a.Description}"/>
</apex:column>
<apex:column headerValue="Organisation Size">
<apex:inputField value="{!a.Organization_Size__c}"/>
</apex:column>
<apex:column headerValue="Organisation Size">
<apex:inputField value="{!a.Account.Organization_Size__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</div>

Related

Orbeon + jsf -> submit in selectonemenu

I have a problem with xforms, how refresh only rich:panel when I choose value from h:selectOneMenu :
<!--<h:form> call bean but--> <form><!--open start page-->
<h:selectOneMenu id="add" onchange="submit()" <!-- can't find context , error orbeon/java--> >
<!-- is not working <a4j:support event="onchange" actionListener="#{bean.action}"/> -->
<s:selectItems value="#{bean.List()}" var="message" itemValue="#{message}" label="#{message}" />
</h:selectOneMenu>
</form>
more Code JSF :
<form>
<rich:panel styleClass="DocumentBody" id="documentPanel"
name="panell" style="margin-top:10px; height:90px;">
<f:facet styleClass="documentHeader" name="header"></f:facet>
<div id="documentTest" class="actionButtons">
<div style="clear: both; height: 15px; width: 60px" />
<s:button id="addButton" value="#{messages['operation.save.button']}"
action="#{actionBean.generateNewName()}" reRender="confirm"
onclick="#{actionBean.generateNewName()};#{rich:component('confirm')}.show();return false;">
</s:button>
<s:button id="loadButton" value="#{messages['operation.load.button']}"
action="#{actionBean.loadDraft()}" reRender="documentTests,documentPanel,loadButton" />
<s:button id="deleteButton" value="#{messages['operation.delete.button']}"
action="#{actionBean.deleteDraft()}" reRender="documentTests,documentPanel,deleteButton" />
</div>
</rich:panel>
</form>
<h:form style="margin: 0;">
<h:selectOneMenu id="messageTypeAdd"
style="margin-right:5px; margin-top:-30px;margin-left:90px;"
valueChangeListener="#{actionBean.documentTestChange}"
enableManualInput="false" selectFirstOnUpdate="true"
directInputSuggestions="true" onchange="submit()">
<!-- submit() rerender all page, but i try refresh only modalPanel id="confirm" -->
<s:selectItems value="#{actionBean.getdocumentTestList()}"
var="message" itemValue="#{message}" label="#{message}" />
<!--a4j and f:ajax is not work, i try update JSF 1.2 to 2.0 -->
</h:selectOneMenu>
</h:form>
<rich:modalPanel id="confirm" autosized="true" width="300">
<f:facet name="header"></f:facet>
<rich:messages style="color:red;" globalOnly="true" />
<a4j:outputPanel ajaxRendered="true">
<h:panelGrid>
<h:panelGrid columns="2">
<h:outputText value="#{messages['report.name.label']}" />
<h:inputText id="newDraftNameInput" value="#{actionBean.newDraftName}"
valueChangeListener="#{actionBean.newDraftNameChange}">
</h:inputText>
</h:panelGrid>
</h:panelGrid>
</a4j:outputPanel>
</rich:modalPanel>

GWT custom widget taking too long to create

I've a view which displays a list of custom tweeter feed like widgets. Following is the template for the widget:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style type="com.ziplly.app.client.widget.TweetWidget.Style"
src="tweetwidget.css">
</ui:style>
<ui:with type="com.ziplly.app.client.resource.ZResources" field="resources"/>
<g:HTMLPanel ui:field="tweetPanel" addStyleNames="{style.tweetPanel}">
<div class='{style.tweet_block}'>
<div class='{style.tweet_image}'>
<b:Image ui:field="authorImage" />
</div>
<div class='{style.tweet_content_section}'>
<div class="{style.tweetActionDropdown}">
<b:Dropdown text="edit">
<b:NavLink ui:field="editTweetLink">Edit</b:NavLink>
<b:NavLink ui:field="deleteTweetLink">Delete</b:NavLink>
<b:NavLink ui:field="reportSpamLink">Report Spam</b:NavLink>
</b:Dropdown>
</div>
<div class="{style.tweet_content}">
<span class='{style.tweet_text}' ui:field="tweetContentSpan" />
<b:TextArea ui:field="tweetContentTextArea"
addStyleNames="{style.tweetContentTextArea}" />
<g:HTMLPanel ui:field="tweetEditButtonPanel">
<b:Button type="PRIMARY" size="SMALL" ui:field="saveBtn">save</b:Button>
<b:Button size="SMALL" ui:field="cancelBtn">cancel</b:Button>
</g:HTMLPanel>
</div>
<div class='tweet_actions'>
<div>
<div class='{style.tweet_action_link}'>
<g:Anchor ui:field="likeTweetLink" addStyleNames="{style.smalltext}">Like</g:Anchor>
</div>
<div class='{style.tweet_action_link}'>
<g:Anchor ui:field="commentLink" addStyleNames="{style.smalltext}">Comment</g:Anchor>
</div>
<div class='{style.tweet_sender_link}'>
posted by
<g:Anchor ui:field="authorProfileLink">
<span class="smalltext" ui:field="authorName" />
</g:Anchor>
on
<span ui:field="timeCreated" />
</div>
</div>
</div>
</div>
</div>
<g:HTMLPanel addStyleNames="{style.people_liked_section}" ui:field="tweetLikePanel">
</g:HTMLPanel>
<div class="{style.commentSectionDiv}">
<g:HTMLPanel addStyleNames="{style.tweetCommentSection}" ui:field="tweetCommentSection">
</g:HTMLPanel>
<g:HTMLPanel>
<b:TextArea ui:field="commentInputTextBox" addStyleNames="{style.commentInputTextBox}" />
<div class="{style.commentInputActionSection}">
<b:Button type="PRIMARY" size="SMALL" ui:field="commentBtn">comment</b:Button>
<b:Button size="SMALL" ui:field="cancelCommentBtn">cancel</b:Button>
</div>
</g:HTMLPanel>
</div>
</g:HTMLPanel>
</ui:UiBinder>
I'm using something like following to populate the view:
final long time1 = System.currentTimeMillis();
for (final TweetDTO tweet : tweets) {
final long time11 = System.currentTimeMillis();
final TweetWidget tw = new TweetWidget();
tw.setWidth(tweetWidth);
final long time12 = System.currentTimeMillis();
tw.setPresenter(presenter);
tw.displayTweet(tweet);
final long time13 = System.currentTimeMillis();
communityWallPanel.add(tw);
final long time14 = System.currentTimeMillis();
System.out.println("Time to create tweet widget: " + (time12 - time11) + " to render: " + (time13 - time12) + " to addToPanel: " + (time14 - time13));
tweetWidgetMap.put(tweet.getTweetId(), tw);
}
final long time2 = System.currentTimeMillis();
System.out.println("Time to render wall: " + (time2 - time1));
On an average I'm seeing about 300+ milli seconds to render each widget on the page. Out of the 300 ms, 280+ is taken to create that template. It seems unreasonably long time for creating a widget from template. Any help will be appreciated.

how to pass a parameter from search container column text from one jsp to another jsp?

hai i need to pass parameters from one jsp in the search-container-column-text to another jsp. i have displayed the results and i have added hyperlink at last of the column when it click it will open the edit.jsp page and i need to pass the courseid to that edit.jsp from the result.jsp. can any one tell me the solution?
edit.jsp
<%
PortletURL editCourseURL=renderResponse.createActionURL();
editCourseURL.setParameter(ActionRequest.ACTION_NAME,"editCourse");
%>
<%
String ns =renderRequest.getParameter("courseId");
System.out.println("hai hello "+ns);
//long n= Long.parseLong(ns);
System.out.println("hello world");
Course courses =CourseLocalServiceUtil.getCourse(3);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//sdf = new SimpleDateFormat("yyyy-MM-dd");
String sdate = sdf.format(courses.getSdate());
String edate = sdf.format(courses.getEdate());
String cname=courses.getCname();
String cdesc=courses.getCdesc();
System.out.println(sdate);
%>
<form action="<%=editCourseURL%>" method="post" id="register-form" >
<div class="label1">Course Name</div>
<input type="text" id="cname" name="cname" value="<%=cname%>"/><br />
<div class="label2">Course Description</div>
<input type="text" id="cdesc" name="cdesc" value="<%=cdesc%>"/><br/>
<div class="label3">Start Date</div>
<input type="date" name="sdate" id="sdate" value="<%=sdate%>"/><br/>
<div class="label4">End Date</div>
<input type="date" id="edate" name="edate" value="<%=edate%>" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<portlet:renderURL var="homeURL">
<portlet:param name="jspPage" value="/html/course/view.jsp"></portlet:param>
</portlet:renderURL>
--HOME--
result.jsp:
<%
int n=CourseLocalServiceUtil.getCoursesCount();
List courses = CourseLocalServiceUtil.getCourses(0,n);
if(Validator.isNull(courses))courses = new ArrayList();
%>
<portlet:renderURL var="edit">
<portlet:param name="jspPage" value="/html/course/edit.jsp"></portlet:param>
</portlet:renderURL>
<portlet:renderURL var="delete">
<portlet:param name="jspPage" value="/html/course/delete.jsp"></portlet:param>
</portlet:renderURL>
<liferay-ui:search-container delta="10" emptyResultsMessage="no-courses-were-found" >
<liferay-ui:search-container-results results="<%=courses%>" total="<%=courses.size()%>" />
<liferay-ui:search-container-row className="com.course.slayer.model.Course" modelVar="course" >
<liferay-ui:search-container-column-text name="Course Name" property="cname" />
<liferay-ui:search-container-column-text name="Course Description" property="cdesc" />
<liferay-ui:search-container-column-text name="Start Date" property="sdate" />
<liferay-ui:search-container-column-text name="End Date" property="edate" />
<liferay-ui:search-container-column-text name="Edit" href="<%=edit%>" value="edit">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="Delete" href="<%=delete%>" value="delete" />
</liferay-ui:search-container-row >
<liferay-ui:search-iterator />
</liferay-ui:search-container >
result.jsp:
You can pass parameter like this :-
<portlet:renderURL var="edit">
<portlet:param name="jspPage" value="/html/course/edit.jsp"></portlet:param>
<portlet:param name="courseName" value="<%=courseName%>"></portlet:param>
</portlet:renderURL>
<portlet:renderURL var="delete">
<portlet:param name="jspPage" value="/html/course/delete.jsp"></portlet:param>
<portlet:param name="courseName" value="<%=courseName%>"></portlet:param>
</portlet:renderURL>
HTH

get value checkbox in zk

i have a grid with list checkbox
<div height="200px">
<grid id ="actListBox" model="#bind(vm.actions)" >
<template name="model">
<row style=" width:200px !important; ">
<cell rowspan="5" align="left" >
<checkbox style="height: 70px; width:1000px; overflow: auto; margin-left:10px;"
label="${each.action_name}" id ="${each.actionid}" value ="${each.actionid}" />
</cell>
</row>
</template>
</grid>
<span>
<checkbox label="Check all" value ="checkall" id="chkAll"/>
</span>
</div>
and now i want get all value of checkbox but i can't found anyway
please help me
thanks all
You can in your composer get checked Ids by iterating over actions:
#Command
public void checkedIds(final Event e){
final StringBuilder builder = new StringBuilder("Checked Ids: ");
for (final Action action : actions) {
if (action.getChecked()) {
builder.append(action.getId()).append(' ');
}
}
Messagebox.show(builder.toString());
}
I updated the ZK fiddle.

synchronization validation and display of dialog in a PrimeFaces JSF2.0 form

I have a form with jsf2 and primefaces that contains a submit button that managed two things:
First: form validation with the update attribute and second launching a confirmation dialog box when validation succeeded and all of this are managed by:
update="myfieldset display"
so my problem is that when I click into the button validation: if validation don't succeeded : validation messages are displayed in the form : ok
but if the validation succeeded I must click a second time to display dialog box
anyone know how to solve this problem there?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<script type="text/javascript">
<!--
function effacer(formulaire){
for (var i=0; i<formulaire.length; i++){
if (formulaire.elements[i].type=="input" || formulaire.elements[i].type=="textarea" ) {formulaire.elements[i].value="";}
}
document.getElementById('contenu_input').value="";
}
//-->
</script>
<body>
<ui:composition template="./template_utilisateur.xhtml">
<ui:define name="content">
<h:form id="form" prependId="false" >
<p:fieldset id="myfieldset" legend="Nouveau message">
<p:messages id="msgs"/>
<h:panelGrid columns="3" style="margin-bottom:10px">
<h:outputLabel for="title" value="Titre : *"/>
<p:inputText id="title" style="width:340px;" value="#{messageController.titre}" required="true" requiredMessage="veuillez saisir un titre" label="Titre">
<f:validateLength minimum="10" />
</p:inputText>
<p:message for="title" display="icon"/>
<h:outputLabel for="city" value="Destinataire : *" />
<p:selectOneMenu id="city" value="#{messageController.destinataire}" label="Destinataire" required="true" requiredMessage="veuillez choisir au moins un destinataire" >
<f:selectItem itemLabel="Séléctionner déstinataire" itemValue="" />
<f:selectItems value="#{messageController.users}" />
</p:selectOneMenu>
<p:message for="city" id="msgSurname3" display="icon"/>
<h:outputLabel for="comm" value="Lié a La commande N° : " />
<p:selectOneMenu id="comm" label="Commande" value="#{messageController.idComm}" >
<f:selectItem itemLabel="Aucune commande" itemValue="" />
<f:selectItems value="#{messageController.id_c}" />
</p:selectOneMenu>
<p:message for="comm" id="msgSurnamse3" display="icon"/>
</h:panelGrid>
<h:outputLabel for="contenu" value="Contenu : *" />
<h:panelGrid columns="2">
<p:editor id="contenu" widgetVar="editer" value="#{messageController.message}" width="600" required="true" requiredMessage="Veuillez saisir le contenu du message" >
<f:validateLength minimum="10" />
</p:editor>
<p:message for="contenu" id="editorm" display="icon"/>
</h:panelGrid>
<h:panelGrid columns="3">
<p:commandButton id="submitButton" value="envoyer" update="myfieldset display" onclick="#{messageController.retournerDialog()}" icon="ui-icon-disk" />
<p:commandButton id="clearButton" type="reset" value="initialiser" onclick="editer.clear()"
icon="ui-icon-close" />
</h:panelGrid>
</p:fieldset>
<p:dialog header="Confirmation" widgetVar="dlg" showEffect="fade" hideEffect="fade" modal="true">
<h:panelGrid id="display" columns="1" cellpadding="4">
<h:outputText value="Titre : " />
<h:outputText value="#{messageController.titre}" id="model"/>
<h:outputText value="Déstinataire :" />
<h:outputText value="#{messageController.destinataire}" id="year"/>
<h:outputText value="Lié à la commande N° : " />
<h:outputText value="#{messageController.idComm}" id="manufacturer"/>
<h:outputText value="Contenu :" />
<h:outputText id="displxcay" value="#{messageController.message}" escape="false" />
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
and here the method to launch the dialog
public String retournerDialog(){
String retour = "";
if( getDestinataire() != "" && getMessage()!= "" && getTitre()!="" && getMessage().length()>9 && getTitre().length()>9){
retour="dlg.show()";
}
return retour;
}
thank you in advance
Update: thank you BalusC for your detailed response, I tested both of your answers but they don't work
here is the code of the button :
<p:commandButton id="submitButton" value="envoyer" update="myfieldset, display" action="#{messageController.showDialog}" icon="ui-icon-disk" />
and the managedBean :
private boolean showDialog;
public void showDialog() {
showDialog = true;
}
public boolean isShowDialog() {
return showDialog;
}
and with this code above the dialog doesn't appear even if validation is succeeded
: I think because action must return outcome string not boolean
and when I make :
<p:commandButton id="submitButton" value="envoyer" update="myfieldset, display" onclick="dlg.show();" icon="ui-icon-disk" />
it appear even if the validation failed
and to remind you
when I put a method above like this :
<p:commandButton id="submitButton" value="envoyer" update="myfieldset, display" onclick="#{messageController.retournerDialog()}" icon="ui-icon-disk" />
I have to click twice (I think one for validation and one for displaying dialog)for the dialog is displayed
also in the official documentation : they use this dialog with onclick attribute
do you have any other idea