I am trying to make a h:panelgrid visible and invisible by clicking on a button that's why i made this code:
<p:menu styleClass="ui-menubar" style="width:auto">
<p:menuitem value="khraaaaaaaaa" actionListener="#{accounts.buttonUser()}"></p:menuitem>
</p:menu>
<h:panelGrid id="naalobouk" binding="#{accounts.pg1}">
<h1>Activer/désactiver un compte étudiant</h1>
<hr/>
<h:form id="etudiants">
<p:dataTable emptyMessage="Pas d'étudiant!"
paginator="true"
paginatorPosition="bottom"
rows="4"
value="#{accounts.etudiants}"
var="stu">
<f:facet name="header">
<h:outputText value="Les comptes étudiant" />
</f:facet>
<p:column headerText="#">
<h:outputText value="#{stu.id}" />
</p:column>
<p:column headerText="nom">
<h:outputText value="#{stu.nom}" />
</p:column>
<p:column headerText="prenom">
<h:outputText value="#{stu.prenom}" />
</p:column>
<p:column headerText="email">
<h:outputText value="#{stu.email}" />
</p:column>
<p:column headerText="password">
<h:outputText value="#{stu.password}" />
</p:column>
<p:column headerText="action">
<p:commandButton rendered="#{accounts.butshow}" value="#{stu.actif?'desactiver':'activer'}" action="#{accounts.doToggleStudentState(stu)}" update=":etudiants"/>
</p:column>
</p:dataTable>
</h:form>
</h:panelGrid>
and here is my bean code
private HtmlPanelGrid pg1 = new HtmlPanelGrid();//getter and setter
public void buttonUser(){
if(pg1.isRendered()==true){
pg1.setRendered(false);;
}
if(pg1.isRendered()==false){
pg1.setRendered(true);
}
}
When i click on the button nothing happens. What's the problem here ?
I'm assuming you want the method to negate the rendered property. In that case the method is flawed, as mentioned in the comments. The simplest code would be
public void buttonUser() {
pg1.setRendered(!pg1.isRendered());
}
The main problem is that the p:menuItem by default uses ajax, which by default does'nt update anything on the page. So either update something, or don't use ajax;
<p:menuitem value="khraaaaaaaaa" actionListener="#{accounts.buttonUser()}" ajax="false">
With ajax you need to wrap the panelGrid in a component that will always be rendered, since you can't update a component that has not been rendered in the first place. Wrap the panelGrid in a panelGroup:
<h:panelGroup id="container">
and update that:
<p:menuitem value="khraaaaaaaaa" actionListener="#{accounts.buttonUser()}" update=":container">
Related
I have a problem with Primefaces data-table and context menu.
Context menu contains only one option, which deletes row with records.
How I understood, I need to pass to managed bean var parameter (order)? which contains row data in map structure.
<p:dataTable id="#{id}" var="order" rowIndexVar="rowId" value="#{ordersProvider}" emptyMessage="No more rows" rowKey="#{id}" selectionMode="single">
<p:column headerText="№" filterBy="#{order.id}" filterMatchMode="contains">
<div style="text-align: center;">
<h:outputText value="#{order.id}"/>
</div>
</p:column>
<p:column headerText="№ on site" filterBy="#{order.noticeNumber}" filterMatchMode="contains">
<div style="text-align: center;">
<h:outputText value="#{order.noticeNumber}" />
<f:param name="searchString" value="#{order.noticeNumber}" />
</div>
</p:column>
<p:column headerText="Company" filterBy="#{order.customerName}" filterMatchMode="contains">
<div style="text-align: center;">
<h:outputText value="#{order.customerName}"/>
</div>
</p:column>
<p:column id="col">
<f:facet name="header">
<p:contextMenu for="#{id}">
<p:menuitem value="Delete" update="#{id}" icon="ui-icon-close" action="#{clientOrdersBean.cancel(order)}"/>
</p:contextMenu>
</f:facet>
</p:column>
</p:dataTable>
Here is my bean method, for deleting data.
public void cancel(OrderBG order){
order.setStatus(OrderStatus.Canceled);
Environment.getInstance().getServiceProvider().getOrderBgService().save(order);
}
The problem is, that value passes - null. I don't know how to get whole row from table.
Any suggestions? Thank you in advance.
Problem was successfully resolved by getters and setters.
In managed bean:
private OrderBG newOrder = new OrderBG();
public OrderBG getNewOrder() {
return newOrder;
}
public void setNewOrder(OrderBG newOrder) {
this.newOrder = newOrder;
}
public void cancel(){
getNewOrder().setStatus(OrderStatus.Canceled);
Environment.getInstance().getServiceProvider().getOrderBgService().save(getNewOrder());
}
In xhtml UI:
<p:contextMenu for="#{id}">
<p:menuitem value="Delete" update="#{id}" icon="ui-icon-close" actionListener="#{clientOrdersBean.cancel}"/>
</p:contextMenu>
<p:dataTable id="#{id}" var="order" value="#{ordersProvider}" emptyMessage="Заявки отсутствуют" rowKey="#{id}" selection="#{clientOrdersBean.newOrder}" selectionMode="single">
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
I have a PrimeFaces p:dataTable with one column of type p:cellEditor with an p:inputText field.
This inputText is supposed to be required but if I set required="true" and leave the input empty nothing happens / no message is shown. The form including the above is submitted anyway.
Here's my code, especially the <p:column headerText="Data Value"> part:
<h:form id="my-form">
<p:dataTable var="dataItem" rowIndexVar="rowIndex" value="#{backingBean.dataList}" draggableRows="true" editable="true" editMode="cell">
<p:ajax event="rowReorder" update="#form"/>
<p:column headerText="Order Position">
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Data Name">
<h:outputText value="#{dataItem.name}" />
</p:column>
<p:column headerText="Data Value">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{dataItem.value}" /></f:facet>
<f:facet name="input"><p:inputText required="true" requiredMessage="Please insert a value" id="valueInput" value="#{dataItem.value}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<div>
<h:commandLink action="#{backingBean.submit()}">Submit</h:commandLink>
</div>
<h:messages id="validateMsg" />
</h:form>
The submitting h:commandLink is not an ajax call. But in my opinion it shouldn't submit the form anyway as long as the required p:inputText fields are empty.
I also tried using h:inputText instead of p:inputText with the same result.
I tried to add a required h:inputText outside the p:dataTable which works as expected and prevents the form from being submitted as long as it is empty.
Any ideas about how I get a required p:inputText field in p:cellEdit ?
According to rion18's suggestion. I'm checking in my backing bean if all values are set. Only if all values are set the submit button is shown. Here's how I ended up doing this:
<h:form id="my-form">
<p:dataTable var="dataItem" rowIndexVar="rowIndex" value="#{backingBean.dataList}" draggableRows="true" editable="true" editMode="cell">
<p:ajax event="cellEdit" update=":#{p:component('submit-button-group')}" />
<p:column>
...
</p:column>
</p:dataTable>
<div>
<h:panelGroup id="submit-button-group">
<h:commandLink action="#{backingBean.submit()}" rendered="#{backingBean.isAllValuesSet()}">Submit</h:commandLink>
</h:panelGroup>
</div>
</h:form>
In my backing bean I have a simple function that iterates over the dataList:
public boolean isAllValuesSet(){
for(DataItem item:dataItems){
if(item.getValue()==null || item.getValue().isEmpty()){
return false;
}
}
return true;
}
I am providing a search function using JSF. I get the list and display it correctly in a datatable :
<p:dataTable id="props" var="prop" value="#{propController.propSearch}" editable="true" style="margin-bottom:20px">
<p:column headerText="Id" width="20">
<h:outputText value="#{prop.id}" />
</p:column>
<p:column headerText="Name" width="300">
<h:outputText value="#{prop.name}"/>
</p:column>
<p:column headerText="Description">
<h:outputText value="#{prop.shortDescription}" />
</p:column>
<p:column headerText="Price" width="120">
<h:outputText value="#{prop.price}" />
</p:column>
<p:column width="120">
<h:commandButton value="View Prop" immediate="true" action="#{propController.viewSingleProp(prop)}" />
</p:column>
<p:column width="120">
<h:commandButton value="Delete" immediate="true" onclick="return confirm('Are you sure you want to delete this prop?')" actionListener="#{propController.deleteProp(prop)}" />
</p:column>
</p:dataTable>
</h:form>
However the commandButton to view each individual item does not get called. Instead the search page just refreshes with no data.
Why is this happening?
(I hope your opening tag of <h:form> is just missing in your code posted in your question, not in your actual code!)
You need to remove the attribute immediate="true" from the h:commandButton.
See:
Immediate=true VS immediate=false in JSF Component
I'm using Primefaces Datatable-ContextMenu and Dialog to update a row (When after click to contextmenu it opens a dialog which contains will update object's fields in <p:inputext />).
I have tried dynamic true, initilazing object on constructor because when page is rendered selectedObject will be null in dialog and when I tried to use it gives null pointer exception so that i need other advices.
Here is ContextMenu:
<p:contextMenu for="functions" id="functionContextMenu">
<p:menuitem value="Guncelle" icon="ui-icon-" update="updateDialog" oncomplete="updateDialog.show()"/>
And my dialog is here:
<p:dialog header="Guncelle" widgetVar="updateDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="updateDialog" dynamic="true">
<h:panelGroup id="display">
<h:outputText value="#{functionControllerBean.selectedFunction.functionName}" />
<h:inputText id="firstName" value="{functionControllerBean.tempSelectedFunction1.functionName}" />
</h:panelGroup>
</p:dialog>
If I dont use <p:inputText /> its ok and show what i put <h:outputText /> but when i put p:inputext inside of dialog;it doesnt show output text value and shows <p:inputText /> empty even its not.
I had used beanname.objectname.field before inside of <p:inputText /> or <h:inputText /> but there was no problem but now it's not working.
And here is my ManagedBean :
#ManagedBean
#RequestScoped
public class FunctionControllerBean implements Serializable {
private EfaFunctions willAddFunction;
private EfaFunctions selectedFunction = new EfaFunctions();
Thanks in advance
UPDATE Here is page
<h:form id="form">
<p:contextMenu for="functions" id="functionContextMenu">
<p:menuitem value="Guncelle" icon="ui-icon-" update="updateDialog" oncomplete="updateDialog.show()"/>
<p:menuitem value="Sil" update="#form" icon="ui-icon-close" actionListener="#{functionControllerBean.deleteFunction}"/>
</p:contextMenu>
<p:dataTable resizableColumns="true" id="functions" var="function" value="#{functionControllerBean.functions}" rowKey="#{function.functionId}"
selection="#{functionControllerBean.selectedFunction}" selectionMode="single">
<p:column headerText="Id">
#{function.functionId}
</p:column>
<p:column headerText="Key ">
#{function.functionKey}
</p:column>
<p:column headerText="Isim" >
#{function.functionName}
</p:column>
<p:column headerText="Tip" >
#{function.functionType}
</p:column>
<p:column headerText="Url" >
#{function.uri}
</p:column>
<p:column headerText="Olusturulma Tarihi" >
#{function.creationDate}
</p:column>
<p:column headerText="Guncelleme Tarihi" >
#{function.lastUpdateDate}
</p:column>
<p:column headerText="Olusturan Kisi" >
#{function.createdBy}
</p:column>
<p:column headerText="Guncelleyen Kisi" >
#{function.createdBy}
</p:column>
</p:dataTable>
<p:dialog header="Islem Sonucu" widgetVar="actionResult" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="actionResult"
visible="#{functionControllerBean.actionResult!=null}">
<h:outputText value="#{functionControllerBean.actionResult}"/>
</p:dialog>
<p:dialog header="Guncelle" widgetVar="updateDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold" id="updateDialog" >
<h:panelGroup id="display">
<h:outputText value="#{functionControllerBean.selectedFunction.functionName}" />
<p:inputText value="#{functionControllerBean.selectedFunction.functionName}"/>
</h:panelGroup>
</p:dialog>
</h:form>