hi to all
am newbie to jsf , i have made a page in which in this page am retrieving
all the new rows (messages) from the table with flag='not_validated' and
after that those messages will be displayed in the page and i have made a
flag in which the user can check or uncheck the box , if the box is checked
i ll change the flag from 'not_validated' to 'accepted' and if he unchecked
the flag it will updated as 'refused' but this will happend once the user
click on 'validate' button ,
by the way the page will be automatically refreshed if there is no rows are
displayed , so that if there are no displayed messages in the page it will
be refreshed automatically and will check whether any records are inserted
to the table or not ,
the problem is that , when the new message comes inserted to the table it
will be displayed in the page , now during the few seconds of the user
validation of this new record if new record has been inserted to the
database before the user click on validate ,
so now in the secnario one new record is displaying in the page for the user
, and another new record is inserted in the table but it is not displayed ,
now if the user validate the record which is displaying in the current page(
by clicking on validate button ,) the getter of the messages will be called
again and we will have 2 records not one and both of the records will be
updated instead on only one record (which was displyaing)
so for me i want to validate only the records which were displayed to the
user
so is there any way to avoid calling the getter of the messages once the
user click on validate button , or is there any other way to do that
please help me
the java bean is
/**
*
*/
package com.lit.screen.backoffice.web.bean;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.richfaces.component.UIDataTable;
import com.lit.screen.backoffice.api.account.Account;
import com.lit.screen.utils.log.Log;
import com.lit.screen.view.api.IValidator;
import com.lit.screen.view.api.Message;
/**
* @author ahasan
*
*/
public class ValidationBean extends BaseBean {
private IValidator validator;
private UIDataTable table;
private List<Message> messages;
private Long messagesSize;
private boolean pollEnabled = true;
private Long limitBy;
private static final String CONF_PATH = System
.getProperty("jboss.server.home.dir")
+ File.separator
+ "conf"
+ File.separator
+ "lit-screen-messages-limit.xml";
public ValidationBean(){
Log.getLogger(this.getClass()).info("ValidationBean -->
ValidationBean -->
Constractor ");
processMessages();
}
public List<Message> getMessages() {
return this.messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
public void save(ActionEvent ae) {
Log.getLogger(this.getClass()).info("ValidationBean --> Save -->
Starting");
List<Message> messagesList = new ArrayList<Message>();
Log.getLogger(this.getClass()).info("ValidationBean --> Save
--> Current
size is"+this.messages.size());
for(Message message:this.messages){
if (message.getId()!=null){
Log.getLogger(this.getClass()).info("ValidationBean --> Save --> Added
to the list");
messagesList.add(message);
}
}
Log.getLogger(this.getClass()).info("ValidationBean --> Save
--> Current
size is"+messagesList.size());
this.validator.updateMessages(messagesList);
Log.getLogger(this.getClass()).info("ValidationBean --> Save
--> Ending");
processMessages();
}
public IValidator getValidator() {
return validator;
}
public void setValidator(IValidator validator) {
this.validator = validator;
}
public UIDataTable getTable() {
return table;
}
public void setTable(UIDataTable table) {
this.table = table;
}
public boolean isPoll() {
return messages.size() == 0;
}
public void pollListener(ActionEvent ae) {
if (messages == null || messages.size() <= 0) {
messages = validator.getUnValidatedMessages((Account)
userInfo
.getUser());
this.messagesSize = (long) messages.size();
}
}
/**
* @return the messagesSize
*/
public Long getMessagesSize() {
return messagesSize;
}
/**
* @param messagesSize
* the messagesSize to set
*/
public void setMessagesSize(Long messagesSize) {
this.messagesSize = messagesSize;
}
/**
* @return the pollEnabled
*/
public boolean isPollEnabled() {
return this.pollEnabled;
}
/**
* @param pollEnabled
* the pollEnabled to set
*/
public void setPollEnabled(boolean pollEnabled) {
this.pollEnabled = pollEnabled;
}
/**
* @return the limitBy
*/
public Long getLimitBy() {
// this.limitBy = (long) 10;
XMLConfiguration messagesLimit = null;
try {
messagesLimit = new XMLConfiguration(CONF_PATH);
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
Log.getLogger().info(
"Unable to read the limit of the
messages configuration file . Reason :
"
+ this.limitBy);
}
this.limitBy = (long) messagesLimit.getInt("message.limit");
return this.limitBy;
}
/**
* @param limitBy
* the limitBy to set
*/
public void setLimitBy(Long limitBy) {
this.limitBy = limitBy;
}
public void processMessages() {
if (this.limitBy == null) {
this.limitBy = (long) 10;
Log.getLogger()
.info(
"limit has been
assigned the default value "
+
this.limitBy);
} else {
Log.getLogger().info(
"limit has been assinged file for the
file and its value is "
+ this.limitBy);
}
this.messages = this.validator.getUnValidatedMessagesWithLimit(
(Account) userInfo.getUser(),
this.getLimitBy());
if (this.messages == null) {
this.messagesSize = (long) 0;
this.pollEnabled = true;
} else {
this.messagesSize = (long) this.messages.size();
if (this.messagesSize == 0) {
this.pollEnabled = true;
} else {
this.pollEnabled = false;
}
}
}
}
and the jsf page is validator.xhtml
<!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:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<f:loadBundle basename="resources" var="msg" />
<ui:composition template="/templates/commonViewer.xhtml">
<ui:define name="scripts">
function checkUncheckAll(thisCheckbox) {
var el;
var elid = 0;
var whichBox = thisCheckbox.checked;
var thisForm = thisCheckbox.form;
while (el = thisForm[elid++])
{
if (el.type == 'checkbox')
{
el.checked = whichBox;
}
}
}
</ui:define>
<ui:define name="pageTitle">#{msg.validator}</ui:define>
<ui:define name="pageHeader">#{msg.validator}</ui:define>
<ui:define name="body">
<h:form>
<a4j:poll id="validatorPoll" interval="5000"
reRender="messageTable"
enabled="#{validationBean.pollEnabled}"></a4j:poll>
<rich:panel id="templatesPanel"
header="#{msg.messageList}">
<rich:dataTable id="messageTable"
binding="#{validationBean.table}"
align="center"
value="#{validationBean.messages}"
var="message">
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg.messageId}" />
</f:facet>
<h:outputText
value="#{message.validatedMessageId}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg.messageFrom}" />
</f:facet>
<h:outputText
value="#{message.from}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg.messageContent}" />
</f:facet>
<h:outputText
value="#{message.content}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg.messageDate}" />
</f:facet>
<h:outputText
value="#{message.date}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="#{msg.messageValidate}"/>
<h:selectBooleanCheckbox id="checkuncheckall"
onclick="checkUncheckAll(this)"/>
</f:facet>
<h:selectBooleanCheckbox value="#{message.valid}" />
</rich:column>
</rich:dataTable>
</rich:panel>
<h:outputLabel value="#{validationBean.pollEnabled}"
style="color:white;"
/>
<a4j:commandLink
actionListener="#{validationBean.save}"
value="#{msg.messageValidate}" reRender="messageTable , validatorPoll"
immediate="true" ></a4j:commandLink>
</h:form>
</ui:define>
</ui:composition>
</html>
i have defined the bean as following in the faces.config
<managed-bean>
<managed-bean-name>validationBean</managed-bean-name>
<managed-bean-class>com.lit.screen.backoffice.web.bean.ValidationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>userInfo</property-name>
<property-class>com.lit.screen.backoffice.web.bean.UserInfoBean</property-class>
<value>#{userInfo}</value>
</managed-property>
<managed-property>
<property-name>validator</property-name>
<property-class>com.lit.screen.view.api.IValidator</property-class>
<value>#{validator}</value>
</managed-property>
</managed-bean>
--
View this message in context:
http://www.nabble.com/avoid-calling-getter-when-the-form-is-submitted-tp20498548p20498548.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.