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
Related
I have a expansion datatable which is being populated by an Arraylist from the backend wich has an id as primary key. When row is expanded, that id specific rows has to be searched in an another table and all the rows has to be displayed. when i am trying to pass the id as parameter in the value attribute, it's giving class cast exception.
here's the XHTML Code
<h:form>
<p:dataTable var="data"
value="#{trackerList.trackerList}">
<f:facet name="header">Summary</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="ID">
<h:outputText value="#{data.id}" />
</p:column>
<p:column headerText="Status">
<h:outputText value="#{data.status}" />
</p:column>
<p:column headerText="Created Time">
<h:outputText value="#{data.createdTime}" />
</p:column>
<p:column headerText="Created By">
<h:outputText value="#{data.createdby}" />
</p:column>
<p:column headerText="Updated By">
<h:outputText value="#{data.updatedby}" />
</p:column>
<p:rowExpansion>
<p:dataTable var="metadata" value="#{statusList.getScenarioStatusList(data.id)}">
<p:column headerText="Requirements">
<h:outputText value="#{metadata.requirements}" />
</p:column>
<p:column headerText="Exam Name">
<h:outputText value="#{metadata.examName}" />
</p:column>
<p:column headerText="Status">
<h:outputText value="#{metadata.status}" />
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
</h:form>
Please Help.
i think you need to define below line inside the p:datatable tag with passing id as parameter and instead of #{statusList.getScenarioStatusList(data.id)} in sub datatable you just do value= "#{yourBean.scenarioStatusList}". populate scenarioStatusList in loadLists(data.id) method.
<p:ajax event="rowToggle" listener="#{yourBean.loadLists(data.id)}" />
I have the following Primefaces 3.5 page where I defined two commandLink. My problem is that action of lockout is not fired (checked with breakpoint) although lockoutTest with the same setting works. oncomplete works on both commandLink No exception is thrown.
<p:dataTable id="calendar" value="#{calendarView.calendarData.entrySet().toArray()}" var="row">
<f:facet name="header">
<p:panelGrid>
<p:row>
<p:column>
<p:commandLink id="lockoutTest"
value="test lockout"
update=":mainForm:lockoutEditorDialog"
process="#this"
action="#{calendarView.editLockout(15,15)}"
oncomplete="lockoutDialogWidget.show()">
<f:attribute name="title" value="valami" escape="true" />
</p:commandLink>
</p:column>
</p:row>
</p:panelGrid>
</f:facet>
<p:column style="width: 50px; text-align: right">
<f:facet name="header">
<h:outputText value="#{msgs.calendar_room}" />
</f:facet>
<h:outputText value="#{row.key.roomNumber}" />
</p:column>
<p:columns value="#{calendarView.columns}" var="column" style="text-align: center; #{not empty row.value[column].color ? 'background-color:#'.concat(row.value[column].color):''}">
<f:facet name="header">
<h:outputText value="#{column}" />
</f:facet>
<p:commandLink id="lockout"
value="#{row.value[column].text}"
update=":mainForm:lockoutEditorDialog"
process="#this"
action="#{calendarView.editLockout(row.key.roomNumber,column)}"
oncomplete="lockoutDialogWidget.show()"
rendered="#{row.value[column].text == 'K'}">
<f:attribute name="title" value="#{row.value[column].label}" escape="true" />
</p:commandLink>
</p:columns>
</p:dataTable>
UPDATE:
I've changed p:columns to a simple p:column for testing and it works:
<p:column id="testcolumn">
<p:commandLink id="lockouttest"
value="T"
update=":mainForm:lockoutEditorDialog"
process="#this"
action="#{calendarView.editLockout(15,15)}"
oncomplete="lockoutDialogWidget.show()"
>
</p:commandLink>
</p:column>
Use actionListener instead of action when you want to call a method in your backing bean.
Also, make sure your p:commandLink is placed within a h:form (I assume you've ommited it here since it should be a parent of your p:datatable)
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">
I need explanation for the below value binding in the outputText inside p:dialog .I dont clear with that and is there any other way.
In my sample :
I have tried ,if i select the single or many check box the value get binded but when I click root check box which used for selecting all the check boxes, its getting selected but the values not get stored in the back end.
<p:dataTable id="checkboxDT"
var="car"
value="#{dtSelectionView.cars6}"
selection="#{dtSelectionView.selectedCars}"
rowKey="#{car.id}"
style="margin-bottom:0">
<f:facet name="header">
Checkbox
</f:facet>
<p:column selectionMode="multiple"
style="width:16px;text-align:center"/>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<f:facet name="footer">
<p:commandButton process="checkboxDT"
update=":form:multiCarDetail"
icon="ui-icon-search"
value="View"
oncomplete="PF('multiCarDialog').show()" />
</f:facet>
</p:dataTable>
<p:dialog header="Selected Cars"
widgetVar="multiCarDialog"
modal="true"
showEffect="fade"
hideEffect="fade"
resizable="false"
width="200">
<p:outputPanel id="multiCarDetail" style="text-align:center;">
<ui:repeat value="#{dtSelectionView.selectedCars}"
var="car">
<h:outputText value="#{car.id} - #{car.brand}"
style="display:block"/>
</ui:repeat>
</p:outputPanel>
</p:dialog>
You should update checkboxDT because update is used to determines id’s of components to be updated (refreshed with updated values from server). If you do not update checkboxDT, the selectedCars do not update too.
<p:commandButton process="checkboxDT"
update="checkboxDT,:form:multiCarDetail"
icon="ui-icon-search"
value="View"
oncomplete="PF('multiCarDialog').show()" />
I'm currently working with primeface's p:rowExpansion and noticed that it's not working inside a p:outputPanel. Here's a sample code:
<p:commandButton action="#{xxxSearchBean.search()}" value="Search" update="messages resultPanel" styleClass="button"></p:commandButton>
<p:outputPanel id="resultPanel">
<p:panel rendered="#{xxxSearchBean.hasResults()}">
<ui:include src="xxxSearchView.xhtml">
<ui:param name="searchBean" value="#{xxxSearchBean}" />
</ui:include>
</p:panel>
</p:outputPanel>
The included view:
<p:accordionPanel activeIndex="0">
<p:tab title="Criminal Results">
<p:dataTable var="c" value="#{searchBean.results}">
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{c.lastname}" />
</p:column>
<p:column headerText="First Name">
<h:outputText value="#{c.firstname}" />
</p:column>
<p:rowExpansion>
<p:panelGrid columns="4"
columnClasses="form-field-label,value,form-field-label,value">
<h:outputText value="Label" />
<h:outputText value="Value" />
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
</p:tab>
</p:accordionPanel>
The above code successfully show the result grid when there are results, but when I click the rowExpansion it doesn't work.
When I moved out the panel and remove the rendered property, the row expansion worked. But I don't want to show the grid on page load :-(
Any idea?
I don't know if <p:rowExpansion> really doesn't work with <p:outputPanel>. But since you don't need any special features of <p:outputPanel>, you can just use <h:panelGroup> instead. :)
I was able to solved the problem by changing the backing bean annotation from #Model to #Conversation scope, then start the conversation the moment the view is render.