When I use f:validator inside a field of a dataTable, doesn't work, if I insert a breakpoint in my validator class, it never executes.
My dataTable:
<p:dataTable value="#{contrato.plantillaPrograma}" var="pl" scrollHeight="300" rendered="#{contrato.abrirPrograma}" autoUpdate="true">
<p:column headerText="#{txtMsg['crearContrato.fecha']}" style="width:125px"
sortBy="#{pl.fecha}">
<h:inputText value="#{pl.fecha}">
<f:converter converterId="dateConverter" />
</h:inputText>
</p:column>
<p:column headerText="#{txtMsg['crearContrato.programa']}" style="width:125px"
sortBy="#{pl.programa}">
<h:inputText value="#{pl.programa}" />
</p:column>
<p:column headerText="#{txtMsg['crearContrato.fechaFactura']}" style="width:125px"
sortBy="#{pl.fechaFactura}">
<p:inputText value="#{pl.fechaFactura}" validator="sheetEnFirme">
<f:converter converterId="dateConverter"/>
</p:inputText>
</p:column>
</p:dataTable>
My class:
package es.axpo.jsf.validator;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
#FacesValidator(value="sheetEnFirme")
public class SheetEnFirmeValidator implements Validator{
public void validate(FacesContext fc, UIComponent comp, Object obj)
throws ValidatorException {
throw new ValidatorException(new FacesMessage("Error"));
}
}
Make sure that the #{contrato} bean is at least #ViewScoped. Make sure that you aren't preparing plantillaPrograma in its getter method, but instead in bean's (post)constructor. Make sure that the dateConverter hasn't thrown a ConverterException which you should have noticed by a faces message in <h:message(s)> or in the server's log.
By the way, why are you not just using the builtin <f:convertDateTime> for dates?
It's solved.
My problem was on the command button, I had property process="#this", when removed, validation works fine
Related
I use JSF 2.2 and Primefaces 6.1. I have a problem with textarea value on first form submit. I use multiple subviews for one form. The problem is when type something into textarea, after first form submit this value disapear and not update data model. But when type again and fire submit, then this value is showing. The textarea is inside subTable in dataTable.
I tried use valueChangeListener together with ajax. This works, but when click to fast to submit, then value haven't be updated. I tried only ajax but result was the same. I tried valueChangeLister with onchange="submit()" but this not worked. tried solution Primefaces valueChangeListener or <p:ajax listener not firing for p:selectOneMenu but this not working
Textarea code
<h:form id="reuestForm">
<div class="form-group">
<p:dataTable id="edScopeTable" styleClass="form-group dataTable-space"
value="#{requestBean.employeeDealerTabController.getEdScopeCategories()}"
var="category">
<p:columnGroup type="header">
<p:row>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_colScope_header}"/>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_col_openIdConnect_header}"/>
<p:column headerText="#{i18nMsg.ed_env_scopes_tbl_col_reasonNeeded}"/>
</p:row>
</p:columnGroup>
<p:subTable
value="#{requestBean.employeeDealerTabController.getScopeReasonsByCategory(category)}"
var="edScope" rendered="#{requestBean.employeeDealerTabController.isCategoryInTable(category)}">
<p:column styleClass="#{requestBean.employeeDealerTabController.calculateDiff(edScope,'cell-right')} textAlign-center">
<p:inputTextarea id="reason"
value="#{edScope.reason}" rows="2"
autoResize="false"
data-disable-type="custom"
styleClass="form-control #{edScope.getDiffValue('reason')}"
rendered="#{edScope.edScopeConst.reasonNeeded}"
label="#{i18nMsg.edScope_request_selectionTable_scope_reasonNeeded} #{edScope.edScopeConst.name}"
disabled="#{requestBean.employeeDealerTabController.disableReasonField()}">
<f:attribute name="scope" value="#{edScope}"/>
<f:validateBean
binding="#{requestBean.validatorContainer.requiredBeanValidator}"/>
<p:message for="reason" display="tooltip"/>
</p:inputTextarea>
<h:outputText
rendered="#{not edScope.edScopeConst.reasonNeeded}"
value="#{i18nMsg.edScope_request_selectionTable_scope_noReasonNeeded}"/>
</p:column>
</p:subTable>
</p:dataTable>
</div>
<div class="text-right">
<p:commandButton value="#{(requestBean.request.version eq 1 and requestBean.request.stateDraft) or requestBean.isEdRequestToBePrinted() ? i18nMsg.general_mainButton_send_and_print : i18nMsg.general_mainButton_send}"
id="send"
update="requestForm"
actionListener="#{requestBean.prepareDialog()}"
oncomplete="args.validationFailed ? PF('validationFailedMessageDialog').show() : PF('readyToSendDialog').show(); jQuery(document).scrollTop(0)"
title="#{requestBean.sendButtonDisabled ? i18nMsg.request_sendButtonTooltip : ''}"
styleClass="ui-priority-primary" icon="ui-icon-mail-closed"
disabled="#{requestBean.sendButtonDisabled}" data-disable-type="custom" />
</div>
</h:form>
RequestBean
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class RequestBean extends PageBeanBase implements Serializable {
private EmployeeDealerTabController employeeDealerTabController;
#PostConstruct
public void initialize() {
employeeDealerTabController = new EmployeeDealerTabController();
}
public EmployeeDealerTabController getEmployeeDealerTabController() {
return employeeDealerTabController;
}
public void prepareDialog() {
// preparation before send and show dialog with confirmation send form
}
// rest of method
}
EmployerDealerTabController
public List<EdScopeREason> getScopeReasonsByCategory(int category) {
if(category == 1) {
return scopesOidcList;
} else {
return scopesIdentityList;
}
}
EdScopeReason
#Entity
#Table(name = "ED_SCOPE_REASON")
public class EdScopeReason extends InlineDiffBase<EdScopeReason> implements EdScopeConstBearer, Serializable, Comparable<EdScopeReason> {
private String reason;
#Basic
#Column(name = "REASON")
#NotBlank(groups = RequiredValidationGroup.class, message = "{iamat.validation.general.edScopeReason.notempty}")
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}
I have setter and getter method. When I debug this value is pass to validator but not set to component. I'm little confused why this value is not set on the first time
EDIT
I add jsf ajax to textarea input and set 5s delay on commandButton. This is some kind of workaround, but still look for better solution. When I use primefaces ajax I don't need delay, but for every primefaces ajax I display loader.gif.
<p:inputTextarea id="reason"
...{requestBean.employeeDealerTabController.disableReasonField()}">
<f:attribute name="scope" value="#{edScope}"/>
<f:validateBean
binding="#{requestBean.validatorContainer.requiredBeanValidator}"/>
<p:message for="reason" display="tooltip"/>
<f:ajax />
</p:inputTextarea>
....
<p:commandButton value="#{(requestBean.request.version eq 1 and requestBean.request.stateDraft) or requestBean.isEdRequestToBePrinted() ? i18nMsg.general_mainButton_send_and_print : i18nMsg.general_mainButton_send}"
id="send"
update="requestForm"
actionListener="#{requestBean.prepareDialog()}"
oncomplete="args.validationFailed ? PF('validationFailedMessageDialog').show() : PF('readyToSendDialog').show(); jQuery(document).scrollTop(0)"
title="#{requestBean.sendButtonDisabled ? i18nMsg.request_sendButtonTooltip : ''}"
styleClass="ui-priority-primary" icon="ui-icon-mail-closed"
disabled="#{requestBean.sendButtonDisabled}" data-disable-type="custom" delay="5000" />
I'm using STS (Spring tool suite) with spring boot, primefaces and hibernate.
I have an page with a p:datatable. In the last column, have a p:commandbutton for edit data of the table (p:dialog).
When I open the dialog, all data load correct. If I close de dialog without save and open other line of the table data load correct again, but, if I save the data and open a new dialog of other line of the table, the field p:selectOneMenu is loaded with wrong data. Your value is the same value of the last dialog saved. All dialog data has correct, less the combobox (p:selectOneMenu). In debug, the value returned in backing bean is correct.
Some things I've tried:
Changed p:commandbutton to p:commandlink;
In button "save" of dialog, "update" field with the p:panel of table, the h:form, h:datable;
Change onComplete to onClick;
Use h:selectOneMenu instead of p:selectOneMenu;
Downgrade primefaces (currently 6.1) and myfaces (currently 2.2.12).
All no sucess.
ps: Datatable is filtered and paginated.
xhtml:
<p:panel id="pnlData" header="My Table">
<h:form id="frmTable">
<p:dataTable var="item" value="#{RSDMBean.myData}"
id="tblTicketsID" widgetVar="tabelaTickets" some things of pagination and filters here...>
<p:column />
<p:column /> ...
<p:column headerText="Edit">
<p:commandButton value="Edit"
actionListener="#{RSDMBean.editTicketLoad(item.idTicket)}"
update=":formPnl:pnlTkct" oncomplete="PF('dlgtkt').show();">
</p:commandButton>
</p:column>
</p:datatable>
</h:form
</p:panel>
<p:dialog id="dlgtktID" header="Edit ticket" widgetVar="dlgtkt"
modal="true">
<h:form id="formPnl">
<h:panelGrid id="pnlTkct" columns="2" cellpadding="10"
cellspacing="1" style="absolute">
<h:outputText style="font-weight:bold" value="Id Ticket: " />
<h:outputText value="#{RSDMBean.ticketEdited.id}" />
Others fields here...
<h:outputText style="font-weight:bold" value="County: " />
<p:selectOneMenu style="min-width: 162px;" required="true">
<f:selectItem itemLabel="#{RSDMBean.ticketEdited.county.name}"
itemValue="#{RSDMBean.ticketEdited.county.id}" />
<f:selectItems
value="#{RSDMBean.countyItensedit.entrySet()}" var="entry"
itemValue="#{entry.key}" itemLabel="#{entry.value}" />
</p:selectOneMenu>
<p:commandButton value="Save" action="#{RSDMBean.saveEdit}"
update=":frmTable:tblTicketsID" oncomplete="PF('dlgtkt').hide();" />
end tags here...
Bean:
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;
import org.springframework.beans.factory.annotation.Autowired;
.
.
.
#Controller("RSDMBean")
#RequestScoped
public class MyMBean implements Serializable {
#Autowired
private ResiduoService residuoService;
#Autowired
private ResiduoRepository residuoRepository;
#Autowired
private CountyRepository countyRepository;
private Residuo ticketEdited;
private List<County> county;
private Map<Long, String> countyItensEdit = new HashMap<Long, String>();
public void editTicketLoad(String param) {
long idTicket = Long.parseLong(param);
ticketEdited = residuoRepository.findOne(idTicket);
county = countyRepository.findAll();
}
#PostConstruct
public void construct() {
//some loads database here...
county = countyRepository.findAll();
if (countyItensEdit.isEmpty()) {
for (Municipio c : countyItensEdit) {
countyItensEdit.put(c.getId(), c.getNome());
}
}
}
In p:selectOneMenu was missing value tag:
<p:selectOneMenu style="min-width: 162px;" required="true"
value="#{RSDMBean.ticketEdited.county.id}">
I am trying to pass a parameter (a user's id from a datatable) from one page to the next where I am using it (showing the user's details). The problem is that I can not get it. What am I missing? What am I doing wrong? I am using PrimeFaces 5 and JSF 2.2 (also Hibernate 4). Is there any way that I can have the parameter #PostConstruct so that I can load the user's details immediately?
The first page with the datable
<h:form id="manageUserForm" prependId="false">
<p:growl id="messages" showDetail="true" life="20000"/>
<p:dataTable id="usersTable" var="user" value="#{manageUsers.users}">
<f:facet name="header">
#{pvtmsg.registeredUsers}
</f:facet>
<p:column headerText="ID">
<h:outputText value="#{user.id}" />
</p:column>
<p:column headerText="#{pvtmsg.username}">
<h:outputText value="#{user.username}" />
</p:column>
<p:column headerText="#{pvtmsg.firstname}">
<h:outputText value="#{user.firstname}" />
</p:column>
<p:column headerText="#{pvtmsg.lastname}">
<h:outputText value="#{user.lastname}" />
</p:column>
<p:column headerText="#{pvtmsg.email}">
<h:outputText value="#{user.email}" />
</p:column>
<p:column headerText="#{pvtmsg.status}">
<h:outputText value="#{user.enabled ? pvtmsg.enabled : pvtmsg.disabled}" />
</p:column>
<p:column style="width:32px;text-align: center">
<p:commandLink action="editUser.xhtml?faces-redirect=true">
<f:setPropertyActionListener value="#{user.id}" target="#{manageUsers.selectedUser}" />
<f:param name="userId" value="#{manageUsers.selectedUser}" />
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
Its backing bean
package beans;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import models.User;
import utils.PropertyHelper;
#Named(value = "manageUsers")
#ViewScoped
public class ManageUsers implements Serializable {
private static final long serialVersionUID = 954672295622776147L;
private List<User> users = null;
private String selectedUser = null;
public ManageUsers() {
try {
PropertyHelper helper = new PropertyHelper();
users = helper.getUsers();
} catch (Exception ex) {
Logger.getLogger(ManageUsers.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<User> getUsers() {
return users;
}
public String getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(String selectedUser) {
this.selectedUser = selectedUser;
}
}
The second page
<f:metadata>
<f:viewParam name="userId" value="#{editUserBean.userId}" />
</f:metadata>
<h:form id="editUserForm" prependId="false">
<p:growl id="messages" showDetail="true" life="20000"/>
<!--nothing yet-->
</h:form>
Its backing bean
package beans;
import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named(value = "editUserBean")
#ViewScoped
public class EditUserBean implements Serializable {
private static final long serialVersionUID = 543216875622776147L;
private String userId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
Your commandLink doesn't make sense here. Typically when you want to navigate with a commandLink, you should do a redirect in your backing bean.
If you want to navigate using outcome, then something like this should work for you:
<h:link outcome="editUser.xhtml">
<f:param name="userId" value="#{user.id}" />
</h:link>
So I found my solution here http://www.oracle.com/technetwork/articles/java/jsf22-1377252.html and, after some time, the last piece that I needed here here http://www.coderanch.com/t/625319/JSF/java/working-viewParam
Your f:viewParams won't be available during the #PostConstruct method call. You should assign a f:viewAction, since you are using JSF 2.2, to handle business processing on GET parameters.
<f:metadata>
<f:viewParam name="userId" value="#{editUserBean.userId}" />
<f:viewAction action="#{editUserBean.processUserId}"/>
</f:metadata>
See also:
Read this if using JSF older than 2.2
JSF bean: call #PostConstruct function after ViewParam is set
This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 6 years ago.
I try write my first JSF2.0 project (with using EJB3.1). I don't understand why my #ManagedBean annotation not work.
I always get an error, when I run application on Glassfish v3
exception
javax.servlet.ServletException: /login.xhtml #34,133
value="#{loginBean.login}": Target Unreachable, identifier 'loginBean'
resolved to null
root cause
javax.el.PropertyNotFoundException: /login.xhtml #34,133
value="#{loginBean.login}": Target Unreachable, identifier 'loginBean'
resolved to null
If I define a managed bean in faces-config.xml - it will work. But I want to use annotation.
May be I use wrong libraries in my poms?
Example of managedbean (it will be a transfer object):
package edu.tsystems.vmmail.web.core.domain;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
#ManagedBean
#ViewScoped
public class LoginBean implements Serializable {
private String login;
private String password;
public LoginBean() {}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
login.xhtml (where i can try to use it):
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:loadBundle var="common" basename="edu.tsystems.vmmail.web.ui.MessageResources" />
<h:head>
<title>Welcome to VMMail Web Interface</title>
<link type="text/css" href="#{request.contextPath}/css/style.css" rel="stylesheet" />
</h:head>
<h:body>
<f:view>
<h:form id="loginForm" method="post">
<p:panelGrid id="mainLogin" styleClass="noInnerBorderTable">
<f:facet name="header">
<p:row>
<p:column colspan="4">
<h:outputText value="#{common['login.welcome']}" /><br/>
<h:message for="loginBean" id="login1Error" />
</p:column>
</p:row>
</f:facet>
<p:row>
<p:column rowspan="2">
<div class="logoCell"></div>
</p:column>
<p:column>
<h:outputText value="#{common['field.login']}" for="loginBean" />
</p:column>
<p:column>
<p:inputText id="loginBean" required="true" value="#{loginBean.login}" requiredMessage="#{common['field.login.required']}" />
</p:column>
<p:column rowspan="2">
<div class="submitButtonCell">
<p:commandLink styleClass="loginAnchor" title="#{common['field.loginButton']}"
action="#{userController.loggingIn(login)}" ajax="false" />
</div>
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputText for="password" value="#{common['field.password']}" />
</p:column>
<p:column>
<p:password id="password" required="true" value="#{loginBean.password}" requiredMessage="#{common['field.password.required']}" />
</p:column>
</p:row>
<f:facet name="footer">
<p:row>
<p:column colspan="4">
<h:outputText value="#{common['login.notHave']}" />
<a href="#{request.contextPath}/registration.xhtml">
<h:outputText value="#{common['login.registerNow']}" />
</a>
</p:column>
</p:row>
</f:facet>
</p:panelGrid>
</h:form>
</f:view>
</h:body>
</html>
UserController class:
package edu.tsystems.vmmail.web.core.controllers;
import edu.tsystems.vmmail.web.core.dao.UserDAO;
import edu.tsystems.vmmail.web.core.domain.LoginBean;
import edu.tsystems.vmmail.web.core.model.UserEntity;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
#Stateless
#ViewScoped
public class UserController {
#EJB
private UserDAO userDAO;
private UserEntity user;
public boolean isLoggedIn() {
return user != null;
}
public String loggingIn(LoginBean loginBean) {
FacesContext context = FacesContext.getCurrentInstance();
if(userDAO == null) {
context.addMessage("loginForm:login1Error", new FacesMessage("DAO IS NULL!"));
// return "/loginBean.xhtml?faces-redirect=true&error=1";
}
user = userDAO.getUserByLoginAndPassword(loginBean.getLogin(), loginBean.getPassword());
if (user != null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
session.setAttribute("user", user.getId());
return "/mail/mail.xhtml?faces-redirect=true";
} else {
return "/loginBean.xhtml?faces-redirect=true";
}
}
public String logout() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
return "/login.xhmtl?faces-redirect=true";
}
}
I really not understand why it not works :( What do I do wrong?
UPD: Stack trace: http://pastebin.com/istJmMHr
Source code may be downloaded from my google drive: https://docs.google.com/file/d/0B4Am7SXJwmtKNVc0LVhWVlEyMVk/view
I think you can better start with a really small example to get a grasp of things. There are many things not quite right in your code.
To start, an #Stateless bean can't be view scoped. Think about this for a moment. What would it actually mean to have a stateless view scoped bean? Why did you think you needed one in the first place?
A view should have one backing bean and this one is often view scoped. Any DTOs that you might need for that view should not be view scoped, but should just be instance variables of the main backing bean. That way they'll be automatically dependent on that scope.
In your case, make loginBean an instance variable just like the user variable.
It happend because my #ManagedBean was placed in EJB package, not in WAR package.
When I moved all #ManagedBeans into my WAR module all earned!
I have tried a bunch of suggestions after googling but none has so far worked for me. I am trying to display a simple datatable with editable inputText values in each row. table is being populated from database via a usual List of objects. Here is my xhtml page and managed bean
Richfaces 4.2.1, JSF 2 mojarra bundled with JBoss 7.1, JDK 1.6
<rich:dataTable value="#{wlScoreBean.scoreList}" binding="#{wlScoreBean.scoreTable}" var="item" id="table" style="width:100%">
<rich:column>
<f:facet name="header">PARAM NAME</f:facet>
<h:outputText value="#{item.paramName}" />
</rich:column>
<rich:column>
<f:facet name="header">1 Score</f:facet>
<h:inputText value="#{item.name1}" />
</rich:column>
<rich:column>
<f:facet name="header">2 Score</f:facet>
<h:inputText value="#{item.name2}" />
</rich:column>
</rich:dataTable>
<br/>
<h:panelGrid columns="3" id="buttonRow">
<a4j:commandButton value="Save" render="table" execute="#this" action="#{wlScoreBean.update()}">
</a4j:commandButton>
</h:panelGrid>
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.event.ValueChangeEvent;
import org.richfaces.component.UIDataTable;
#ManagedBean(name = "wlScoreBean")
#ViewScoped
public class WS implements Serializable
{
private static final long serialVersionUID = 1L;
private HtmlDataTable scoreTable;
private List<WorkloadScore> scoreList;
public void watchScore(ValueChangeEvent e)
{
System.out.println("old value="+e.getOldValue() + ", New Value="+e.getNewValue());
}
public List<WorkloadScore> getScoreList() {
return scoreList;
}
public void setScoreList(List<WorkloadScore> scoreList) {
this.scoreList = scoreList;
}
#EJB
private WorkloadScoreManagerService wlScoreManager;
public HtmlDataTable getScoreTable() {
return scoreTable;
}
public void setScoreTable(HtmlDataTable scoreTable) {
this.scoreTable = scoreTable;
}
public WorkloadScoreBean()
{
}
#PostConstruct
private void getAllScores()
{
this.scoreList = wlScoreManager.getAllScores();
}
public void update()
{
for (WorkloadScore wls : getScoreList())
{
System.out.println(wls.getParamName()+"="+wls.getPortabilityScore()+","+wls.getVirtualizationScore());
}
//wlScoreManager.update(workloadScore);
}
}
Here's all the things I tried. All of them result in only the OLD VALUES being printed to console in the update() method.
Changed from rich:dataTable to plain old JSF h:dataTable, same result
Bound the dataTable to a Managed Bean property, checked in update() method, old values are being printed here too. I just did a getVlaue() on the UIDataTable object and cast it to List.
The List is supposed to have been updated with changed values from the form, but I do not see it happening. I did make sure to put the MBean in ViewScope.
do you have a h:form outside the datatable? and did you try to replace inputtext with inplaceinput fields?
See answer here https://community.jboss.org/thread/200684?tstart=0
I changed execute=#form and it worked! no need for ValueChangeEvent or messing with dataTable binding. The List values are updated in place and the update method prints the correct value