how to edit single row in rich:dataTable - modal-dialog

i have to edit a row in a table using rich faces 4 and modal panel. I am new one so please tell me in details and i know to make a table in rich faces. i already searched so many things but not getting any fruitful

See answer for question "Richfaces: show details in popup [commandbutton, action and popupPanel]". It works in RichFaces 4.x with rowClick.
Or here is example with commandLink:
<a4j:commandLink action="#{actionBean.setupTransactionDetails}"
event="onclick" render="transactionDetails"
oncomplete="#{rich:component('transactionDetails')}.show()"
styleClass="rich-link">
<h:outputText value="#{res.transactionType}" />
<f:setPropertyActionListener value="#{res.transactionId}"
target="#{profile.transactionId}" />
</a4j:commandLink>
But I prefer updated version like this:
<a4j:jsFunction name="showDetail" action="#{actionBean.setupTransactionDetails}"
oncomplete="#{rich:component('transactionDetails')}.show();"
render="transactionDetails">
<a4j:param name="id" assignTo="#{profile.transactionId}"
converter="javax.faces.Long" />
</a4j:jsFunction>
<rich:dataTable id="txnTable" rows="#{referenceData.recordsPerPage}"
style="width: 100%" rowClasses="oddrow, evenrow"
value="#{profile.transactions}" var="res" sortMode="single">
<h:column width="110">
<f:facet name="header">
<h:outputText value="#{msg.transactionType}" />
</f:facet>
<a4j:commandLink onclick="showDetail('#{res.transactionId}');"
value="#{res.transactionType}" />
</h:column>
</rich:dataTable>
<rich:popupPanel id="transactionDetails" autosized="true"
style="max-height:600px;">
<!-- f:facet name="header" and f:facet name="controls" here -->
<h:form id="transactionDetailsForm">
<!-- some details here -->
</h:form>
</rich:popupPanel>
Profile backing bean
private Long transactionId; // + getter and setter
Action backing bean
public void setupTransactionDetails() {
Transaction txn = DAO.getInstance().get(Transaction.class, getProfile().getTransactionId());
transactionForm.setup(txn);
}
In case if you use EL 2.2 (or higher) you can call action bean method with parameter.

Related

Primefaces v.5.3.5 confirm dialog render issue outside main h:form and inside main form is rendered but it is not working properly

I am using PF v.5.3.5 and JSF v.2.2.8. It is a frequent topic in SO. I noticed that there is a bug in PF v.5.3.5 documentation related to the appendTo attribute.
1st approach
The p:confirmDialog is rendered and commandbuttons are rendered but actions does not work and message is not rendered if it is placed inside of nested h:form.
2st approach
If I place this dialog outside of main h:form it is not rendered at all also if I add the global="true" attribute.
3st approach
The p:confirmDialog is rendered and commandbuttons are rendered but actions does not work and message is rendered if the nested h:form is removed.
<h:form>
...
<p:confirmDialog id="askSessionDialog1" widgetVar="askSessionDialog1" severity="alert"
appendTo="#(body)" rendered="#{treeData.askSessionDialogRendered}" visible="#{treeData.askSessionDialogRendered}">
<h:form>
<f:facet name="message">
<h:outputText value="#{msg.WEB_ADMIN_PAGES_TREESEGMENT_NOSESSION}" escape="false"/>
</f:facet>
<p:commandButton value="#{msg.WEB_BUTTONS_OK}" action="#{treeData.save(false, true)}" icon="fa fa-check"
update="#(form)" type="button" />
<p:commandButton value="#{msg.WEB_BUTTONS_CANCEL}" action="#{treeData.setAskSessionDialogRendered(false)}"
icon="fa fa-close" onclick="PF('askSessionDialog1.hide()')" update="#(form)" type="reset" />
</h:form>
</p:confirmDialog>
...
</h:form>
BECKEND PART
setAskSessionDialogRendered(true);
RequestContext.getCurrentInstance().update("treeSegmentForm askSessionDialog askTurnOffDialog askSessionDialog1 askTurnOffDialog1");
Thanks in advance for constructive posts and comments.
SOLVED
This is the best approach that works for me now.
<h:form>
...
<p:confirmDialog id="askSessionDialog" widgetVar="askSessionDialog" severity="alert"
appendTo="#(body)" rendered="#{treeData.askSessionDialogRendered}" visible="#{treeData.askSessionDialogRendered}">
<f:facet name="message">
<h:outputText value="#{msg.WEB_ADMIN_PAGES_TREESEGMENT_NOSESSION}" escape="false"/>
</f:facet>
<h:form>
<p:commandButton value="#{msg.WEB_BUTTONS_OK}" icon="fa fa-check" type="button" accesskey="o">
<p:ajax event="click" listener="#{treeData.save(false, true)}" oncomplete="PF('askSessionDialog').hide()"
update="#(form)" />
</p:commandButton>
<p:commandButton value="#{msg.WEB_BUTTONS_CANCEL}" icon="fa fa-close" type="reset" accesskey="c">
<p:ajax event="click" listener="#{treeData.setAskSessionDialogRendered(false)}"
onsuccess="PF('askSessionDialog').hide()" update="#(form)" />
</p:commandButton>
</h:form>
</p:confirmDialog>
...
</h:form>
BACKEND
setAskSessionDialogRendered(true);
RequestContext.getCurrentInstance().update("treeSegmentForm");
SPACIAL THANKS TO: #YagamiLight
He helped me to kick off my solution.

Strange javax.el.PropertyNotFoundException, does not work with manual deploy but works in eclipse deploy

I'm having a problem to declare a property in a managed bean (JSF 2.2), I have already read other questions about name convention of property in beans and mine appears to be ok. My page.jsf is a ui composition and the property name is a date: private Date dataSemAtendimento. This is the calendar tag of primefaces (5.1) that I'm working with:
<p:dialog header="Escolha as data de feriado e ponto facultativo"
widgetVar="modalCalendar" id="modalCalendar" modal="true" width="400"
height="500" appendTo="#(body)">
<p:calendar id="popup" widgetVar="popupCal"
value="#{postoAtendimentoBean.dataSemAtendimento}">
</p:calendar>
<p:commandButton value="Adicionar data" update="tableCal">
<p:ajax listener="#{postoAtendimentoBean.adicionarDataFeriado}" />
</p:commandButton>
<p:dataList id="tableCal"
value="#{postoAtendimentoBean.postoDiaSemAtendimentoList}" var="data"
style="width:50%">
<f:facet name="header">
Datas que não ocorreram o atendimento
</f:facet>
<p:column>
<h:outputText value="#{data}">
<f:convertDateTime locale="pt" />
</h:outputText>
</p:column>
<p:column>
<p:commandButton icon="ui-icon-trash" update="tableCal"
action="#{postoAtendimentoBean.removerDataFeriado(data)}">
<p:ajax listener="#{postoAtendimentoBean.removerDataFeriado(data)}"></p:ajax>
</p:commandButton>
</p:column>
</p:dataList>
<p:separator />
<p:panelGrid style="margin: auto;">
<p:commandButton value="Confirmar" onclick="PF('modalCalendar').hide();" />
</p:panelGrid>
</p:dialog>
And this is the managed bean code related to the get/setter:
#ManagedBean
#ViewScoped
public class PostoAtendimentoBean extends AbstractCRUDBean<PostoAtendimento, Long> {
private Date dataSemAtendimento;
public Date getDataSemAtendimento() {
return dataSemAtendimento;
}
public void setDataSemAtendimento(Date dataSemAtendimento) {
this.dataSemAtendimento = dataSemAtendimento;
}
}
Error Rendering View[/resources/template/template.xhtml]: javax.el.PropertyNotFoundException: /pages/cadastros/posto_atendimento/manter_posto_atendimento_persistencia.xhtml #161,25 value="#{postoAtendimentoBean.dataSemAtendimento}": The class 'br.com.webtech.scheduler.bean.postoatendimento.PostoAtendimentoBean' does not have the property 'dataSemAtendimento'.
I'm running in a wildfly (8.2.1) instance, but the strange thing is when I deploy it manually it doesn't work but when I deploy via eclipse adding the ear inside the server tab it works normally. I'm lost, already tried a couple of things. Any ideas? Thanks.
Another strange thing is, this started to happen when I changed the context-root of my application via Maven webModule tag.
Edit: I made a workaround by copying the .class with the wrong context-root and putting it inside the generated ear with the new context-root, that works but it's an awlful way to solve the problem.

commandLink not work primefaces mobile

primefaces mobile commandLink action does not work, it's not loading the page with id="station1". f:setPropertyActionListener is work and call setSelectedStation() method .
<pm:page id="fastStationPage">
<pm:header title="Fast Charging Station" swatch="b" ></pm:header>
<pm:content>
<h:form id="stationsDetailsForm">
<p:growl id="messages" showDetail="true" />
<p:dataList value="#{navigationViewImpl.fastStationList}" var="station" type="ordered">
<p:commandLink value="#{station.name}" action="pm:station1?transition=slide" update=":station1:stationDetail">
<f:setPropertyActionListener value="#{station}" target="#{navigationViewImpl.selectedStation}" />
</p:commandLink>
</p:dataList>
</h:form>
</pm:content>
</pm:page>
<pm:page id="station1">
<pm:content>
<h:outputText id="stationDetail" value="#{navigationViewImpl.selectedStation.name}" escape="false"/>
</pm:content>
</pm:page>
public void setSelectedStation(StationDTO selectedStation) {
this.selectedStation = selectedStation;
}
I got answer. I not configure face-config.xml file. I am not add navigation-handler
<application>
<navigation-handler>
org.primefaces.mobile.application.MobileNavigationHandler
</navigation-handler>
</application>

jsf inputText disabled and readonly properties in form

This question is a follow on from a previous question "InputText value null when disabled is true" however I can not add comments to it.
I am using jsf 2.2 and the both the disabled and readonly properties when set true, for the inputText and inputTextarea controls when included in a form is deleting data from the associated field in the database when the object is merged because the fields are null when the object is returned from the jsf page.
The purpose for setting these properties on a form's field is to display the data in the field but not allow the user to change it and save changes to other fields in the form.
What other way can this be achieved other than placing the fields outside of the form and complicate the page layout.
Graham
I solved the problem, it was caused by using #RequestScoped instead of #SessionScoped for my page controller bean.
What I was doing was using a edit link from a datatable passing the current product object to the doEditProduct method.
<h:dataTable id="viewProductsTable" value="#{productController.products}" var="_product"
styleClass="data-table" headerClass="table-header" rowClasses="table-row">
<h:column>
<f:facet name ="header">
<h:outputText value="Product Name" />
</f:facet>
<h:outputText value="#{_product.productName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Goal"/>
</f:facet>
<h:outputText value="#{_product.goal}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Details"/>
</f:facet>
<h:outputText value="#{_product.description}"/>
</h:column>
<h:column>
<h:form>
<h:commandLink value="Edit" action="#{productController.doEditProduct(_product)}"/>
</h:form>
</h:column>
</h:dataTable>
the productController.doEditProduct method then opened the edit page
public String doEditProduct(Product product) {
this.product = product;
return "edit-product.xhtml";
the edit page contained a simple edit form
<h:form id="addProductForm">
<h:panelGrid columns="2" columnClasses="top-alignment, top-alignment">
<h:outputLabel for="product-name" value="Product Name"/>
<h:outputText value="#{productController.product.productName}" id="product-name" />
<h:outputLabel for="goal" value="Goal" />
<h:inputTextarea value="#{productController.product.goal}" id="goal" rows="10" cols="100" />
<h:outputLabel for="details" value="Details" />
<h:inputTextarea value="#{productController.product.description}" id="details" rows="20" cols="100"/>
<f:facet name="footer">
<h:panelGroup style="padding-top: 15px; display: inline-block; float: right; white-space: nowrap">
<h:commandButton id="submit" value="Save" action="#{productController.updateProduct()}" class="button" />
<h:button id="Cancel" outcome="index.xhtml" value="Cancel" class="button"/>
</h:panelGroup>
</f:facet>
</h:panelGrid>
</h:form>
At this point the product data was displayed on the page. However when the save button was clicked and ran the update method
public String updateProduct() {
try {
log.log(Level.INFO, "Updating: {0}", product.getGoal());
productFacade.edit(product);
} catch (Exception e) {
log.log(Level.WARNING, e.toString());
String errorMessage = getRootErrorMessage(e);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "could not update product");
facesContext.addMessage(null, m);
return "";
}
return "index.xhtml";
Any field that had was disabled or readonly was set to null. In fact any non input field, anywhere on the page was set to null.
#RequestScope on the controller class meant that the class was being reinstantiated and thus the object stored in product was being assigned a new object in the PostConstruct method. The values in the editable fields were transferred to this new object and the non editable fields were set to null. Merging with the database meant that the data in the fields was deleted.
Using #SessionScoped means that the controller beans continues to exist across page requests. (I needed to remind myself about basic web page lifecycles)
Hope this helps anybody else that has this behaviour.
Graham

jboss rich dataTable wrong data

<rich:dataTable id="companyList" var="company"
value="#{companyList.resultList}"
rowClasses="odd-row, even-row"
rendered="#{not empty companyList.resultList}">
<rich:column width="25px" style="text-align:center;">
<f:facet name="header">#{messages.Edit}</f:facet>
<a4j:commandLink reRender="companyPanel"
oncomplete="#{rich:component('companyPanel')}.show()"
style="align: center;"> <f:setPropertyActionListener target=
"#{companyHome.instance}"
value="#{company}" />
<rich:toolTip value="#{messages.Edit}" />
</a4j:commandLink>
</rich:column>
<h:column>
<f:facet name="header">
#{messages.companyName}</f:facet>
#{company.companyName}
</h:column>
</rich:dataTable>
Hi I have some problem my rich datatable. All operation work normally , I search some data in dataTable ,I get true list in datatable but, If I try to update some data in column , wrong instance coming. Forexample , I choose banana which name is my data , but it brings before searching data not bring banana. I do not understand why. Sorry my english.
Not sure but, have you tried this
<f:setPropertyActionListener target="#{companyHome.id}" value="#{company.id}" />
instead of
<f:setPropertyActionListener target="#{companyHome.instance}" value="#{company}" />