JSF CommandButton action not invoked (another example) - jsf

I took the example from https://stackoverflow.com/a/3180885/242042 just tweaked it for my needs.
Here's my bean:
#ManagedBean
#ViewScoped
public class ParticipantBean implements
Serializable {
private boolean edit;
private List<Participant> list;
private Participant participant = new Participant();
#Inject
private transient ParticipantDAO participantDAO;
public void add() {
System.out.println("Calling add");
participantDAO.save(participant);
init();
}
public void delete(final Participant participant) {
participant.getAudit().cancel();
participantDAO.save(participant);
init();
}
public void edit(final Participant participant) {
this.participant = participantDAO.get(participant.getId());
edit = true;
}
public void fire() {
System.out.println("fired");
}
public List<Participant> getList() {
return list;
}
public Participant getParticipant() {
return participant;
}
#PostConstruct
public void init() {
list = participantDAO.getAll();
participant = new Participant(); // Reset placeholder.
}
public boolean isInEdit() {
return edit;
}
public void saveParticipant() {
System.out.println("Calling save");
participantDAO.save(participant);
System.out.println("Done Calling save");
init();
edit = false;
}
}
And my JSF file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Really simple CRUD</title>
</h:head>
<h:body>
<h3>List items</h3>
<h:form rendered="#{not empty participantBean.list}">
<h:dataTable value="#{participantBean.list}" var="item">
<h:column><f:facet name="header">ID</f:facet>#{item.id}</h:column>
<h:column><f:facet name="header">Name</f:facet>#{item.name}</h:column>
<h:column><h:commandButton value="edit" action="#{participantBean.edit(item)}" /></h:column>
<h:column><h:commandButton value="delete" action="#{participantBean.delete(item)}" /></h:column>
<h:column><h:commandButton value="fire" action="#{participantBean.fire}" /></h:column>
</h:dataTable>
</h:form>
<h:panelGroup rendered="#{empty participantBean.list}">
<p>Table is empty! Please add new items.</p>
</h:panelGroup>
<h:panelGroup rendered="#{!participantBean.inEdit}">
<h3>Add item</h3>
<h:form>
<p>Name: <h:inputText value="#{participantBean.participant.name}" /></p>
<p><h:commandButton value="add" action="#{participantBean.add}" /></p>
<p><h:commandButton value="fire" action="#{participantBean.fire}" /></p>
</h:form>
</h:panelGroup>
<h:panelGroup rendered="#{participantBean.inEdit}">
<h3>Edit item #{participantBean.participant.id}</h3>
<h:form>
<p>Name: <h:inputText value="#{participantBean.participant.name}" /></p>
<p><h:commandButton value="save" action="#{participantBean.saveParticipant}" /></p>
<p><h:commandButton value="add" action="#{participantBean.add}" /></p>
<p><h:commandButton value="fire" action="#{participantBean.fire}" /></p>
</h:form>
</h:panelGroup>
</h:body>
</html>
So it is quite similar, but what I don't understand is why on the "edit" it does not want to invoke the actions. (i.e. I don't see anything on SystemOut.log)
I was looking at the answer https://stackoverflow.com/a/13327382/242042 to see if there was anything to merit it, but I found that the "System.out.println()" events do not even get fired. The control is there.
One thing I did notice was the commandButtons reload the screen while inEdit
I have eliminated "Prime Faces" as well and I am testing on WebSphere 9.0.0.3. The code is in https://github.com/trajano/jee/tree/no-prime-faces
I also have tried reordering the form such that the edit block is in the form like so but it still the actions do not fire.
<h:form rendered="#{not empty participantBean.list}">
<h:dataTable value="#{participantBean.list}" var="item">
<h:column><f:facet name="header">ID</f:facet>#{item.id}</h:column>
<h:column><f:facet name="header">Name</f:facet>#{item.name}</h:column>
<h:column><h:commandButton value="edit" action="#{participantBean.edit(item)}" /></h:column>
<h:column><h:commandButton value="delete" action="#{participantBean.delete(item)}" /></h:column>
</h:dataTable>
<h:panelGroup rendered="#{participantBean.inEdit}">
<h3>Edit item #{participantBean.participant.id}</h3>
<p>Name: <h:inputText value="#{participantBean.participant.name}" /></p>
<p><h:commandButton value="save" action="#{participantBean.saveParticipant}" /></p>
<p><h:commandButton value="add" action="#{participantBean.add}" /></p>
</h:panelGroup>
</h:form>
I also tried having edit() written this way to get the participant that was on the original list that way it will have the proper optimistic lock #Version
public void edit(final Participant participant) {
this.participant = participant;
edit = true;
}

In JSF 2.2 there are two annotations in different packages named #ViewScoped
javax.faces.bean.ViewScoped ← correct one
javax.faces.view.ViewScoped ← incorrect one introduced with JSF 2.2 (which was what I was using when I wrote the question)
To limit it to JSF 2.2 as per #Jasper de Vries 's comment. The annotations need to change to
#javax.inject.Named
#javax.faces.view.ViewScoped

Related

h:selectBooleanCheckBox action on select

I have a <h:selectBooleanCheckBox> as part part of my JSF which I want to run a bean method when it's state has changed from unchecked to checked.
I have the following controller bean
#Named
#ViewScoped
public class UserController {
#Inject
private UserService userService;
#Inject
private LocationService locationService;
private UserFilter userFilter;
private List<User> users;
private List<Location> locations;
#PostConstruct
public void init() {
users = userService.listAll();
locations = locationService.listAll();
userFilter = new UserFilter();
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public List<Location> getLocations() {
return locations;
}
public void setLocations(List<Location> locations) {
this.locations = locations;
}
public void listAllUsers() {
users = userService.listAll();
}
public void findUsers() {
// code that uses the UserFilter
// to decide which user filter find method to use
}
}
The UserFilter is a simple DTO
public class UserFilter {
private boolean allUsers = true;
private String username;
private String location;
//getters and setters
}
And my JSF has is like so
<?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:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Users</title>
</h:head>
<h:body>
<h1>Users</h1>
<h:form id="filterForm">
<h:selectBooleanCheckbox id="selectAll" value="#{userController.userFilter.allUsers}" title="allUsers">
<f:ajax render="filterGrid"/>
</h:selectBooleanCheckbox><h:outputText value ="All users"/>
<h:panelGrid id="filterGrid" columns="3">
<h:inputText id="userName" value="#{userController.userFilter.userName}" disabled="#{userController.userFilter.allUsers}"/>
<h:selectOneMenu id="selectLocation" value="#{userController.userFilter.location}" disabled="#{userController.userFilter.allUsers}">
<f:selectItems value="#{userController.locations}" var="location" itemValue="#{location.location}" itemLabel="#{location.location}"/>
</h:selectOneMenu>
<h:commandButton value="Filter" disabled="#{userController.userFilter.allUsers}" action="#{userController.findUsers()}"/>
</h:panelGrid>
</h:form>
<h:form rendered="#{not empty userController.users}">
<h:dataTable value="#{userController.users}" var="user">
<h:column>#{user.name}</h:column>
<h:column>#{user.location.location}</h:column>
<h:column><h:commandButton value="delete" action="#{userController.delete(user)}"/></h:column>
</h:dataTable>
</h:form>
<h:panelGroup rendered="#{empty userController.users}">
<p>Table is empty! Please add new items.</p>
</h:panelGroup>
<h3>Add user</h3>
<h:form id="user">
<p>Value: <h:inputText id="name" /></p>
<p>
<h:commandButton value="add" action="#{userController.add(param['user:name'])}"/>
</p>
</h:form>
</h:body>
</html>
As you can see by default it lists all users, then when the checkbox is unchecked you have the option to filter on username/location.
What I want is for the check box to run the userController.listAllUsers() method when it's state moves from unchecked to checked.
And a small additional question, how do I get the checkbox to appear in the same row as the panel grid items?
I have a habit of answering my own questions it seems! I needed an additional <f:ajax tag that rendered the user form and had the listener attribute set
So something like
<h:selectBooleanCheckbox id="selectAll" value="#{userController.userFilter.allUsers}" title="allUsers">
<f:ajax render="filterGrid"/>
<f:ajax render="usersForm" listener="#{userController.listAllUsers()}"/>
</h:selectBooleanCheckbox><h:outputText value ="All users"/>

primefaces dynamic nested datatable

With primefaces I made a multicheckbox with several divisions to choose. After clicking the submit Button the chosen divisions should be listed in a datatable with the associated items in a subtable. There could be 0 - n items which should be shown in the subtable.
division1 -> item1, item2
division2 -> item3, item4, item5
The first impression of the webpage looks fine. When I only choose one division and press submit the fitting items will be shown. But when I want to display other items they get overwritten. e.g. when I choose division2 it will display the items item1, item2 and item 5.
How can I make it so that the items will be loaded correctly every time?
I also changed the subtable to a nested datatable, but the behaviour was the same.
I've primefaces version 4.0
Below is my code:
division_list.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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>
<title>Gruppenverwaltung</title>
</h:head>
<h:body>
<f:view>
<h:form id="myForm">
<h2>
<h:outputText value="Division List" />
</h2>
<h:outputText value="Grid: " />
<p:selectOneRadio id="grid" value="#{divisionController.selectedDivisions}" layout="grid" columns="3"
converter="DivisionConverter">
<f:selectItems value="#{divisionController.divisions}" />
</p:selectOneRadio>
<p:commandButton value="Submit" update=":myForm" />
<p:dataTable id="dtDivisions" value="#{divisionController.selectedDivisions}" var="division">
<p:subTable id="stItems" var="item" value="#{division.items}">><f:facet name="header">
<h:outputText value="#{division.name}" />
</f:facet>
<p:column>
<h:inputText value="#{item.name}" />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-disk" action="#{divisionController.doUpdateItem(item)}" />
<p:commandButton icon="ui-icon-trash" oncomplete="confirm.show()">
<f:setPropertyActionListener target="#{divisionController.selectedItem}" value="#{item}" />
</p:commandButton>
</p:column>
</p:subTable>
</p:dataTable>
</h:form>
<p:confirmDialog message="Gewählter Eintrag löschen?" widgetVar="confirm"> --><h:form
id="formDialog">
<p:commandButton value="Yes" action="#{divisionController.doDeleteItem}"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" oncomplete="confirmation.hide()" />
<p:commandButton value="No" type="button" onclick="confirm.hide()" styleClass="ui-confirmdialog-no"
icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
</f:view>
</h:body>
</html>
DivisonController.java:
...
#ManagedBean
#ViewScoped
public class DivisionController implements Serializable {
...
private List<DivisionDto> divisions;
private List<DivisionDto> selectedDivisions;
...
#PostConstruct
public void init() throws MappingTOException {
....
if (divisions == null) {
divisions = club.getDivisions();
}
}
...
DivisionDto.java
...
public class DivisionDto {
....
private List<ItemDto> items;
private String name;
...
ItemDto.java
...
public class ItemDto {
...
private DivisionDto division;
private String name;
...
DivisionConverter.java
#FacesConverter(value = "DivisionConverter")
public class DivisionConverter implements Converter {
private static Map<String, DivisionDto> divisionCache = new HashMap<String, DivisionDto>();
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
DivisionDto val = divisionCache.get(value);
if (val == null) {
val = new DivisionDto();
val.setName(value);
}
return val;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value instanceof DivisionDto) {
DivisionDto division = (DivisionDto) value;
divisionCache.put(division.getName(), division);
return division.getName();
} else {
return "";
}
}
}
I would be really grateful for any help.
I solved the issue wie a datatable in a datatable and put a filter on the first datatable. Now it works as expected.

In JSF, how to update a page dynamically and partially with ajax and with out form validation?

I have a JSF 2 form like this:
<h:form>
<h:panelGrid columns="2">
<a4j:repeat value="#{dialog.departments}" var="depart">
<h:inputText value="#{depart.name}"/>
<h:selectOneRadio value="#{depart.hasSubdepartment}">
<f:ajax render="#form" execute="#form" immediate="true"/>
<f:selectItem itemValue="#{true}"/>
<f:selectItem itemValue="#{false}"/>
</h:selectOneRadio>
<a4j:repeat value="#{depart.subdepartments}" var="sub" rendered="#{depart.hasSubdepartment}">
<h:inputText value="#{sub.name}"/>
<h:outputText value=" " />
</a4j:repeat>
</a4j:repeat>
</h:panelGrid>
</h:form>
I have simply the form. As you could see, this form displays data structure of departments like a tree.
What I want to implements is that if user switch the radio button to true, the sub-departments will be displayed, if switch to false, the sub-departments will be hidden.
The problem is that:
If the execute value of the f:ajax tag is set to #form, the validation of the backing beans such as #NotNull and #Size will be called. But we don't want to call the validation now since we do not want to save the data now.
If the execute value of the f:ajax tag is set to #this, it seems that the after the ajax request, the value of the radio reverts. For example, if the radio value is false, and we click true, then after the ajax request, the value go back to false, and the sub-department part is not rendered. This will not happen if execute is set to #form.
Thanks very much if you have any idea or hint.
I don't have a Richfaces integrated testing environment, however I've achieved what you want in plain JSF (that's why it could be an ajax4jsf specific issue). Here you have a test case which works and follows SSCCE standards. Tested with Mojarra 2.1.26 & Tomcat 6:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form>
<h:panelGrid columns="2">
<ui:repeat value="#{dialog.departments}" var="depart">
<h:inputText value="#{depart.name}" />
<h:selectOneRadio value="#{depart.hasSubdepartments}">
<f:ajax render="#form" immediate="true" />
<f:selectItem itemValue="#{true}" />
<f:selectItem itemValue="#{false}" />
</h:selectOneRadio>
<h:panelGroup id="subdepartmentPanel"
rendered="#{depart.hasSubdepartments}">
<ui:repeat value="#{depart.subdepartments}" var="sub">
<h:inputText value="#{sub.name}" />
</ui:repeat>
</h:panelGroup>
</ui:repeat>
</h:panelGrid>
</h:form>
</h:body>
</html>
#ManagedBean
#ViewScoped
public class Dialog {
public class Department {
private String name;
private List<Department> subdepartments = new ArrayList<Dialog.Department>();
private boolean hasSubdepartments;
public Department(String name) {
this.name = name;
}
public String getName() {
return name;
}
public List<Department> getSubdepartments() {
return subdepartments;
}
public boolean isHasSubdepartments() {
return hasSubdepartments;
}
public void setHasSubdepartments(boolean hasSubdepartments) {
this.hasSubdepartments = hasSubdepartments;
}
public void setName(String name) {
this.name = name;
}
public void setSubdepartments(List<Department> subdepartments) {
this.subdepartments = subdepartments;
}
}
private List<Department> departments = new ArrayList<Dialog.Department>();
public Dialog() {
// Create departments and subdepartments
departments.add(new Department("First Department"));
Department d = new Department("Second department");
d.getSubdepartments().add(new Department("Subdepartment"));
departments.add(d);
}
public List<Department> getDepartments() {
return departments;
}
}

How to remove a row <h:datatable> programmatically

I have a form like the following picture.
In the above picture you can see a green add button. When I click on it, it create a new row in a datatable via send a <f:ajax> to backing bean and render <h:datatable>.
Until now all thing is good. But i Except when I click on a cross button inside of each row, that row removed. but it have a bug. for example when I click on the third row cross button, it removes this row from backing bean but not from my ui.
in the following you can see my backing bean and .xhtml file.
#ManagedBean(name = "AddPollContorler")
#ViewScoped
public class AddPollControl {
private List<Answer> answers = new ArrayList<Answer>();
#PostConstruct
public void init(){
answers.add(new Answer());
answers.add(new Answer());
}
public List<Answer> getAnswers() {
return answers;
}
public void setAnswers(List<Answer> answers) {
this.answers = answers;
}
public void addAnswer() {
answers.add(new Answer());
}
public void removeAnswer() {
String index=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("index");
if (StringUtil.isNumber(index))
answers.remove(Integer.parseInt(index));
}
}
.xhtml :
<div class="panel panel-success rgt">
<div class="panel-heading rgt">
<div style="float: left;">
<h:commandLink styleClass="btn btn-success table-button" action="#{AddPollContorler.addAnswer}">
<h:graphicImage library="img" name="add.png" styleClass=" table-icon" />
<f:ajax execute="answers" render="answers"></f:ajax>
</h:commandLink>
</div>
<h4><h:outputText value="#{msg['protected.poll.add.answers']}"/></h4>
</div>
<div class="form-margin">
<h:dataTable value="#{AddPollContorler.answers}" var="answer" id="answers" style="width:100%;">
<h:column >
<div class="input-group poll-answer" style="margin: 5px;">
<span class="input-group-addon no-left-radius"><h:outputText value="#{CounterControler.index+1}" /></span>
<h:inputText value="#{answer.text}" styleClass="form-control no-radius"/>
<div class="input-group-addon no-right-radius poll-answer-remove" >
<h:commandLink action="#{AddPollContorler.removeAnswer}">
<h:graphicImage library="img" name="cross.png" />
<f:param name="index" value="#{CounterControler.last}" />
<f:ajax render="answers answers" />
</h:commandLink>
</div>
</div>
</h:column>
</h:dataTable>
</div>
</div>
update: 2013/06/12
#ManagedBean(name="CounterControler")
public class CounterControl {
private int index=0;
public int getIndex(){
return index++;
}
public int getLast(){
return index-1;
}
}
your code does look pretty good already. How does the CounterControler internally work? (no source given) Alternatives to send the current object might be
to give the object directly as the parameter (you need a fitting converter for that),
give it as direct parameter (action="#{AddPollContorler.removeAnswer(answer)}, works from EL 2.2 on), or
directly get the current object out of the given ActionEvent
The last point would look like
xhtml
<h:commandLink action="#{AddPollContorler.removeAnswer}">
<h:graphicImage library="img" name="cross.png" />
<f:ajax render="answers" />
</h:commandLink>
managed bean
public void removeAnswer(ActionEvent ev) {
Answer selectedItem = null;
try {
UIDataTable objHtmlDataTable = retrieveDataTable(
(UIComponent)ev.getSource());
selectedItem = (Answer) objHtmlDataTable.getRowData();
answers.remove(answer);
} catch (NullPointerException e) {
// somehow couldn't find the element
}
}
private static UIDataTable retrieveDataTable(UIComponent component) {
if (component instanceof UIDataTable) {
return (UIDataTable) component;
}
if (component.getParent() == null) {
return null;
}
return retrieveDataTable(component.getParent());
}
I like that one because it takes most logic out of the frontend. Hope you get your rows cleaned with one of that tactics.
Also, you only need to mention answers once in <f:ajax render="answers" />
EDIT: Even I don't know why - wrapping a <h:panelGroup layout="block" id=" answersWrapper"> around the <h:dataTable> and rendering that panelGroup worked for me.
<h:form id="myForm">
<h:panelGroup id="answerWrapper" layout="block">
<rich:dataTable value="#{myTestBean.answers}" var="answer" id="answers">
<h:column >
<h:outputText value="#{answer}"/>
<h:commandButton id="button" action="#{myTestBean.doTheAction}">
<f:ajax render=":myForm:answerWrapper" />
</h:commandButton>
</h:column>
</rich:dataTable>
</h:panelGroup>
</h:form>

'omnifaces.SelectItemsConverter' converter id is not registered

I'm trying to create a selectManyCheckbox feature in my application, but now I'm in "converter problem". To take care this, I'm trying to use Omnifaces that already have a converter to objects.
My solution is based on this and this question (both answered by BalusC).
Don't know if it helps, but he is my view code:
<h:selectManyCheckbox style="margin-bottom: 40px;" id="disciplinas" value="#{cursoMBean.listaDisciplinasDoCurso}" converter="omnifaces.SelectItemsConverter">
<f:selectItems value="#{cursoMBean.listaTodasDisciplinas}" var="disciplina" itemValue="#{disciplina}" itemLabel="#{disciplina.nome}"/>
</h:selectManyCheckbox>
And my MBean:
private static ArrayList<Disciplina> listaTodasDisciplinas;
private static ArrayList<Disciplina> listaDisciplinasDoCurso;
public ArrayList<Disciplina> getListaTodasDisciplinas() {
return listaTodasDisciplinas;
}
public void setListaTodasDisciplinas(
ArrayList<Disciplina> listaTodasDisciplinas) {
CursoMBean.listaTodasDisciplinas = listaTodasDisciplinas;
}
public ArrayList<Disciplina> getListaDisciplinasDoCurso() {
return listaDisciplinasDoCurso;
}
public void setListaDisciplinasDoCurso(
ArrayList<Disciplina> listaDisciplinasDoCurso) {
CursoMBean.listaDisciplinasDoCurso = listaDisciplinasDoCurso;
}
Disciplina:
public class Disciplina {
private int id;
private String nome;
public Disciplina(int id, String nome) {
this.id = id;
this.nome = nome;
}
public Disciplina() {
}
// Methods
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
if (!(nome.isEmpty() || nome == " " || nome == " ")){
this.nome = nome;
}
}
#Override
public String toString() {
return nome;
}
}
My problem is: this actually don't works. When I select some checkbox and submit, this create a new Curso but the arraylist of selected Disciplina still empty. I think the problem is that JSF can't find Omnifaces converter. This is my HTML tag in view:
<html 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"
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
When I hover the "converter" in selectManyCheckbox appears a warning:
'omnifaces.SelectItemsConverter' converter id is not registered.
I putted the Omnifaces JAR inside Web-Inf/lib. To me, everything is okay, why Omnifaces don't populate my ArrayList with the selected items?
Edit
This is the button to submit the form with the checkboxes:
<h:commandButton id="enviar" styleClass="btn btn-lg btn-success pull-right" value="Adicionar" action="#{cursoMBean.cadastrar}">
<f:ajax event="click" onevent="insert.hide()" render=":meuForm:minhaTabela"
listener="#{cursoMBean.cadastrar}" />
</h:commandButton>
And here is the called method:
public String cadastrar() {
Curso curso = new Curso();
System.out.println("Check if listaDisciplinasDoCurso have something inside): " + listaDisciplinasDoCurso.size() +"\n");
for (Disciplina d : listaDisciplinasDoCurso) {
System.out.println(d);
}
if (!(this.getNome().isEmpty() || this.getNome() == " " || this
.getNome() == " ")) {
curso.setNome(this.getNome());
// Clearing the listaDisciplinasDoCurso
listaDisciplinasDoCurso = new ArrayList<Disciplina>();
// Adding course to database
controleCurso.adicionar(curso);
System.out.println("Inserted. " + curso.toString());
} else {
System.out.println("Error: Not inserted. " + curso.toString());
}
limparCampos();
atualizarListagem();
return null;
}
Edit 2
My newest code, with two forms:
<h:form id="inserirDisciplina">
<div class="form-group">
<div class="col-md-10">
<h:inputText styleClass="form-control" id="disciplina" value="#{cursoMBean.nome}" valueChangeListener="#{cursoMBean.atualizarListagemPesquisa}">
<f:ajax event="keyup" render=":meuForm:minhaTabela" />
</h:inputText>
</div>
<div class="col-md-2">
<h:commandButton value="Adicionar" styleClass="btn btn-md btn-success" process="disciplina" partialSubmit="true">
<p:ajax event="click" update=":meuForm:display" render=":meuForm:dialog" partialSubmit="true" process="disciplina" oncomplete="PF('insert').show();" onerror="alert('erro');" />
</h:commandButton>
</div>
</div>
</h:form>
<p:messages autoUpdate="true" />
<p:dialog id="dialog" header="Inserir Curso" widgetVar="insert"
resizable="false" modal="true" width="600" height="500"
hideEffect="clip" closeOnEscape="true">
<h:form>
<h:panelGrid id="display" styleClass="col-lg-10 center" style="margin-top: 10px; margin-bottom: 15px;">
<label for="nome">Nome:</label>
<p:inputText styleClass="form-control adicionar" id="nome" value="#{cursoMBean.nome}">
</p:inputText>
</h:panelGrid>
<h:panelGrid styleClass="col-lg-10 center">
<p:columnGroup>
<label for="disciplinas">Disciplinas do Curso:</label>
<h:selectManyCheckbox style="margin-bottom: 40px;" id="disciplinas" value="#{cursoMBean.listaDisciplinasDoCurso}" converter="omnifaces.SelectItemsConverter">
<f:selectItems value="#{cursoMBean.listaTodasDisciplinas}" var="disciplina" itemValue="#{disciplina}" itemLabel="#{disciplina.nome}" />
</h:selectManyCheckbox>
</p:columnGroup>
</h:panelGrid>
<h:panelGrid styleClass="col-lg-10 center">
<p:columnGroup>
<h:commandButton id="enviar" styleClass="btn btn-lg btn-success pull-right" value="Adicionar" action="#{cursoMBean.cadastrar}">
<f:ajax event="click" execute="#form" onevent="insert.hide()" render=":meuForm:minhaTabela" listener="#{cursoMBean.cadastrar}" />
</h:commandButton>
</p:columnGroup>
</h:panelGrid>
</h:form>
</p:dialog>
As to the Eclipse warning mentioned in the title,
'omnifaces.SelectItemsConverter' converter id is not registered
just ignore it. It's actually registered via a #FacesConverter annotation. It's only the IDE who's not smart enough to detect the #FacesConverter annotated classes in JARs deployed in /WEB-INF/lib. It's only looking for <converter> entries in faces-config.xml. Try to actually run the webapp project. If the converter wasn't properly registered, then you should have gotten the following exception:
javax.faces.FacesException: Expression Error: Object named: omnifaces.SelectItemsConverter not found
Coming back to your concrete problem, those static properties aren't right. Remove those static modifiers. Also, the <f:ajax> executes by default the current component, as in
<f:ajax execute="#this">
You need to specify it to #form if you intend to execute the entire form
<f:ajax execute="#form">
Also, the onevent="insert.hide()" is wrong. The onevent attribute should point to a function reference, not perform a function call. The function reference is in turn called three times per ajax request. Just use <h:commandButton onclick> for that instead.
Unrelated to the concrete problem, also get rid of event="click" it's the default already. There's no need to repeat the defaults.

Resources