#ViewScoped beans are not supported on stateless views - jsf

I have a page in JSF:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:param name="navLinkActive" value="poiAdder"/>
<ui:define name="content">
<h:outputStylesheet library="clock" name="clockpicker.css"/>
<h:outputScript library="clock" name="clockpicker.js"/>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<div class="col-md-12">
<ui:include src="/WEB-INF/lego/leftMenu.xhtml"/>
<div class="col-md-10">
<h:form id="poiForm" prependId="false" enctype="multipart/form-data">
<div class="col-md-6">
<h:outputLabel for="address"
value="Adres"/>
<h:inputText id="address"
styleClass="col-md-10"
value="#{poiAdderBean.poi.address}"
requiredMessage="#{msg.fieldRequired}"
required="true"/>
<input type="button"
class="btn btn-default"
value="#{msg.findAddress}"
onclick="codeAddress()"/>
<h:message for="address" style="display: block; color:red"/>
<h:outputLabel for="longitude"
value="Współrzędne (automatycznie)"/>
<h:outputLabel for="latitude"
styleClass="descriptionLabel"
value="podaj adres, a potem wybierz dokładną lokalizację na mapie, jeśli potrzebne"/>
<div class="col-md-12">
<h:inputText id="longitude"
styleClass="col-md-4 col-md-offset-2"
required="true"
requiredMessage="#{msg.fieldRequired}"
value="#{poiAdderBean.poi.longitude}"
converter="javax.faces.Double">
</h:inputText>
<h:inputText id="latitude"
styleClass="col-md-4"
required="true"
requiredMessage="#{msg.fieldRequired}"
value="#{poiAdderBean.poi.latitude}"
converter="javax.faces.Double">
</h:inputText>
</div>
<h:message for="latitude" style="display: block; color:red"/>
<h:message for="longitude" style="display: block; color:red"/>
<h:outputLabel for="poiTypeSelector"
value="Wybierz kategorię POI"/>
<h:selectOneMenu id="poiTypeSelector"
styleClass="btn"
value="#{poiAdderBean.poi.poiCategory}">
<f:selectItems value="#{poiAdderBean.poiCategoryList}"
var="poiCat"
itemLabel="#{msg['poi'.concat(poiCat)]}"
itemValue="#{poiCat}"/>
</h:selectOneMenu>
<h:outputLabel for="phoneNumber"
value="#{msg.phoneNumber}"/>
<h:inputText id="phoneNumber"
style="width: 350px"
value="#{poiAdderBean.poi.phone}"
validator="#{PhoneValidator.validate}">
</h:inputText>
<h:message for="phoneNumber" style="display: block; color:red"/>
<h:outputLabel for="linkwww1"
value="Link www #1"/>
<h:inputText id="linkwww1"
style="width: 350px"
value="#{poiAdderBean.poi.link}">
<f:validator validatorId="linkValidator"/>
<f:attribute name="linkDescritpion" value="#{description1}"/>
</h:inputText>
<h:message for="linkwww1" style="display: block; color:red"/>
<h:outputLabel for="linkwww1Description"
value="Opis #1"/>
<h:inputText id="linkwww1Description"
binding="#{description1}"
style="width: 350px"
value="#{poiAdderBean.poi.linkDescription}">
</h:inputText>
<h:message for="linkwww1Description" style="display: block; color:red"/>
<h:outputLabel for="linkwww2"
value="Link www #2"/>
<h:inputText id="linkwww2"
style="width: 350px"
value="#{poiAdderBean.poi.link2}">
<f:validator validatorId="linkValidator"/>
<f:attribute name="linkDescritpion" value="#{description2}"/>
</h:inputText>
<h:message for="linkwww2" style="display: block; color:red"/>
<h:outputLabel for="linkwww2Description"
value="Opis #2"/>
<h:inputText id="linkwww2Description"
binding="#{description2}"
style="width: 350px"
value="#{poiAdderBean.poi.link2Description}">
</h:inputText>
<h:message for="linkwww2Description" style="display: block; color:red"/>
<h:outputLabel value="#{msg.openingHours}"/>
<div class="col-md-12">
<div class="col-md-6">
<div class="input-group clockpicker">
<span class="input-group-addon" id="from">DO</span>
<h:inputText styleClass="form-control"
id="clockInputStart"
value="#{poiAdderBean.poi.openHoursStart}">
</h:inputText>
<span class="input-group-addon" id="timeFrom">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
<div class="col-md-6">
<div class="input-group clockpicker">
<span class="input-group-addon" id="to">DO</span>
<h:inputText styleClass="form-control"
id="clockInputStop"
value="#{poiAdderBean.poi.openHoursStop}">
</h:inputText>
<span class="input-group-addon" id="timeTo">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
</div>
<div class="col-md-12">
<h:outputLabel for="disableAccess"
value="#{msg.disableAccess}"/>
<h:selectBooleanCheckbox id="disableAccess"
value="#{poiAdderBean.poi.disableAccess}">
</h:selectBooleanCheckbox>
</div>
<div class="col-md-6">
<h:outputLabel for="titlePl" value="#{msg.polishTitle}"/>
<h:inputText id="titlePl"
value="#{poiAdderBean.polish.title}"
required="true"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="titlePl" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="titleEng" value="#{msg.englishTitle}"/>
<h:inputText id="titleEng"
value="#{poiAdderBean.english.title}"
required="true"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="titleEng" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="descriptionPl" value="#{msg.descriptionPl}"/>
<h:inputTextarea id="descriptionPl"
value="#{poiAdderBean.polish.description}"
style="resize: none"
required="true"
styleClass="form-control"
rows="4"
requiredMessage="#{msg.fieldRequired}"/>
<h:message for="descriptionPl" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:outputLabel for="descriptionEng" value="#{msg.descriptionEn}"/>
<h:inputTextarea id="descriptionEng"
value="#{poiAdderBean.english.description}"
required="true"
style="resize: none"
styleClass="form-control"
rows="4"
requiredMessage="#{msg.description}"/>
<h:message for="descriptionEng" style="display: block; color:red"/>
</div>
<div class="col-md-6">
<h:inputFile styleClass="btn btn-default" id="file" value="#{poiAdderBean.uploadedFile}">
<f:ajax listener="#{poiAdderBean.uploadFile()}" execute="#this"/>
</h:inputFile>
</div>
</div>
<div class="col-md-6">
<div id="map-canvas" style="height: 600px;"></div>
</div>
<div class="col-md-12 loginSubmit">
<h:commandButton styleClass="btnDefault"
style="margin-top: 50px"
value="#{msg.add}"
action="#{poiAdderBean.createPoi}">
</h:commandButton>
</div>
</h:form>
</div>
</div>
<script type="text/javascript">
// <![CDATA[
$('.clockpicker').clockpicker({
placement: 'bottom',
align: 'left',
autoclose: true,
'default': 'now'
});
var map;
var marker;
var geocoder;
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(50.05923273190915, 19.92233544588089)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
google.maps.event.addListener(map, 'click', function (event) {
setLatLong(event.latLng);
makeMarker(map, event.latLng);
codeLatLng(event.latLng);
}); //end addListener
}
function makeMarker(map, latLong) {
if (marker != null) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: latLong,
map: map
});
}
function codeAddress() {
var address = document.getElementById("address").value;
if (address != null && address != "") {
geocoder.geocode({'address': address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
map.setCenter(location);
map.setZoom(18);
makeMarker(map, location);
setLatLong(location);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
} else {
alert("Nie podano adresu");
}
}
function codeLatLng(latLng) {
geocoder.geocode({
'latLng': latLng
}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[0]) {
document.getElementById("address").value = results[0].formatted_address;
console.log(results[0]);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
function setLatLong(location) {
document.getElementById("longitude").value = location.lng();
document.getElementById("latitude").value = location.lat();
}
//]]>
</script>
</ui:define>
</ui:composition>
and bean for this page:
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.Part;
import java.io.*;
#Named("poiAdderBean")
#SessionScoped
public class PoiAdderBean implements Serializable {
#Inject
PrincipalBean principalBean;
#Inject
#Created
Event<Poi> poiCreated;
private Poi poi;
private Translation polish;
private Translation english;
private Part uploadedFile;
private Image image;
public void uploadFile() {
image = new Image();
byte[] bytes = new byte[0];
if (uploadedFile!= null) {
try {
InputStream is = uploadedFile.getInputStream();
if (is != null) {
bytes = IOUtils.toByteArray(is);
is.close();
}
} catch (IOException e) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"error uploading file",
null);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
image.setContent(bytes);
image.setContentType(uploadedFile.getContentType());
}
public Part getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
this.uploadedFile = uploadedFile;
}
public Poi getPoi() {
return poi;
}
public void setPoi(Poi poi) {
this.poi = poi;
}
public Translation getPolish() {
return polish;
}
public void setPolish(Translation polish) {
this.polish = polish;
}
public Translation getEnglish() {
return english;
}
public void setEnglish(Translation english) {
this.english = english;
}
public PoiCategory[] getPoiCategoryList(){
return PoiCategory.values();
}
#PostConstruct
public void init(){
poi = new Poi();
polish = new Translation(Language.PL, Status.READY);
english = new Translation(Language.EN, Status.READY);
}
public String createPoi(){
english.setAuthor(principalBean.getLoggedUser());
polish.setAuthor(principalBean.getLoggedUser());
poi.addTranslation(polish);
poi.addTranslation(english);
polish.setPoi(poi);
english.setPoi(poi);
if(image != null){
poi.setImage(principalBean.getDataAccess().mergeEntity(image));
}
principalBean.getDataAccess().mergeEntity(poi);
poiCreated.fire(poi);
return "/secure/poiTranslator.xhtml?faces-redirect=true";
}
}
For some completely strange and unknown to me reason, there is always error message on a bottom of a page that says:
#ViewScoped beans are not supported on stateless views
but this is clearly #SessionScoped bean. I can't find source of this error, that's why I posted entire code.
PLUS - when I don't upload a file - validation works just fine, and after successfully writing Poi object in database, page is redirected to poiTranslator page, just like it should. BUT when I add image - validation don't work, and page is not redirected - but objects are stored correctly in database.
Thanks for any help

Thanks to #Gimby I found small error in my template file.
Like in post from BalusC blog he posted, in my template was line that was enabling statelessness - which was not wanted in first place.
Thanks for help.
link to BalusC artickle

Related

updating bean when change selectonemenu value without refreshing the page

I have selectonemenu and i want when i change the value of selectonemenu i want that the bean value updated for to display some code that i have in a block condition without submitting and refreshing the page without this i will lose the other value fill in the form
I have none display
I have selectonemenu block
<h:selectOneMenu id="categorieSelect" value = "#{categorie.option}"
valueChangeListener="#{categorie.categorieChanged}">
<f:selectItem itemValue="selection" itemLabel="Choisissez une catégorie" noSelectionOption="true"/>
<f:selectItems value ="#{categorie.options}" var="categorieSelect" />
<f:ajax event="change" execute="#form"/></h:selectOneMenu>
I have also some block in c:choose which i want to display when the value of selectonemenu change
<c:choose>
<c:when test="#{categorie.option == 'offreemploi'}">
<div class="row">
<p:outputLabel value="Type d'annonce *" class="outputelement" id="test3"></p:outputLabel>
</div>
<div class="row">
<h:selectOneRadio id="typeannonce" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="Le type d'annonce est obligatoire"
class="inputelement"
value="#{offreEmploi.typeannonce}" binding="#{typeannonce}">
<f:selectItem itemValue="demande" itemLabel="Demande (Vous recherchez un emploi)"
/>
<f:selectItem itemValue="offre" itemLabel="Offre (Vous recherchez un employé)" />
</h:selectOneRadio>
</div>
<div class="row">
<h:message for="typeannonce" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText value="Intitulé du poste *" class="outputelement"></h:outputText>
</div>
<div class="row">
<h:inputText id="intituleposte" binding="#{intituleposte}" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="L'intitule du poste est obligatoire"
class="col-xs-12 col-sm-6 col-md-6 col-lg-6 inputelement"
value="#{offreEmploi.intituleposte}"></h:inputText>
</div>
<div class="row">
<h:message for="intituleposte" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText value="Description du poste *" class="outputelement"></h:outputText>
</div>
<div class="row">
<h:inputTextarea id="descriptionposte" rows="10" cols="30" binding="#{descriptionposte}" required="#{not empty param[menucategorie.clientId]}"
requiredMessage="La description du poste est obligatoire"
class="col-xs-12 col-sm-6 col-md-6 col-lg-6 inputelement"
value="#{offreEmploi.descriptionposte}"></h:inputTextarea>
</div>
<div class="row">
<h:message for="descriptionposte" class="message col-xs-12 col-sm-6 col-md-6 col-lg-6"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photos : Une annonce avec photos est beaucoup plus consulté qu'une annonce sans photos"></h:outputText>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo principal"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo1}" binding="#{photo1}"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo 2"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo2}" binding="#{photo2}"/>
</div>
<div class="row">
<h:outputText class="outputelement" value="Photo 3"></h:outputText>
<p:fileUpload mode="simple" class="inputelement"
value="#{photo.photo3}" binding="#{photo3}"/>
</div>
</c:when>
<c:otherwise>Bonjour</c:otherwise>
</c:choose>
and here is my backing bean
#ManagedBean
#SessionScoped
public class Categorie implements Serializable{
String option; // +getter +setter
List<SelectItem> options; // +getter
public String getOption() {
return option;
}
public void setOption(String selectedOption) {
this.option = selectedOption;
}
public List<SelectItem> getOptions() {
return options;
}
public void setOptions(List<SelectItem> options) {
this.options = options;
}
public void categorieChanged(ValueChangeEvent e) {
//assign new value to country
option = e.getNewValue().toString();
}
public void changeCountry() {
//System.out.println("Selected country is: " + option.);
}
public Categorie() {
options = new ArrayList<SelectItem>();
SelectItemGroup group1 = new SelectItemGroup("EMPLOI");
group1.setSelectItems(new SelectItem[] {
new SelectItem("offreemploi", "Offre d'emploi")
});
options.add(group1);
}
public void save(){
}
}

the data on my database are not updatd when i change the value of p:selectBooleanCheckbox , but it works with the inputText [duplicate]

This question already has an answer here:
when i click on the p:selectBooleanCheckbox, it works but for the second click it doesn't work,why?
(1 answer)
Closed 5 years ago.
when i want to update the value of the <p:selectBooleanCheckbox> and click on update button, its value doesn't change on the database, but when i replace it with .
this is my code :
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:evoice="http://ccs.tn/taglib/evoice">
<ui:include src="CloseTicketDialog.xhtml" />
<div class="form-body pal">
<div class="row">
<p:outputLabel for="call_from_tel_number"
styleClass="col-md-2 control-label" value="Numéro Entrant" />
<div class="col-md-3">
<div class="input-icon right">
<i class="fa fa-phone" />
<p:inputText id="call_from_tel_number" maxlength="32" size="9"
value="#{ticketController.ticket.callFromTelNumber}"
validatorMessage="Numéro Entrant : Composé au minimum par 8 chiffres dans [0..9]."
styleClass="form-control">
<f:validateRegex pattern="[0-9\s]*" />
<f:validateLength minimum="8" maximum="32" />
<p:ajax event="blur" id="ajax_call" disabled="#{ticketController.ticket.ticketId ne null}"
process="call_from_tel_number,form:growl"
update="form:growl,form:tab_view:lastName, form:tab_view:firstName"
listener="#{ticketController.queryOldTickets(ticketController.ticket)}"
onstart="PF('statusDialog').show()"
oncomplete="PF('statusDialog').hide()"/>
</p:inputText>
</div>
</div>
<p:outputLabel for="reply_to_tel_number" value="Deuxièmme Numéro"
styleClass="col-md-3 control-label" />
<div class="col-md-3">
<div class="input-icon right">
<i class="fa fa-phone" />
<p:inputText id="reply_to_tel_number" maxlength="32" size="9"
readonly="{ticketController.ticket.ticketId ne null}"
value="#{ticketController.ticket.otherPhonenum}"
validatorMessage="Deuxièmme Numéro : Accepte seulement des chiffres dans [0..9]."
styleClass="form-control">
<f:validateRegex pattern="[0-9]*" />
</p:inputText>
</div>
</div>
</div>
<div class="form-group" />
<div class="row">
<p:outputLabel for="telOwner" value="proprietaire de num"
styleClass="col-md-2 control-label" />
<div class="col-md-3">
<div class="input-icon right">
<p:selectBooleanCheckbox selected="true" id="telOwner" value="#{ticketController.ticket.phoneLineOwner}" />
</div>
</div>
</div>
what is the problem? what the value of "telOwner" is updated when i use p:inputText and its not updated when i use p:selectBooleanCheckbox?
this is the controller:
#Controller(value = "ticketController")
#Scope("view")
public class TicketController extends eVoiceController implements Serializable {
public String saveTicket() {
log.info("saveTicket");
if (!isValide(ticket)) {
return null ;
}
if (ticket.getOwner() == null) {
ticket.setOwner(currentUser());
} else {
ticket.setLastUpdateBy(currentUser());
ticket.setLastUpdateDate(new Timestamp(System.currentTimeMillis()));
}
Integer ticketId = ticketService.saveTicket(ticket);
// ticket.getTicketCategories().size();
if (closeTicketCmdBtn != null) {
closeTicketCmdBtn.setDisabled(false);
}
showInfoMessage(i18n("ticket.saved.number", ticketId));
log.info("TICKET[" + ticketId + "]");
return null;
}
this is the service:
#Override
#Transactional(readOnly = false)
public Integer saveTicket(final Ticket ticket) {
LoyaltyCard card = ticket.getLoyaltyCard();
if (card != null) {
card.setCreatedBy(ticket.getCreatedBy());
card = loyaltyCardService.save(card);
}
ticket.setLoyaltyCard(card);
Integer id = ticketDao.save(ticket).getTicketId();
/**
* #TODO run on seperate Thread
*/
ruleService.assignSeverity(ticket);
return id;
}
and this is the entity code:
#Column(name = "phone_line_owner")
#org.hibernate.annotations.Type(type = "yes_no")
private Boolean phoneLineOwner;

Issue with resetting datagrid in primefaces

I am new to JSF and I am working on an application where a group of parameters placed in a datagrid can be either added or removed. Below is the initial level of screenshot:
When I click on RemoveInvoice of any of the existing list, the list present after that box should automatically take the position of the removed list. But in my case, a blank section is getting displayed as per the below screenshot:
My jsf code looks like:
<div class="listing_Table">
<p:dataGrid columns="3" layout="grid" id="addInvoicePanel"
value="#{hrOrganizationPaymentDetailBean.invoiceDetailTOList}"
var="invoiceDetail">
<p:panelGrid rendered="#{!invoiceDetail.delete}">
<div class="Table">
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceType:</p:outputLabel>
</div>
<div class="Cell">
<p:selectOneMenu value="#{invoiceDetail.invoiceTypeID}"
filter="true" filterMatchMode="contains" required="true"
requiredMessage="InvoiceType is required">
<f:selectItems
value="#{hrOrganizationPaymentDetailBean.newInvoiceTypeList}"
var="list" itemValue="#{list.typeId}"
itemLabel="#{list.type}" />
</p:selectOneMenu>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceNumber:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoiceNumber}"
required="true" requiredMessage="InvoiceNumber is required" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceAmount:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoiceAmount}"
required="true" requiredMessage="InvoiceAmount is required">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>InvoicePath:</p:outputLabel>
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.invoicePath}" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel>
<span class="redColor">*</span>InvoiceDate:</p:outputLabel>
</div>
<div class="Cell">
<p:calendar id="invoiceDate"
value="#{invoiceDetail.invoiceDate}" showOn="button"
readonlyInput="true" timeZone="IST" pattern="dd-MMM-yyyy"
required="true" requiredMessage="InvoiceDate is required" />
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel value="ServiceTax:" />
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.serviceTax}">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell">
<p:outputLabel value="TDS:" />
</div>
<div class="Cell">
<p:inputText value="#{invoiceDetail.tDS}">
<f:convertNumber pattern="#0.00" />
</p:inputText>
</div>
</div>
<div class="Row">
<div class="Cell"></div>
<div class="Cell">
<p:commandButton styleClass="Submit_button"
value="Remove Invoice"
action="#{hrOrganizationPaymentDetailController.removeInvoiceDetail(invoiceDetail)}"
update=":EditOrganizationPaymentDetailForm:addInvoicePanel" />
</div>
</div>
</div>
</p:panelGrid>
</p:dataGrid>
</div>
And my backend java code is:
public void removeInvoiceDetail(InvoiceDetailTO invoiceDetailTO)
{
List<InvoiceDetailTO> invoiceDetailTOList = null;
List<Long> deletedInvoiceDetail = null;
try {
invoiceDetailTOList = hrOrganizationPaymentDetailBean.getInvoiceDetailTOList();
deletedInvoiceDetail = hrOrganizationPaymentDetailBean.getDeletedInvoiceDetailID();
if (deletedInvoiceDetail != null && !deletedInvoiceDetail.isEmpty()) {
} else {
deletedInvoiceDetail = new ArrayList<Long>();
}
for (InvoiceDetailTO detailTO : invoiceDetailTOList) {
if ((detailTO.getInvoiceDetailID() != null && detailTO.getInvoiceDetailID().equals(invoiceDetailTO.getInvoiceDetailID()))
|| (detailTO.getUniqueID() != null && detailTO.getUniqueID().equals(invoiceDetailTO.getUniqueID()))) {
detailTO.setDelete(true);
if (invoiceDetailTO.getInvoiceDetailID() != null) {
deletedInvoiceDetail.add(invoiceDetailTO.getInvoiceDetailID());
}
}
}
hrOrganizationPaymentDetailBean.setInvoiceDetailTOList(invoiceDetailTOList);
hrOrganizationPaymentDetailBean.setDeletedInvoiceDetailID(deletedInvoiceDetail);
} catch (Exception e) {
LOGGER_.error("", e);
}
}
Please advise where I am making a mistake?
The problem is in <p:panelGrid rendered="#{!invoiceDetail.delete}">. Even with rendered="false" cell won't be removed from html page after rendering. If you open debugger in your browser (press F12 for Mozilla or Chrome) you can find empty cell there <td class="ui-datagrid-column"></td>. So you need to remove deleted item from your #{hrOrganizationPaymentDetailBean.invoiceDetailTOList} and update dataGrid.

Unable to call method specified in ValueChangeListener attribute of <ice:selectOneRadio>

I am creating a Icefaces Datatable.First column have radio button. On clicking of radio button of first row i am able to edit the row. On clicking of radio button of another rows another operation should be performed(but not edit). I have one command button at the bottom of the datatable which saves the data. Find below the code for the same
------------------xhtml----------------------
<h1>IceFaces 3 </h1>
<h:form>
<ice:selectOneRadio id="myRadioId"
value="#{order.checked}" layout="spread"
valueChangeListener="#{orderBean.editSelectedRow}"
partialSubmit="true">
<f:selectItem itemValue="" />
</ice:selectOneRadio>
<ace:dataTable value="#{orderBean.orderList}" var="o" style="width: 300px !important">
<ace:column headerText="Select">
<ice:radio for="myRadioId" />
</ace:column>
<ace:column headerText="Order No">
<h:inputText value="#{o.orderNo}" size="10" rendered="#{o.editable}" />
<h:outputText value="#{o.orderNo}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Product Name">
<h:inputText value="#{o.productName}" size="20" rendered="#{o.editable}" />
<h:outputText value="#{o.productName}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Price">
<h:inputText value="#{o.price}" size="10" rendered="#{o.editable}" />
<h:outputText value="#{o.price}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Quantity">
<h:inputText value="#{o.qty}" size="5" rendered="#{o.editable}" />
<h:outputText value="#{o.qty}" rendered="#{not o.editable}" />
</ace:column>
</ace:dataTable>
<br/><br/>
<ice:commandButton value="Save Changes" action="#{orderBean.saveAction}" />
</h:form>
</h:body>
------------------------------managed bean------------------------------
//bean
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import org.icefaces.ace.component.datatable.DataTable;
#ManagedBean(name="orderBean")
#SessionScoped
public class OrderBean implements Serializable{
private static final long serialVersionUID = 1L;
private static final ArrayList<Order> orderList =
new ArrayList<Order>(Arrays.asList( new Order("A0001", "Intel CPU", new BigDecimal("700.00"), 1),
new Order("A0002", "Harddisk 10TB", new BigDecimal("500.00"), 2),
new Order("A0003", "Dell Laptop", new BigDecimal("11600.00"), 8),
new Order("A0004", "Samsung LCD", new BigDecimal("5200.00"), 3),
new Order("A0005", "A4Tech Mouse", new BigDecimal("100.00"), 10)
));
public ArrayList<Order> getOrderList() {
return orderList;
}
public String saveAction() {
//get all existing value but set "editable" to false
for (Order order : orderList){
order.setEditable(false);
}
//return to current page
return null;
}
// listener method
public void editSelectedRow(ValueChangeEvent evt) {
// We get the table object
DataTable table = getParentDatatable((UIComponent) evt.getSource());
if(table==null) return;
// We get the object on the selected line.
Object o = table.getRowData();
Order order = (Order)o;
// Eventually, if you need the index of the line, simply do:
int index = table.getRowIndex();
if(index == 0){
order.setEditable(true);
}
// ...
}
// Method to get the DataTable.
private DataTable getParentDatatable(UIComponent compo) {
if (compo == null) {
return null;
}
if (compo instanceof DataTable) {
return (DataTable) compo;
}
return getParentDatatable(compo.getParent());
}
//managed bean
#ManagedBean(name="order")
public static class Order{
String orderNo;
String productName;
BigDecimal price;
int qty;
boolean editable;
boolean checked;
public Order(){ }
public Order(String orderNo, String productName, BigDecimal price, int qty) {
this.orderNo = orderNo;
this.productName = productName;
this.price = price;
this.qty = qty;
}
//getter and setter methods
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getQty() {
return qty;
}
public void setQty(int qty) {
this.qty = qty;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
}
}
-------------------------------generated html--------------------------------
<table>
<thead>
<tr>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt10">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt10_text">Select</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt12">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt12_text">Order No</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt15">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt15_text">Product Name</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt18">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt18_text">Price</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt21">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt21_text">Quantity</span></span>
</div></th>
</tr>
</thead>
<tbody class="ui-datatable-data ui-widget-content">
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_0" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:0:_t14">A0001</span></td>
<td><span id="j_idt6:j_idt9:0:_t17">Intel CPU</span></td>
<td><span id="j_idt6:j_idt9:0:_t20">700.00</span></td>
<td><span id="j_idt6:j_idt9:0:_t23">1</span></td>
</tr>
<tr class=" ui-datatable-odd " id="j_idt6:j_idt9_row_1" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:1:_t14">A0002</span></td>
<td><span id="j_idt6:j_idt9:1:_t17">Harddisk 10TB</span></td>
<td><span id="j_idt6:j_idt9:1:_t20">500.00</span></td>
<td><span id="j_idt6:j_idt9:1:_t23">2</span></td>
</tr>
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_2" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:2:_t14">A0003</span></td>
<td><span id="j_idt6:j_idt9:2:_t17">Dell Laptop</span></td>
<td><span id="j_idt6:j_idt9:2:_t20">11600.00</span></td>
<td><span id="j_idt6:j_idt9:2:_t23">8</span></td>
</tr>
<tr class=" ui-datatable-odd " id="j_idt6:j_idt9_row_3" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:3:_t14">A0004</span></td>
<td><span id="j_idt6:j_idt9:3:_t17">Samsung LCD</span></td>
<td><span id="j_idt6:j_idt9:3:_t20">5200.00</span></td>
<td><span id="j_idt6:j_idt9:3:_t23">3</span></td>
</tr>
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_4" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:4:_t14">A0005</span></td>
<td><span id="j_idt6:j_idt9:4:_t17">A4Tech Mouse</span></td>
<td><span id="j_idt6:j_idt9:4:_t20">100.00</span></td>
<td><span id="j_idt6:j_idt9:4:_t23">10</span></td>
</tr>
</tbody>
</table>
probleme here is that i am unable to call editSelectedRow(ValueChangeEvent evt) method of OrderBean.java
I think what you are missing is the onchange property , do something like the following :
<ice:selectOneRadio id="myRadioId"
value="#{order.checked}" layout="spread"
valueChangeListener="#{orderBean.editSelectedRow}"
onchange="submit()">
<f:selectItem itemValue="" />
</ice:selectOneRadio>
Hope that Helps.

editing a data in a datatable using a modal form

i have a datatable, each row has a
<p:commandButton styleClass="edit-promo-img" action="#{branchController.prepareEdit}" value="" oncomplete="updateBranchForm()"/>
this is my modal:
<div id="edit-branch-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<h:form id="editBranchForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
Branch Details
</div>
<div class="modal-body">
<div><h:outputLabel value="#{bundle.CreateBranchLabel_name}" for="name" /></div>
<div><h:inputText id="name" value="#{branchController.selected.name}" title="#{bundle.CreateBranchTitle_name}" required="true" requiredMessage="#{bundle.CreateBranchRequiredMessage_name}"/></div>
</div>
<div class="modal-footer">
<p:commandButton action="#{branchController.update}" value="#{bundle.CreateBranchSaveLink}" />
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
<p:remoteCommand name="updateBranchForm" update="#form" />
</h:form>
prepareEdit method:
public void prepareEdit() {
current = (Branch) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
}
selected method:
public Branch getSelected() {
if (current == null) {
current = new Branch();
selectedItemIndex = -1;
}
return current;
}
when i debugged on the getSelected method, there is actually correct data on my "current" object.
my problem is, the input in the modal has no data.
using JSF 2.0 with Primefaces and my bean is using ViewScope.

Resources