Access and refresh dataTable after getting data - jsf

I have got some problems with my JSF page, and (probably) with backing bean. I have got own template and I fill the content area with some pages. I have got search page with commandbutton and I would like to get data from database (JPA) and than fill the datatable.
Look at my searchpeople.xhtml:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="content">
<h:form id="sampleform">
<p:accordionPanel activeIndex="-1" id="accordingpanle">
<p:tab title="User options" >
<p:growl id="growl" showDetail="true" showSummary="true"/>
<p:commandButton id="searchbutton" action="#{mb_person.search}" value="Szukaj" update="personsearchresulttable" />
</p:tab>
</p:accordionPanel>
<p:dataTable id="personsearchresulttable" var="person" value="#{mb_person.people}" widgetVar="personTable" style="margin-top: 10px" >
<p:column headerText="Id" style="width:10%">
<h:outputText value="#{person.id}" />
</p:column>
<p:column headerText="Name" style="width:20%">
<h:outputText value="#{person.name}" />
</p:column>
<p:column headerText="Surname" style="width:20%">
<h:outputText value="#{person.surname}" />
</p:column>
<p:column headerText="Company">
<h:outputText value="#{person.companyName}" />
</p:column>
<p:column style="width:4%" headerText="Open">
<h:link outcome="persondetails" value="Open">
<!--<f:param name="personid" value="#{person.id}"/>-->
<f:param name="personid" value="10076"/>
</h:link>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
And my backingbean with EJB injection.
#ManagedBean(name="mb_person")
public class MB_Person implements Serializable{
#EJB
private PersonFacade personFacade;
private List<PersonAndCompany> people = new ArrayList<PersonAndCompany>();
public MB_Person() {
}
public List<PersonAndCompany> getPeople() {
return people;
}
public void setPeople(List<PersonAndCompany> people) {
this.people = people;
}
public void search() {
int[] range = {0,5};
setPeople(personFacade.findPersonWithMoreThanXProjects(20));
setPeople(personFacade.findPersonAndCompanyName(range));
for(PersonAndCompany p:people){
System.out.println(p.getName());
}
}
public String goToPersonDatailPage(int id){
return "persondetails.jsf?personid="+id;
}
}
I tried small test and printout all data in method search and I received good results.
Someone can help me how to update dataTable using ajax? In this form I have got an exception
Cannot find component with identifier "personsearchresulttable" referenced from "sampleform:accordingpanle:searchbutton".

Relative client IDs are searched relative to parent NamingContainer component. The <p:accordionPanel> is by itself a NamingContainer. So the relative client ID personsearchresulttable would be searched inside the context of the <p:accordionPanel>. However, it's actually outside the panel, inside the <h:form>.
You need to change the relative client ID to be an absolute client ID.
update=":sampleform:personsearchresulttable"
See also:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"

Related

Processing a data table from outside the form

I have a button outside the datatable form which function is to delete the selected row, but the problem is that it returns an empty value of that row in the backing bean, the update of the growl message is done correctly and the action is called too.
However when putting the button inside the form it works fine, but I need it to be in the toolbar which is outside the form.
This is my xhtml code:
<ui:define name="content">
<div class="row">
<p:toolbar id="tb">
<f:facet name="left">
<p:inputText style="margin-right:10px" placeholder="Rechercher..." />
<p:commandButton icon="fa fa-search" />
</f:facet>
<f:facet name="right">
<p:commandButton onclick="PF('analyseForm').show();" icon="fa fa-plus" />
<p:commandButton icon="fa fa-file-pdf-o" />
<p:commandButton process="#this,:form:anaDT" update=":form" action="#{personel.removeSelectedAnalyse}" icon="fa fa-trash-o" />
<!-- this button does the update and runs the action but returns a null value of the selected row-->
</f:facet>
</p:toolbar>
</div>
<div class="row">
<h:form id="form">
<p:growl id="msgs" />
<p:dataTable style="font-size:12px;" id="anaDT" scrollable="true" scrollWidth="100%" var="ana" value="#{personel.analyses}" paginator="true" selectionMode="single" selection="#{personel.selectedAnalyse}" paginatorPosition="bottom" rowKey="#{ana.idAnalyse}"
rows="10">
<!-- columns here -->
<f:facet name="footer">
<!-- this button works fine -->
<p:commandButton class="btn btn-default" process="form:anaDT" update="form" ajax="true" icon="fa fa-trash-o" action="#{personel.removeSelectedAnalyse}" />
</f:facet>
</p:dataTable>
</h:form>
</div>
<p:sticky target=":tb" margin="50" />
</ui:define>
</ui:composition>
Command button outside of a form can not be used to submit a form. If you want to achieve the functionality you desire, one way is to
Have a p:remoteCommand inside the form and bind it to the backing bean method personel.removeSelectedAnalyse and have update="#form"
Invoke the remoteCommand from the command button from the tool bar using onclick attribute and the remoteCommand submits the form. Now the backing bean will have the submitted values from the form so you can do the necessary processing and the form will be updated after the Ajax request completes.
Remote Command showcase: https://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtml
I've changed the rowKey to the entity type, assigning an unique id to the form. There is no need to process the form at the p:commandButton click. I place this button into a <h:form>. Command components always must be there. The entity selection done at row click. When you click on the button it uses the preset entity to remove from the List. Just the rerendering of the <p:dataTable> is needed. And I move the controller into the javax.faces.view.ViewScope. PrimeFaces component use ajax by default so the controllers must be at least as wide scope as view.
The facelet:
?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<div class="row" >
<h:form id="toolbarForm">
<p:toolbar id="tb">
<f:facet name="left">
<p:commandButton value="Delete selected User" process="#this" update="myForm" actionListener="#{myBean.deleteUser}"/>
</f:facet>
</p:toolbar>
</h:form>
</div>
<h:form id="myForm">
<p:dataTable id="usersTable" value="#{myBean.users}" var="user" selectionMode="single" selection="#{myBean.selectedUser}" rowKey="#{user}">
<p:column>
<f:facet name="header">ID</f:facet>
#{user.id}
</p:column>
<p:column>
<f:facet name="header">First name</f:facet>
#{user.firstName}
</p:column>
<p:column>
<f:facet name="header">Last name</f:facet>
#{user.lastName}
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
The controller:
package x;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import lombok.Data;
#Data
#Named( value = "myBean" )
#ViewScoped
public class MyBean implements Serializable
{
private List<User> users;
private User selectedUser;
public MyBean()
{
users = new ArrayList<>();
users.add( new User( 1, "First1", "Last1" ) );
users.add( new User( 2, "First2", "Last2" ) );
users.add( new User( 3, "First3", "Last3" ) );
users.add( new User( 4, "First4", "Last4" ) );
users.add( new User( 5, "First5", "Last5" ) );
}
#PostConstruct
public void init()
{
System.out.println( "MyBean.init() called" );
}
public void deleteUser()
{
if ( selectedUser == null )
System.out.println( "Selected User is null" );
else
System.out.println( "The ID of the User to remove: " + Integer.toString( selectedUser.getId() ) );
boolean bn = users.remove( selectedUser );
}
}
The User class:
package x;
import lombok.Data;
#Data
public class User
{
private int id;
private String firstName;
private String lastName;
public User( int id_, String firstName_, String lastName_ )
{
id = id_;
firstName = firstName_;
lastName = lastName_;
}
}
The source contains lombok annotations to avoid boilerplate coding (getter/setter methods)

Session scoped selectOneMenu value changes back to default after refreshing page [duplicate]

This question already has answers here:
Validation Error: Value is not valid
(3 answers)
Closed 7 years ago.
I have a jsf form in my application which should display several input fields for creating / editing employees. There exists several departments which I want to display with a <h:selectOneMenu>. My other components are basically primefaces components.
If I select an existing employee from my datatable, the department is set correctly (in frontend and bean). I checked the converter and it's getAsString() method in debugging mode. Both seem to work fine.
But when I refresh the page with [F5] it changes the value in the <h:selectOneMenu> back to it's previous one but the bean's value is still fine. It seems that the binding between my session bean and the jsf component isn't working properly.
In addition, there's another problem when I want to save any employee. The validation shows me that the selectOneMenu value is invalid. This error occurs after the getAsObject() method successfully returns my department pojo. I didn't define any validators on this specific component but I use several input components who must not be empty. This error might occur because there's a problem with setting the value as I stated above.
DepartmentConverter.java
#ManagedBean(name="departmentConverter")
public class DepartmentConverter implements Converter {
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
DepartmentDAOImpl deptUtils = new DepartmentDAOImpl();
try {
int code = Integer.parseInt(value);
return deptUtils.getDepartmentById(code);
} catch (NumberFormatException nfe) {
System.out.println("Couldn't transform department code from string to int");
nfe.printStackTrace();
}
return null;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return ((Department) value).getCode() + "";
}
}
SampleJSFBean.java
#ManagedBean(name = "sampleBean")
#SessionScoped
public class SampleJSFBean {
private Task employee;
private List<Task> employees;
private List<Department> departments;
private Department department;
public String showEditEmployeePanel() {
// shows panel
}
public String updateEmployee() {
// saves employee
}
// getter and setter
}
registration.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" template="/templates/BasicTemplate.xhtml">
<ui:define name="content">
<h:form id="formResult">
<p:panel>
<p:dataTable id="employee" var="task" value="#{sampleBean.employees}">
<p:column headerText="Code">
<h:outputText value="#{task.employee.code}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{task.employee.lastname}" />
</p:column>
<p:column headerText="Department">
<h:outputText value="#{task.employee.department.name}" />
</p:column>
<p:column headerText="edit">
<p:commandButton id="btnMut" icon="ui-icon-pencil" title="edit employee" disabled="#{task.jobActive == true}" action="#{sampleBean.showEditEmployeePanel}"
update=":formEmployee" resetValues="true">
<f:setPropertyActionListener value="#{task}" target="#{sampleBean.task}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
<h:form id="formEmployee">
<p:growl autoUpdate="false" />
<p:panel id="panelEmployee">
<h:outputText value="Lastname" styleClass="labelForm" />
<p:inputText id="inputLastname" value="#{sampleBean.task.employee.lastname}" required="true" requiredMessage="Please enter lastname." />
<br />
<h:outputText value="Department" styleClass="labelForm" />
<h:selectOneMenu value="#{sampleBean.department}" converter="#{departmentConverter}">
<f:selectItems value="#{sampleBean.departments}" var="dept" itemLabel="#{dept.code} - #{dept.name}" />
</h:selectOneMenu>
<br />
<p:commandButton value="save" action="#{sampleBean.updateEmployee}" icon="ui-icon-disk" update=":formResult :formEmployee" />
</p:panel>
</h:form>
</ui:define>
Have you tried with primefaces component instead <h:selectOneMenu> use <p:selectOneMenu>.
I'm not sure it helps, but I always use primeFaces's selectOneMenu and always works.

Model is updated but changes get lost

In the form below a person can be entered along with cars. The user can e.g. remove cars by clicking the "minus" commandButton an a row of the dataTable. However,
when the "minus" commandButton is immediate=false then the removal of cars does not work since validation kicks in (lastname of person is required) which is working as expected.
when it is immediate=true, then the save does not work properly. Example: three cars are in the list and "Ford" (being second in the list) is removed. The removal seems to work fine and the browser correctly reflects the change. When saving is triggered via the savePerson - method, however, it shows that the last car in the list (which was Toyota) was removed and not Ford. What can I do to have the changes being reflected when saving the person?
Log-output from bean below:
removing car Car{brand='Ford'}
remaining car Car{brand='Porsche'}
remaining car Car{brand='Toyota'}
saving person
saving car Car{brand='Porsche'}
saving car Car{brand='Ford'}
JSF
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/META-INF/templates/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="formChanges">
<p:accordionPanel id="accPanel">
<p:tab title="Cars">
<p:panelGrid columns="2">
<f:facet name="header">Person</f:facet>
<p:outputLabel value="Last" for="last"/>
<p:inputText id="last" value="#{table.person.last}" required="true"/>
<p:outputLabel value="First" for="first"/>
<p:inputText id="first" value="#{table.person.first}"/>
</p:panelGrid>
<p:dataTable var="car" value="#{table.person.cars}">
<p:column>
<f:facet name="header">Brand</f:facet>
<p:inputText value="#{car.brand}"/>
</p:column>
<p:column>
<f:facet name="header">Options</f:facet>
<p:commandButton value="#{msgs.minus}"
action="#{table.removeCar(car)}"
immediate="true"
update="formChanges:accPanel"/>
</p:column>
</p:dataTable>
<p:commandButton value="#{msgs.plus}" action="#{table.addCar}"
immediate="true" update="formChanges:accPanel"/>
<p:spacer height="10"/>
<p:commandButton id="save" value="#{msgs.save}" icon="ui-icon-check"
action="#{table.savePerson}" ajax="false"/>
</p:tab>
</p:accordionPanel>
</h:form>
</ui:define>
</ui:composition>
Bean
import com.google.common.collect.Lists;
import de.dgr.question.Car;
import de.dgr.question.Person;
import org.slf4j.Logger;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import java.io.Serializable;
import java.util.List;
#ManagedBean(name = "table")
#ViewScoped
public class TableController implements Serializable {
#Inject
private Logger log;
private Person person;
#PostConstruct
public void init() {
List<Car> cars = Lists.newArrayList(new Car("Porsche"), new Car("Ford"), new Car("Toyota"));
person = new Person();
person.setCars(cars);
}
public String savePerson() {
log.info("-> saving person");
for (Car car : person.getCars()) {
log.info("saving car {}", car);
}
return null;
}
public String removeCar(final Car carToDelete) {
log.info("removing car {}", carToDelete);
person.getCars().remove(carToDelete);
for (Car car : person.getCars()) {
log.info("remaining car {}", car);
}
return null;
}
public String addCar() {
log.info("adding empty car");
person.getCars().add(new Car());
return null;
}
public Person getPerson() {
return person;
}
public void setPerson(final Person person) {
this.person = person;
}
}
Thanks to the links BalusC provided me with I implemented the below solution.
immediate = true is wrong in any case since when entering new cars and then deleting one of them the model (components) needs to be updated with the form data. Otherwise, the data already filled in the form would get lost when adding/removing a car (plus/minus commandButton).
That means that all input components of the form need to be processed, including the required component "last" in order to update the model with that data. To avoid validation of the required component "last" when a car is added/removed and to validate only when the save button is klicked the solution of [How to let validation depend on the pressed button? is used.
That last point, however, seems to work only when ajax="false" is not specified. If so, then param[save.clientId] seems always to be empty. Only when ajax="true" (which is the default) will the parameter have a value.
Change jsf page:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/META-INF/templates/template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:form id="formChanges" prependId="false">
<p:accordionPanel id="accPanel" prependId="false">
<p:tab title="Cars">
<h:panelGroup id="panelNewData">
<p:panelGrid columns="2">
<f:facet name="header">Person</f:facet>
<p:outputLabel value="Last" for="last"/>
<p:inputText id="last" value="#{table.person.last}"
required="#{not empty param[save.clientId]}" />
<p:outputLabel value="First" for="first"/>
<p:inputText id="first" value="#{table.person.first}"/>
</p:panelGrid>
<p:dataTable var="car" value="#{table.person.cars}">
<p:column>
<f:facet name="header">Brand</f:facet>
<p:inputText value="#{car.brand}"/>
</p:column>
<p:column>
<f:facet name="header">Options</f:facet>
<p:commandButton value="#{msgs.minus}"
action="#{table.removeCar(car)}"
process="panelNewData"
update="panelNewData"/>
</p:column>
</p:dataTable>
<p:commandButton value="#{msgs.plus}" action="#{table.addCar}"
process="panelNewData" update="accPanel"/>
<p:spacer height="10"/>
<p:commandButton id="save" binding="#{save}" value="#{msgs.save}"
icon="ui-icon-check" action="#{table.savePerson}"
update="accPanel"/>
</h:panelGroup>
</p:tab>
</p:accordionPanel>
</h:form>
</ui:define>
</ui:composition>

Primefaces' p:dialog with form doesn't behave as expected

I generated a Primefaces based CRUD website starting from JPA Entities with netbeans and after adjusting the Update dialog to fit my needs I am experiencing several problems. The domain Model is quite easy: I have an entity Invitation which contains several Guests.
#Entity
public class Invitation implements Serializable {
...
#OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "invitationId")
private List<Guest> guestList;
public List<Guest> getGuestList() {
return guestList;
}
...
}
I have an overview page (list.xhtml) where all the invitations are listed and the user can pick one to edit it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui" template="/template/layout.xhtml">
<ui:define name="content">
<h:form id="InvitationListForm">
<p:dataTable var="invitation" id="datalist"
value="#{invitationController.invitations}" resizableColumns="true"
selectionMode="single" selection="#{invitationController.selected}"
rowKey="#{invitation.invitationId}" paginator="true" rows="10"
rowsPerPageTemplate="10,30,50,100" draggableColumns="true">
<p:ajax event="rowSelect" update="createButton editButton " />
<p:ajax event="rowUnselect" update="createButton editButton " />
<p:column headerText="Name">
<h:outputText id="invitationName" value="#{invitation.name}" />
</p:column>
...
<f:facet name="footer">
<p:commandButton id="createButton" icon="ui-icon-plus"
value="#{msgs.lbl_add_new}" update=":InvitationCreateForm"
oncomplete="PF('InvitationCreateDialog').show()" />
<p:commandButton id="editButton" icon="ui-icon-pencil"
value="#{msgs.lbl_edit}" update=":InvitationEditForm"
oncomplete="PF('InvitationEditDialog').show()"
disabled="#{empty invitationController.selected}" />
</f:facet>
</p:dataTable>
</h:form>
<ui:include src="create.xhtml" />
<ui:include src="edit.xhtml" />
</ui:define>
</ui:composition>
Note that layout.xhtml doesn't contain any form (no nested forms).
The dialog edit.xhtml is divided into 2 parts: one where the user can enter the invitation "head" information and another one with a datatable where she can edit / add / delete guests.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<ui:composition>
<h:form id="InvitationEditForm">
<p:dialog id="InvitationEditDlg" widgetVar="InvitationEditDialog"
modal="true" resizable="false" appendTo="#(body)"
header="#{msgs.lbl_add_new}">
<h:panelGroup id="display">
<p:panelGrid columns="2"
rendered="#{invitationController.selected != null}">
<p:outputLabel value="#{msgs.lbl_name}" for="name" />
<p:inputText id="name"
value="#{invitationController.selected.name}" required="true"/>
...
</p:panelGrid>
<p:dataTable var="aGuest" id="guestTable" style="width: 1200px;"
value="#{invitationController.selected.guestList}"
resizableColumns="false" rowIndexVar="idx" draggableColumns="true">
<p:column width="80" headerText="#{msgs.lbl_name}">
<p:inputText id="guestName" value="#{aGuest.name}" />
</p:column>
...
<p:column width="20">
<p:commandButton
actionListener="#{invitationController.addNewGuest}"
id="addGuestButton" update="guestTable" icon="ui-icon-plusthick"
title="+" />
<p:commandButton
actionListener="#{invitationController.deleteGuest(idx)}"
id="deleteGuestButton" update="guestTable"
icon="ui-icon-minusthick" title="-" immediate="true"
rendered="#{invitationController.selected.guestList.size()>1}" />
</p:column>
</p:dataTable>
<p:commandButton actionListener="#{invitationController.save}"
value="#{msgs.lbl_save}"
update="display,:InvitationListForm:datalist,:growl"
oncomplete="handleSubmit(args,'InvitationEditDialog');" />
<p:commandButton value="#{msgs.lbl_cancel}" immediate="true"
actionListener="#{invitationController.cancel}"
onclick="PF('InvitationEditDialog').hide()" />
</h:panelGroup>
</p:dialog>
</h:form>
</ui:composition>
</body>
</html>
And the Controller
#SessionScoped
#Named
public class InvitationController implements Serializable {
private Invitation selected; //with getter and setter
}
Now, I think my problem should be in the combination of p:dialog and h:form.
The original generated version of edit.xhtml had the form InvitationEditForm nested within the dialog and not the contrary as I posted above. The problem with that was after clicking editButton the dialog was loaded, but the dataTable was always filled with guests of the first Invitation I selected in my session (more strangely, suppose the first invitation in the session had just a guest A: after selecting an Invitation with 2 guests B and C I got A and B displayed). As the controller was returning the right guestList(), I supposed there was a problem with update and inverting form and display solved this problem..
Unfortunately this didn't solve all the problems, as now the actionListener for addGuestButton and deleteGuestButton doesn't get invoked anymore..
I am really confused: can you please help me to fix my code? Thanks in advance!

Page jsf into dialog not working

I try to folow exemple from primefaces site .using Dialog Framework - Basic
<p:commandButton value="Options" icon="ui-icon-extlink" action="#{dialogBean.viewCarsCustomized}" />
Bean DialogBean
public class DialogBean {
public String viewCarsCustomized() {
return "dialog:viewCars?modal=true";
}
}
viewCars.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Manufacturer">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>
</h:body>
</html>
this is My exemple on My Bean .
I Try like this
public String viewComposant(){
return "dialog:AjoutC?modal=true";
}
it is not working,I try to do like this .but every time error
Impossible de trouver un cas de navigation correspondant depuis l'ID
de vue '/pagess/Parsing/ReacgModule.xhtml' pour l'action
'#{parserXls.viewComposant()}' avec le résultat
'dialog:/pagess/pagesComposant/AjoutC.jsf?modal=true'.
public String viewComposant(){
return "dialog:/pagess/pagesComposant/AjoutC.jsf?modal=true";
}
But When I do like this the page returend but not as I like
public String viewComposant(){
return "/pagess/pagesComposant/AjoutC.jsf";
}
3.5 version of primefaces
The dialog: navigation outcome prefix from "Dialog Framework" is introduced in PrimeFaces 4.0 and don't work in older versions.
So, you've 2 options:
Upgrade to PrimeFaces 4.0 (note: it's currently still in beta)
Use the "old" approach of dialogWidgetVar.show() in JavaScript or visible="#{someCondition} in JSF. See also the <p:dialog> examples in PrimeFaces showcase.
Update: as per the comment, here's how you could use it with widgetVar approach in JS:
<p:button value="Open dialog" onclick="w_dialog.show(); return false;" />
<p:dialog widgetVar="w_dialog">
<p>Dialog's content.</p>
<p:dialog>
And here's how you could use the visible approach in JSF:
<h:form>
<p:commandButton value="Open dialog" action="#{bean.showDialog}" update=":dialog" />
</h:form>
<p:dialog id="dialog" visible="#{bean.showDialog}">
<p>Dialog's content.</p>
<p:dialog>
with
private boolean showDialog;
public void showDialog() {
showDialog = true;
}
public boolean isShowDialog() {
return showDialog;
}
You can if necessary move <p:dialog> into an include file which you include by <ui:include>.

Resources