p:commandLink not working with dataTable - jsf

My dataTable is populated by an ajax call, my commandLink (in the datataable) is not pointing to the correct location and always render the same page.and show me in the console :
HtmlLabelRend W Attribute 'for' of label component with id j_id1471051656_3ffdbef6:j_id1471051656_3ffdbfc6 is not defined
But when I put the commandlink outside the datatable the action method works fine.
This problem is rare!, How Can I solve it?
Thanks in advance.
My Jsf Page:
<h:form>
<p:panel header="Busqueda">
<p:panelGrid style="width:100%;">
<p:row>
-----------------------------------(inputs)---------------------------------------
<p:column>
<p:commandButton value="Buscar" update="grilla"
action="#{devolucionAdminController.buscarSD()}">´
</p:commandButton>
</p:column>
</p:row>
</p:panelGrid>
<p:messages closable="true" redisplay="true" id="msj"></p:messages>
</p:panel>
<p:dataTable id="grilla" var="r"
value="#{devolucionAdminController.listado}"
emptyMessage="No se han encontrado solicitudes de devolución">
<p:column headerText="Sec">
<h:outputText value="#{r.idSoliDevo}" />
</p:column>
<p:column headerText="Cuenta">
<h:outputText value="#{r.cuentaId}" />
</p:column>
<p:column headerText="Ver Detalle Sol. Dev ">
<p:commandLink
action="#{bajaController.mostrarSolicitudBaja(r.cuentaId,r.idSoliDevo)}" ajax="false">
<p:commandButton icon="ui-icon-search" title="Ver Detalle" />
</p:commandLink>
</p:column>
</p:dataTable>
<!--works fine -->
<p:commandLink action="#{bajaController.mostrarSolicitudBaja(80003,340)}"
ajax="false">
<p:commandButton icon="ui-icon-search" title="Ver Detalle" />
</p:commandLink>
</h:form>
My first Managed Bean:
#ManagedBean
#RequestScoped
public class DevolucionAdminController {
List<TaSoliDevo> listado;
//getters and setters
........................
public void buscarSD() {
.............................
}
My second Managed Bean:
#ManagedBean
#RequestScoped
public class BajaController {
public String mostrarSolicitudBaja(long cuentaId, long solicDevId) {
.........................
return "goResult";
}}

Use process="#this" and use actionListener instead of action
<p:commandLink process="#this" actionListener="#{bajaController.mostrarSolicitudBaja(80003,340)}"></p:commandLink>

I had the same problem and I was struggling to find a solution but nothing worked for me. Here is how I finally solved the problem :
I removed the ajax attribute
I added process="#this"
Here is what my commandLink looks like after the changes :
<p:commandLink process="#this" action="#{projsSummaryBacking.redirectProjTasks(proj)}" >
<h:outputText value="#{proj.title}" />
</p:commandLink>
I hope that this can help someone. /m\

remove the ajax="false" tag, its work for me

replace your commandLink with
<p:commandButton icon="ui-icon-search" title="Ver Detalle"
action="#{bajaController.mostrarSolicitudBaja(r.cuentaId,r.idSoliDevo)}" ajax="false"/>
Really no need to put a command button inside a command Link, just to put an icon

Related

Create edit form for Primefaces table

I want to create edit form for Primefaces table. I tested this code:
<h:form id="form">
<p:dataTable id="tbl" var="systemuser" value="#{systemusers.systemUsers}"
selectionMode="single" selection="#{systemusers.selectedSystemUser}" rowKey="#{systemuser.username}" lazy="true"
resizableColumns="true"
>
<p:ajax event="rowSelect" listener="#{systemusers.onRowSelect}" update=":form:carDetail" oncomplete="PF('carDialog').show()" />
....................
</p:dataTable>
<p:dialog id="wd" header="System User Details" widgetVar="carDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="true">
<p:outputPanel id="carDetail" style="text-align:center;">
<p:panelGrid columns="2" columnClasses="label,value">
<h:outputLabel for="id" value="ID" />
<p:outputLabel id="id" value="#{systemusers.selectedSystemUser.id}" rendered="#{not systemusers.editable}"/>
<h:inputText value="#{systemusers.selectedSystemUser.id}" rendered="#{systemusers.editable}" />
........
</p:panelGrid>
</p:outputPanel>
<f:facet name="footer">
<p:commandButton value="Edit System User" rendered="#{not systemusers.editable}"
actionListener="#{systemusers.editRecord(false)}">
<f:ajax render=":form:wd" execute=":form:wd"></f:ajax>
</p:commandButton>
<p:commandButton value="Cancel" rendered="#{systemusers.editable}" actionListener="#{systemusers.editRecord(true)}">
<f:ajax render=":form" execute=":form"></f:ajax>
</p:commandButton>
</f:facet>
</p:dialog>
<p:contextMenu for="tbl">
<p:menuitem value="View" update="carDetail" icon="fa fa-search" oncomplete="PF('carDialog').show()"/>
<p:menuitem value="Delete" update="tbl" icon="fa fa-remove" actionListener="#{systemusers.deleteSystemUser}">
<p:confirm header="Confirmation" message="Are you sure?" icon="fa fa-warning" />
</p:menuitem>
</p:contextMenu>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="fa fa-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="fa fa-remove" />
</p:confirmDialog>
</h:form>
Managed bean:
#Named
#RequestScoped
public class Systemusers implements Serializable
{
.......
public void editRecord(boolean editable)
{
SessionFactory factory = HibernateUtils.getSessionFactory();
Session session = factory.getCurrentSession();
try
{
session.getTransaction().begin();
SystemUsersModel obj = new SystemUsersModel();
obj.setId(selectedSystemUser.getId());
..........
session.update(obj);
session.getTransaction().commit();
this.editable = editable;
}
catch (Exception e)
{
e.printStackTrace();
session.getTransaction().rollback();
}
}
......
private boolean editable = false;
public boolean isEditable()
{
return editable;
}
public void setEditable(boolean editable)
{
this.editable = editable;
}
}
When I open the Edit form and I click button Edit System User the form disappears. Probably because I render and execute it. How I can execute the form and under it without closing it?
The example code is bad in multiple ways. Two things stand out:
It is not an [mcve]
<f:ajax render=":form" execute=":form"> is superfluous or might even cause the weird behaviour
OP most likely does not know that (quote from the PrimeFaces showcase , emphasis mine)
CommandButton
CommandButton extends the standard h:commandButton with ajax, partial processing and skinning features.
So the commandBotton is already ajax anabled and does not need to hava a
<f:ajax render=":form" execute=":form">
inside it. This (most likely) makes an the update run twice. One #none (Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes) and one updating the form. The second one most likely does not have any content. But trying (and debugging) will make things clear. If this is not the answer, the reason cannot be seen in the code and hence it should have been a [mcve]

commandLink within PickList in Primefaces passes null value to the managed bean

I am using Primefaces 5.0 and on one of my pages I have this picklist:
<h:form>
...
<p:pickList id="aspectPickList" styleClass="camsPickList" value="#{userAccountMB.aspects}" var="aspect" itemValue="#{aspect}"
itemLabel="#{aspect.aspectName}" showSourceFilter="true" showTargetFilter="true" converter="appAspectConverter">
<f:facet name="targetCaption">#{msg['createUser.userAspects.assignedAspects']}</f:facet>
<f:facet name="sourceCaption">#{msg['createUser.userAspects.availableAspects']}</f:facet>
<p:column>
<h:outputText id="aspectName" value="#{aspect.aspectName}" />
<p:tooltip id="toolTipAspectDescription" for="aspectName" value="#{aspect.description}" />
</p:column>
<p:column style="width:30px;">
#{aspect}
<p:commandLink process="#this" oncomplete="PF('aspectDetailsDialog').show();" actionListener="#{userAccountMB.setSelectedAspect(aspect)}">
<p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
</p:commandLink>
</p:column>
</p:pickList>
...
</h:form>
Managed bean setSelectedAspect method looks like this:
public void setSelectedAspect(AppAspect selectedAspect) {
this.selectedAspect = selectedAspect;
}
The Scope of the Managed Bean is view.
When I click on the command link with icon, the setSelectedAspect method is invoked, but the selectedAspect parameter is null.
What I need to achieve is to show AspectDetails dialog after clicking the commandLink. The AspectDetails dialog contains details about the previously selected aspect.
if I update the code this way:
<p:column style="width:30px;">
#{aspect}
<p:commandLink process="#this" oncomplete="PF('aspectDetailsDialog').show();" actionListener="#{userAccountMB.selectAspect(aspect)}">
<p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
</p:commandLink>
</p:column>
the #{aspect} directive correctly displays the object signature: com.xyz.app.domain.AppAspect#69e1f7aa.
What am I doing wrong? Do I miss something?
I had the same error, try this:
<p:pickList ...>
<p:ajax event="select" listener="#{userAccountMB.selectAspectEvent}">
<f:attribute name="aspectParam" value="#{aspect}" />
</p:ajax>
<f:facet ...>
<f:facet ...>
<p:column>...</p:column>
<p:column style="width:30px;">
<p:commandLink process="#this" oncomplete="PF('aspectDetailsDialog').show();">
<p:graphicImage value="#{resource['images:questionmark_icon.jpg']}" />
</p:commandLink>
</p:column>
</p:pickList>
And the controller:
public void selectAspectEvent(SelectEvent event) {
AppAspect aspectParam = (AppAspect) event.getObject();
if(aspectParam!=null){
this.selectedAspect = aspectParam;
}
}
Regards

PrimeFaces Composite Components: commandLink doesn't work in dataTable

'
<cc:implementation>
<p:outputLabel value="#{cc}"/>
<p> <p:commandButton value="Vedi lista file" actionListener="#{cc.researchFileInDirectory}" update="panelFileLog"/></p>
<h:panelGrid id="panelFileLog">
<p:dataTable var="file" rendered="#{cc.viewFileList}" binding="#{cc.listaFile}">
<p:column headerText="File" style="width:100px">
<h:outputText value="#{file.toString()}" />
</p:column>
<p:column headerText="Link" style="width:100px">
<p:commandLink id="downloadLink" value="download" ajax="false" actionListener="cc.downloadFile">
<p:fileDownload value="#{cc.file}" />
</p:commandLink>
</p:column>
</p:dataTable>
</h:panelGrid>
</cc:implementation>'
This component is called in this page
<l:logFile />
It loads the list of files but when I click on commandLink, it does not call the actionListener method but redirects me to the same page.
Every component that uses StreamedContent does not work in a composite component. For more detailed explained, please read http://jsfcorner.blogspot.be/2012/11/advanced-primefaces-graphic-image.html . Since <p:fileDownload/> is one of them you can't use it.

JSF rendered is not working after commandButton

I have a JSF application using Primefaces 3.5. I have a page where after click in a commandButton I call a method in Managed Bean which will fill a list that will be showed in fields tblPerfis and txtPerfis below.
<ui:composition template="...">
<ui:define name="content">
<h:form id="formPrincipal">
<br />
<p:fieldset legend="Pesquisa de Perfil" >
<p:panelGrid columns="2" >
<f:facet name="footer">
<p:commandButton id="btnPesquisar"
actionListener="#{perfilAcessoMB.pesquisar}" value="Pesquisar"
update="tblPerfis txtPerfis pnlPerfis"
styleClass="ui-icon-search" />
</f:facet>
</p:panelGrid>
</p:fieldset>
<br />
<h:outputText id="txtPerfis" value="Perfis: #{perfilAcessoMB.perfis}" ></h:outputText>
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}" var="perfil" emptyMessage="Nenhum perfil encontrado." >
<p:column headerText="Nome">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
</p:dataTable>
<p:outputPanel id="pnlPerfis">
<p:fieldset id="resultadoPesquisa" legend="Resultado da Pesquisa">TESTE</p:fieldset>
</p:outputPanel>
</h:form>
</ui:define>
</ui:composition>
The called method is the follow:
#ManagedBean
#ViewScoped
public class PerfilAcessoMB {
public void pesquisar(ActionEvent event) {
// Fill perfis List
}
}
At principle, it works as waited. My problem happens when I want add rendered attribute:
<h:outputText id="txtPerfis" value="Perfis: #{perfilAcessoMB.perfis}" rendered="#{not empty perfilAcessoMB.perfis}" ></h:outputText>
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}" rendered="#{not empty perfilAcessoMB.perfis}" var="perfil" emptyMessage="Nenhum perfil encontrado." >
<p:column headerText="Nome">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
</p:dataTable>
<p:outputPanel id="pnlPerfis" rendered="#{not empty perfilAcessoMB.perfis}">
<p:fieldset id="resultadoPesquisa" legend="Resultado da Pesquisa">TESTE</p:fieldset>
</p:outputPanel>
Even when there is results, these fields are not showed. Does someone have any idea what is happening here?
Thanks,
Rafael Afonso
EDIT
Following a workmate suggestion, I changed the code to put dataTable and outputText inside outputPanel. The commandButton will reference the outputPanel but the rendered attibute will be put in datatable and outputText.
<p:commandButton id="btnPesquisar"
actionListener="#{perfilAcessoMB.pesquisar}" value="Pesquisar"
update="pnlPerfis"
styleClass="ui-icon-search" />
<p:outputPanel id="pnlPerfis">
<h:outputText id="txtPerfis" value="Perfis: #{perfilAcessoMB.perfis}" rendered="#{not empty perfilAcessoMB.perfis}" ></h:outputText>
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}" rendered="#{not empty perfilAcessoMB.perfis}" var="perfil" emptyMessage="Nenhum perfil encontrado." >
<p:column headerText="Nome">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
</p:dataTable>
</p:outputPanel>
After this, the page worked as waited.
However, I still did not understand what happened. What is the explanation for this behaviour?
Your problem occurs because our table is not rendered it simply does not exist in your html code, that is not in this context to be found to update or another source.
When you shut a larger scope as the panel and force an update in this it forces the table to check the condition for rendering, if yes the code is written and can be seen without problems.

PrimeFaces PickList component, how to get all target values to one InputText component?

I created xhtml page with one inputText and one commandButton component. When I clicked on button is displaying overlayPanel with pickList and one commandButton under list. I want to get all target values and put it into inputText (this component must be only one). Can you help me how to do it?
Below is xhtml code that I wrote for now:
<h:panelGrid id="displayPlayers" columns="3">
<ui:repeat value="#{pickListBean.players.target}" var="player">
<p:inputText id="input2" value="#{player.name}" />
</ui:repeat>
<p:commandButton id="overPanBtn2" value="overPanBtn2" type="button" />
</h:panelGrid>
<p:overlayPanel id="chartPanel2" for="overPanBtn2" hideEffect="fade">
<p:pickList id="pickList4" value="#{pickListBean.players}" var="player" itemLabel="#{player}" itemValue="#{player}" converter="playerConverter">
<p:column style="width:75%;">
#{player.name}
</p:column>
<p:column style="width:75%;">
#{player.number}
</p:column>
</p:pickList>
<p:commandButton id="playerSubmit4" value="Ok" update="displayPlayers" style="margin-top:5px" />
</p:overlayPanel>
I will be grateful for help.
In your case it should be something like that, you only have to follow the showcase example:
XHTML
<p:pickList id="pickList4" value="#{pickListBean.players}" var="player" itemLabel="#{player}" itemValue="#{player}" converter="playerConverter">
<p:ajax event="transfer" listener="#{pickListBean.onTransfer}" update="msg" />
<p:column style="width:75%;">
#{player.name}
</p:column>
<p:column style="width:75%;">
#{player.number}
</p:column>
</p:pickList>
BACKING BEAN
String selectedPlayerNames;
//GETTER
public void onTransfer(TransferEvent event) {
selectedPlayerNames = "";
for (Player p : players.getTarget()){
selectedPlayerNames += p.getName() + " ";
}
}
Just call the event when transfer happens, and save the targeted values into the String. Then bind this String property to a p:inputText.

Resources