Unable to save dynamic added row - jsf-2

I am adding row dynamicall on click of commandButton.
in which I have two textfield and one dropdown and last column is save.
I am able to save old data which are already in DB,
But unable to save the newly added row. actually control is not reaching to bean when I click on save commandLink.
<div>
<div class="float_right">
<p:commandButton styleClass="add_uom"
value="#{msg['uom.add.new.uom']}" process="#this"
actionListener="#{uomBean.addRow}" immediate="true"
update=":uomFormId:languageDetail">
</p:commandButton>
</div>
<div class="clear"> </div>
<div>
<h:panelGroup id="languageDetail">
<table width="100%" cellspacing="1" cellpadding="1"
border="0" class="role_detail_section">
<thead>
<tr>
<ui:repeat var="language" value="#{uomBean.languageList}">
<th>#{language.languageCode}</th>
</ui:repeat>
<th>#{msg['uom.measuremnet.type.heading']}</th>
<th>#{msg['uom.save']}</th>
<th>#{msg['uom.activate.deactivate.heading']}</th>
</tr>
</thead>
<tbody>
<ui:repeat var="uom" value="#{uomBean.uomDTOList}">
<tr>
<ui:repeat var="uomCountry" value="#{uom.uomList}">
<td><h:inputText styleClass="values"
value="#{uomCountry.languageValue}" /></td>
</ui:repeat>
<td><h:selectOneMenu
value="#{uom.measureTypeId}"
required="true"
requiredMessage="#{msg['uom.measurement.error.msg']}">
<f:selectItem itemLabel="Select" itemValue="0" />
<f:selectItems value="#{uomBean.measureList}"
var="uomtDTO"
itemLabel="#{uomtDTO.measurmentTypeValue}"
itemValue="#{uomtDTO.measurmentTypeId}" />
</h:selectOneMenu></td>
<td>
<p:commandLink value="Saving.." action="#{uomBean.testUOM()}" ></p:commandLink>
</td>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</h:panelGroup>
<h:messages globalOnly="true" />
</div>
</div>
UOMDTO is
private Country country;
private Language language;
private String uomDisplayName;
private String uomDescription;
private List<UOMDetailDTO> uomList;
private Integer measureTypeId;
and UOMDetailDTO is
private String languageName;
private String languageCode;
private String languageValue;

Would be nice to see the source of uomBean.
I can only guess, but if uomBean is request scoped, the new row has been "lost" by the time you click save and thus cannot be saved. If uomBean is view or session scoped, then I would guess that you somehow reset/reload your uomDTOList, loose the new row and get the same problem as if it was request scoped.

Related

tabindex doesn't work on p:selectOneMenu or h:SelectOneMenu

Tabindex attribute is not working on p:selectOneMenu that I am using in my page. I also have h:inputtext on the same page for which tabindex works fine.
I am using primefaces 4.0. Please help. After the 2nd tabindex it gets lost.
<!-- This Dialog page is being used for both ADD & EDIT APPLICANT functionality -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form id="addApplicantForm">
<div class="panel" style="width: 540px;">
<p:outputPanel id="critTabPanel" >
<div class="dlgHeader">#{applicantForITCController.action} Applicant</div>
<table width="100%" border="0" cellspacing="5px" style="font-size: 12px">
<tr>
<td style="width:30%">First Name:</td>
<td style="width:65%;padding-right: 5px" align="right">
<h:inputText id="firstName-input" styleClass="suburbinput round5 applyInput" value="#{applicantForITCController.applicantForITCInfo.firstName}"
required="true" requiredMessage="First Name required" onkeypress="return fnb.pl.events.KeyEvents.isStringKey(event)" maxlength="50" tabindex="1"/>
<p:watermark for="firstName-input" value="Enter First Name" />
</td>
<td style="width:5%">
<p:message for="firstName-input" id="msg-firstName-input" display="icon" />
</td>
</tr>
<tr>
<td style="width:30%">Last Name:</td>
<td style="width:65%;padding-right: 5px" align="right">
<h:inputText id="lastName-input" styleClass="suburbinput round5 applyInput" value="#{applicantForITCController.applicantForITCInfo.lastName}"
onkeypress="return fnb.pl.events.KeyEvents.isStringKey(event)" maxlength="50" required="true" requiredMessage="Last Name required" tabindex="2"/>
<p:watermark for="lastName-input" value="Enter Last Name" />
</td>
<td style="width:5%">
<p:message for="lastName-input" id="msg-lastName-input" display="icon" />
</td>
</tr>
<tr>
<td style="width:30%">Identity Type:</td>
<td style="width:65%;">
<div class="contGeneric">
<div class="colRight">
<div class="fnbDropMenu">
<p:selectOneMenu id="cri-idType" value="#{applicantForITCController.applicantForITCInfo.idType}"
required="true" requiredMessage="Please select an Identity Type" styleClass="selectOnDialog" tabindex="3">
<f:selectItem itemLabel="Please select" itemValue=" " noSelectionOption="true" />
<f:selectItems value="#{applicantForITCController.idTypes}" var="idTy" itemLabel="#{idTy.desc}" itemValue="#{idTy}"/>
<f:validator for="idTypeValidator"
binding="#{za.co.fnb.propertyleader.interfaces.ui.web.validator.IDTypeValidator}"/>
<f:attribute name="idNum" value="#{idNum}" />
</p:selectOneMenu>
</div>
</div>
</div>
</td>
<td style="width:5%">
<p:message for="cri-idType" id="msg-idType" display="icon" />
</td>
</tr>
<tr>
<td style="width:30%">ID/Passport No:</td>
<td style="width:65%;padding-right: 5px" align="right">
<h:inputText id="idNumber" binding="#{idNum}" styleClass="suburbinput round5 applyInput" value="#{applicantForITCController.applicantForITCInfo.idNumber}"
required="true" requiredMessage="ID/Passport Number required" maxlength="30" tabindex="4"/>
<p:watermark for="idNumber" value="Enter ID/Passport Number" />
</td>
<td style="width:5%">
<p:message for="idNumber" id="msg-idNumber" display="icon" />
</td>
</tr>
<tr>
<td style="width:30%">Cell Number:</td>
<td style="width:65%;padding-right: 5px" align="right">
<h:inputText id="cellNo" styleClass="suburbinput round5 applyInput" value="#{applicantForITCController.applicantForITCInfo.cellNo}"
required="true" requiredMessage="Cell Number required" onkeydown="return fnb.pl.events.KeyEvents.isNumericKey(event)" maxlength="10" tabindex="5"/>
<p:watermark for="cellNo" value="Enter Cell Number" />
</td>
<td style="width:5%">
<p:message for="cellNo" id="msg-cellNo" display="icon" />
</td>
</tr>
</table>
</p:outputPanel>
<div class="btnHolder dblExtraForgotPass" align="center" style="padding-top: 15px;">
<a id="colorboxCloseBtn2" class="btn InActive"
href="javascript:addApplicantDialog.hide();"><span>Cancel</span></a>
<p:commandLink process="#this #parent" update=":#{p:component('applicantForITCTbl')} :#{p:component('confirmAppPanel')}
:#{p:component('critTabPanel')} :#{p:component('msgPnl1')}"
action="#{applicantForITCController.updateApplicantForItcList}" styleClass="btn InActive"
oncomplete="fnb.pl.property.handleAddApplicantComplete(xhr, status, args)">
<span>Save</span>
</p:commandLink>
</div>
</div>
</h:form>
</ui:composition>

How to display contents in reverse order in <h:dataTable>

I am accepting data in Array and displaying it in the same screen using <h:dataTable>.
How can display contents in reverse order, i.e. show the latest entry in the first row?
Below is code can i display nonDox.non_List in reverse order
<h:body>
<h:panelGroup rendered="#{not empty dataBase}">
<h:form id="nonDoxScanForm">
<f:event listener="#{nonDox.validate_AccNo}" type="postValidate" />
<table border="0" class="InnerBox" width="55%">
<tr><th colspan="7" align="Center" class="clsTitle">Non Dox Add</th></tr>
<tr>
<td>Delivery Date</td>
<td >Consginee (F2) </td>
<td>Weight (F3)</td>
<td>SubBranch Code(F4)</td>
<td >Consignment No (F10)</td>
<td align="Center">(F12)</td>
</tr>
<tr>
<td> <p:calendar value="#{nonDox.delDate}" id="fDat" /> </td>
<td><h:inputText size="20" id="fcon" value="#{nonDox.consignee}" /> </td>
<td><h:inputText size="20" id="fweig" value="#{nonDox.weight}" >
</h:inputText> </td>
<td><h:inputText size="20" id="fsub" value="#{nonDox.subBranchCode}" >
<f:validateLength maximum="3"></f:validateLength>
</h:inputText> </td>`enter code here`
<td><h:inputText size="10" id="acno" value="#{nonDox.accNo}" onfocus="this.select()" >
</h:inputText>
</td>
<td> <h:commandButton value="Add" id="fAdd" action="#{nonDox.addAction}" onclick="return validate();" />
</td>
<td> <h:commandButton value="Save" action="#{nonDox.saveAction}" >
</h:commandButton>
</td>
</tr>
<tr>
<td colspan="7">
<h:message for="acno"/>
</td>
</tr>
</table>
<h:dataTable value="#{ nonDox.non_List}" var="o"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row" width="55%"
>
<h:column>
<f:facet name="header">Del Date</f:facet>
#{o.cor_Date.substring(0, 10)}
</h:column>
<h:column>
<f:facet name="header">consignee</f:facet>
#{o.consignee}
</h:column>
<h:column>
<f:facet name="header">Weight</f:facet>
#{o.weight}
</h:column>
<h:column>
<f:facet name="header">Rate</f:facet>
#{o.rate}
</h:column>
<h:column>
<f:facet name="header">subBranchCode</f:facet>
#{o.subBranchCode}
</h:column>
<h:column>
<f:facet name="header" >POD No</f:facet>
#{o.accNo}
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<h:commandLink value="Delete" action="#{nonDox.deleteAction(o)}" />
</h:column>
</h:dataTable>
</h:form>
<h:panelGroup >
<h:panelGroup rendered="#{empty dataBase}">
<h1>Session Expired</h1>
<h:link outcome="Login" target="CommonContent" >Login</h:link>
</h:panelGroup>
</h:body>
If you're using an List as in new ArrayList<Item>(), it's easy: use Collections#reverse():
private List<Item> data;
#PostConstruct
public void init() {
data = service.list();
Collections.reverse(data);
}
// ...
Just reference it in <h:dataTable value="#{bean.data}"> the usual way.
If you're using an array as in Item[], then you'd need to convert it to List first with help of Arrays#asList(), so that you can feed it to Collections#reverse():
private List<Item> data;
#PostConstruct
public void init() {
Item[] items = service.array();
data = Arrays.asList(items);
Collections.reverse(data);
}
// ...
Or just rewrite the service method in such way that you don't need to perform this conversion step in the backing bean.
Key is, you shouldn't expect to perform this job in the view. You should just prepare the model in such way that it's exactly as what the view expects. The <h:dataTable> itself doesn't provide any facilities like that.

jQuery UI dialog works only once; opening for second time causes ViewExpiredException when submitted

I'm working in a Java EE aplication thats uses JSF2 and Richfaces 4. We decided that some interactions would be made using modal windows, and we chose Jquery UI Dialog with h:form, because we were already using Jquery UI in this project.
The Dialog is opened correctly, and submits the form, the submit is made using a h:commandButton and a4j:ajax. The h:commandButton stays hidden, and it is triggered by a dialog button.
Everything looks like perfect, but the dialog/forms just works once. If I close and open the dialog without refreshing the page I receive the message when submit the form:
javax.faces.application.ViewExpiredException:
viewId:/frontend/inicial.xhtml - /frontend/inicial.xhtml could not be restored
The JSF/HTML of dialog:
<h:panelGroup id="dialog-nova-intercorrencia" styleClass="ui-dialog-content ui-widget-content">
<h:form id="frm-dialog-nova-intercor" prependId="false">
<table>
<tr>
<td>Paciente</td>
<td>
<h:selectOneMenu id="sel-intern-intercor" value="#{intercorrenciaController.novaIntercorrencia.internacao.internacaoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{internacaoController.listInternacoesSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>Impacto</td>
<td>
<h:selectOneMenu id="sel-impacto" value="#{intercorrenciaController.novaIntercorrencia.impacto.impactoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{intercorrenciaController.listaImpactosSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
Data e Hora
</td>
<td>
<h:inputText value="#{intercorrenciaController.dataIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 130px" />
 
<h:inputText value="#{intercorrenciaController.horaIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 70px" />
</td>
</tr>
<tr>
<td>Resumo</td>
<td><h:inputText value="#{intercorrenciaController.novaIntercorrencia.resumo}" size="25" styleClass="ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td colspan="2">
Comentarios
<br />
<h:inputTextarea cols="30" rows="3" value="#{intercorrenciaController.novaIntercorrencia.descricao}" />
</td>
</tr>
</table>
<h:commandButton id="btt-add-nova-intercor" action="#{intercorrenciaController.cadastrarIntercorrencia}" style="display:none">
<a4j:ajax execute="#form" render="#form frm-dialog-nova-intercor panel-lista-intercorrencias" />
</h:commandButton>
</h:form>
</h:panelGroup>
The JS to create jQuery UI Dialog:
$("#dialog-nova-intercorrencia").dialog({
position: {
my: "top top",
at: "top top",
of: window
},
autoOpen: false,
height: 350,
width: 400,
draggable: false,
resizable: false,
modal: true,
buttons: {
"Cadastrar": function() {
$("#btt-add-nova-intercor").trigger("click");
},
"Cancelar": function() {
$( this ).dialog( "close" );
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
},
close: function() {
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
});
Does anyone knows the reason I can execute the form in dialong only once and in the second time I get the message "view could not be restored" ?
The problem was the JS that I was using to clear the fields before close the dialog:
$(this).find("input").val("");
It was setting the input hidden javax.faces.ViewState in the form with null.
<input type="hidden" name="javax.faces.ViewState" value="" />

p:commandButton does not work in the last ajax request

I have to Tab in selectoneButton as "request" and "archive". In that tab I have information that is called with ajax. In that information I need to have a button As "acceptCommonButton" and "noNowCommonButton" so when a User clicks on the "acceptCommonButton" button it calls the "acceptRequest" method. When a user Clicks on "noNowCommonButton" button it calls to "notNowRequest" method.
My problem is that the Button Works until the last request is in "archive" Tab. It means that when the last request is in "request" tab my Button does not work. it's too Weird!!!!
I think the problem here is caused by DataGrid.
could you please see my Code?!!
<table style="width: 100%">
<tr>
<td>
<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
<f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request"/>
<f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
<f:ajax event="change" render="requestDataGrid" />
</p:selectOneButton>
</td>
</tr>
<tr>
<td>
<p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo"
value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" rows="22" >
<p:column>
<div>
<table border="0" width="100%">
<tr>
<td>
<p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
</td>
<td>
<div>
<table border="0" width="100%">
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
</td>
</tr>
</table>
</div>
</td>
<td>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" process="#form">
</p:commandButton>
</td>
<td>
<p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" process="#form">
</p:commandButton>
</td>
<td>
<p:panel>
<p:ajaxStatus>
<f:facet name="start">
<p:graphicImage value="../resources/img/loading.gif"/>
</f:facet>
<f:facet name="complete">
<h:outputLabel value=""/>
</f:facet>
</p:ajaxStatus>
</p:panel>
</td>
</tr>
</table>
</div>
<hr/>
</p:column>
</p:dataGrid>
<p:panel>
</p:panel>
</td>
</tr>
</table>

How to show A success message on jsf 2

How can i make the success message display out? I have the following code, but only the warning message appear. What do i have to change so that the success message will be display out in my success page ?
userbean.java :
public String Login() throws Exception {
String status = "failure";
current=userBo.validateUser(getLogin(),getPass());
if(current!=null){ exist=false; status = "success";
String message = "submitted successfully !!";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(message)); }
exist=true; return status; }
login.xhtml :
<f:view>
<h:form>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Username</th>
<td><h:inputText value="#{user.login}"
styleClass="login-inp" /></td>
</tr>
<tr>
<th>Password</th>
<td><h:inputSecret value="#{user.pass}"
onfocus="this.value=''" styleClass="login-inp" /></td>
</tr>
<tr>
<th></th>
<!-- <td><input type="button" class="submit-login" /> -->
<td><h:commandButton action="#{user.checkUser}" styleClass="submit-login" />
<h:messages globalOnly="true" />
</td>
</tr>
</table>
</h:form>
</f:view>
success.xhtml :
<h:form>
<h:body>
<h1>heyyyy ,y sucseded !!!</h1> <br/><br/>
<h:commandLink action ="#{user.logout}" > disconnect </h:commandLink>
</h:body>
</h:form>
warning message :
Infos: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(INFO 0), summary=(submitted successfully !!), detail=(submitted successfully !!)]
Your <h:messages globalOnly="true" /> is been placed in the wrong view. You placed it in login.xhtml, but you're navigating to success.xhtml on success instead of returning to login.xhtml. If you put the <h:messages globalOnly="true" /> in success.xhtml, then it will be displayed the way you expected.
on your action method i.e. action="#{user.checkUser}" return a string that string will decide which page to show using your faces-config.xml file.
eg.
< navigation-rule>
< from-view-id>*< /from-view-id>
< navigation-case>
<from-outcome>ReturnedString</from-outcome>
<to-view-id>success.xhtml(path of your file)</to-view-id>
<redirect/>
</navigation-case>
< /navigation-rule>
this will definately work.

Resources