I'm sure that the question is asked before, but I can't fin my explicit problem, I'm afraid it is only a little typo and I can't see it.
I have a simple page in primefaces 10 with a toolbar, with an add-button, a table and a dialoge for adding the data. The dialog has a rendered tag that the requiered field are only rendered if there is a new variable. Everything I used on several other pages of my project.
The new Variable is initialized perfectly but the inside of the dialog isn't rendered, if I remove the rendered tag the field is rendered, but I have put some test-content into my new Variable and this isn't shown either, so I think that my update doesn't get called but I don't see why.
So here is my code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition 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="layout.xhtml">
<ui:define name="header">
<div id="header">
ChangeLog
</div>
</ui:define>
<ui:define name="main">
<h:form id="changelogfrm">
<p:growl id="messages" showDetail="true" life="3000" />
<div class="card">
<p:toolbar>
<p:toolbarGroup>
<p:commandButton value="Neu" icon="pi pi-plus" actionListener="#{changeloghandler.newChangelog}"
update=":changelogfrm:manage-change-content" oncomplete="PF('manageChangeDialog').show()"
styleClass="ui-button-success" style="margin-right: .5rem" />
</p:toolbarGroup>
</p:toolbar>
<p:dataTable var="change" value="#{changeloghandler.changeLogs}"
showGridlines="true" size="small" id="dtChange">
<p:column headerText="Version">
<h:outputText value="#{change.version}" />
</p:column>
<p:column headerText="Typ">
<h:outputText value="#{change.changeType}"/>
</p:column>
<p:column headerText="Beschreibung">
<h:outputText value="#{change.description}"/>
</p:column>
<p:column headerText="Datum">
<h:outputText value="#{change.date}">
<f:convertDateTime type="date" pattern="dd.MM.yyyy HH:mm"/>
</h:outputText>
</p:column>
</p:dataTable>
<p:dialog header="Change" showEffect="fade" modal="true"
widgetVar="manageChangeDialog" responsive="true">
<p:outputPanel id="manage-change-content" class="ui-fluid">
<p:outputPanel rendered="#{not empty changeloghandler.selected}">
<div class="p-field">
<p:outputLabel for="chBeschreibung">Beschreibung</p:outputLabel>
<p:inputTextarea id="chBeschreibung" value="#{changeloghandler.selected.description}" required="true"/>
</div>
</p:outputPanel>
</p:outputPanel>
<f:facet name="footer">
<p:commandButton value="Save" icon="pi pi-check" actionListener="#{changeloghandler.save}"
update="manage-change-content" process="manage-change-content #this"/>
<p:commandButton value="Cancel" icon="pi pi-times" onclick="PF('manageChangeDialog').hide()"
class="ui-button-secondary"/>
</f:facet>
</p:dialog>
</div>
</h:form>
</ui:define>
</ui:composition>
The save-function in the dialog isn't called either.
I've also checked the html on the site, there is no double-form and the ids are set correctly.
Hope you can help me.
!!!EDIT!!!
Hi, here you have the Bean-Class:
package main.java.handler;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import org.primefaces.PrimeFaces;
import main.java.persistence.entities.ChangeLog;
import main.java.persistence.entities.enums.ChangeType;
import main.java.persistence.entities.enums.Version;
import main.java.persistence.interfaces.ChangeLogDbInterface;
#Named("changeloghandler")
#SessionScoped
public class ChangeLogHandler implements Serializable{
private static final long serialVersionUID = 1L;
private List<ChangeLog> changeLogs;
private ChangeLog selected;
private List<Version> versions;
private ChangeType[] changeTypes;
#PostConstruct
private void init() {
changeLogs = ChangeLogDbInterface.loadChangeLogItems();
versions = new ArrayList<>();
for(Version v : Version.values()) {
if(v.isActive()) versions.add(v);
}
changeTypes = ChangeType.values();
}
public void newChangelog() {
ChangeLog newLog = new ChangeLog();
newLog.setDate(new Timestamp(System.currentTimeMillis()));
this.selected = newLog;
}
public void save() {
if (this.selected.getId() == 0) {
ChangeLogDbInterface.createChangeLogItem(selected);
this.changeLogs.add(this.selected);
}
else {
ChangeLogDbInterface.updateChangeLogItem(selected);
}
PrimeFaces.current().executeScript("PF('manageChangeDialog').hide()");
PrimeFaces.current().ajax().update("changelogfrm:dtChange");
}
public List<ChangeLog> getChangeLogs() { return changeLogs; }
public ChangeLog getSelected() { return selected; }
public List<Version> getVersions() { return versions; }
public ChangeType[] getChangeTypes() { return changeTypes; }
public void setChangeLogs(List<ChangeLog> changeLogs) { this.changeLogs = changeLogs; }
public void setSelected(ChangeLog selected) { this.selected = selected; }
public void setVersions(List<Version> versions) { this.versions = versions; }
public void setChangeTypes(ChangeType[] changeTypes) { this.changeTypes = changeTypes; }
}
!!! EDIT 2 !!!
Here is the template, but I think that doesn't help much either:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Asset Tool Connector</title>
<link type="text/css"
href="${facesContext.externalContext.requestContextPath}/resources/css/style.css"
rel="stylesheet" />
<link type="image/x-icon"
href="${facesContext.externalContext.requestContextPath}/resources/images/netzwerk.png"
rel="shortcut icon" />
</h:head>
<h:body>
<ui:insert name="header"/>
<f:event listener="#{sessionHandler.checkLoggedIn}" type="preRenderView" />
<div id="menu">
<ui:include src="menu.xhtml" />
</div>
<div id="main">
<ui:insert name="main"/>
</div>
<div id="footer">
<div>
<h:form id="footerForm">
<p:commandButton value="ChangeLog" action="/changelog?faces-redirect=true"/>
</h:form>
</div>
© ATC - by 5332
</div>
</h:body>
</html>
Except the button in the footer links to the page with my issue, if that would be an issue.
Related
I have to call a remote command through javascript. The remote command is working fine but it invokes on page load instead of the button's onclick event.
Following is my xhtml file code as well as the bean code.
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Crowd Flow</title>
</h:head>
<f:event listener="#{task.loadTaskByTaskId(param['task_id'])}"
type="preRenderView" />
<h:body bgcolor="white">
<h:outputScript>
function getCurrentLocation() {
testingCommand();
}
</h:outputScript>
<h:panelGroup id="header" layout="block">
<h3>Welcome to the task.</h3>
</h:panelGroup>
<h:panelGroup id="taskLayout" layout="block">
<h:outputText value="Category is #{task.taskCategory}"></h:outputText>
<h:outputText value="Task id is is #{task.id}"></h:outputText>
<c:if test="#{param['task_id']=='9'}">
<h:form style="width:400px;" id="newTagTaskForm">
<p:remoteCommand name="testingCommand"
actionListener="#{task.testingCommand()}" autoRun="false" />
Task Name : <h:outputText id="taskName"
value="#{task.newPlaceTagTask.name}"></h:outputText>
<br />
Task Description : <h:outputText id="taskDescription"
value="#{task.newPlaceTagTask.description}"></h:outputText>
<br />
Address : <h:outputText id="taskAddress"
value="#{task.newPlaceTagTask.location.address}"></h:outputText>
<br />
Image : <h:graphicImage width="50" height="50"
url="#{task.newPlaceTagTask.location.image}" />
<br />
<h:inputHidden value="#{task.userId}" id="taskPlaceTagUserId"
name="taskPlaceTagUserId" />
<h:inputHidden value="#{task.newPlaceTagTask.location.id}"
id="taskPlaceTagLocationId" name="taskPlaceTagLocationId" />
<h:commandButton id="testing" value="submit" type="submit" onclick="getCurrentLocation();return false;" ></h:commandButton>
</h:form>
</c:if>
</h:panelGroup>
</h:body>
</html>
Here is the bean function, bean is view scoped.
package com.project.crowdsource.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean(name="task")
#ViewScoped
public class TaskBean implements Serializable {
public TaskBean() {
//initiating user's data access object.
taskDao = new TaskDAO();
}
public String testingCommand() {
System.out.println("in action testing command");
return "";
}
}
Any help would be highly appreciated.
Thanks,
I am developing small web app using JSF/PrimeFaces. I am able to call bean from web, however, I am unable to return web. This is what I have:
requestLeave.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Request leave</title>
</h:head>
<h:body>
<script language="javascript">
var today = new Date();
document.write(today);
</script>
<h:form id="form" >
<h:panelGrid id= "grid" columns="2" cellpadding="5">
<f:facet name="header">
<p:messages id="msgs" />
</f:facet>
<h:outputLabel for="title" value="Leave Title:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.titleLeave}" required="true" requiredMessage="title is required." />
<h:outputLabel for="type" value="Type:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.typeLeave}" required="true" requiredMessage="type is required." />
<p:commandButton value="Submit" actionListener="#{requestLeave.buttonAction}" />
</h:panelGrid>
</h:form>
</h:body>
</html>
RequestLeave.java
import javax.faces.bean.ManagedBean;
#ManagedBean
public class RequestLeave {
private String titleLeave;
private String typeLeave;
public String getTitleLeave() {
return titleLeave;
}
public void setTitleLeave(String titleLeave) {
this.titleLeave = titleLeave;
}
public String getTypeLeave() {
return typeLeave;
}
public void setTypeLeave(String typeLeave) {
this.typeLeave = typeLeave;
}
public String buttonAction() {
System.out.println("leave title " + titleLeave);
System.out.println("leave type " + typeLeave);
return ("index.jsp");
}
}
With this, I cannot return to index.jsp. Can anyone help me? Thanks in advance.
Change the actionListener attribute to action:
<p:commandButton value="Submit" action="#{requestLeave.buttonAction}" />
More info:
Differences between action and actionListener?
Hello I have an inputText on blur event that will send a signal to the backing bean, this bean contains a Boolean variable that determines if another input text will be enabled or not ... but I can not make this work, this is my code:
<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="/Template.xhtml">
<ui:define name="content">
<h:form id="someForm">
<p:growl id="msg" showDetail="true" life="3000"/>
<p:panelGrid border="0" id="panel">
<p:row>
<p:column width="350">
Title
</p:column>
<p:column colspan="2">
<p:inputText id="someId" value="#{someBean.somePropertie}">
<p:ajax event="blur" update="anotherInput" listener="#{someBean.onEvent}" />
</p:inputText>
</p:column>
</p:row>
<p:row>
<p:column width="350">title 2</p:column>
<p:column colspan="2">
<p:inputText id="anotherInput" converter="toUpperCaseConverter" value="#{someBean.somePropertie2}"
disabled="#{someBean.bDisabled}"
/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
Backing bean:
#ManagedBean
#SuppressWarnings("serial")
public class SomeBean implements Serializable{
private boolean bDisabled;
private String somePropertie;
private String somePropertie2;
public void onEvent(){
System.out.println("DO SOMETHING");
this.bDisabled = true;
}
... getters and setters of properties and boolean ....
}
this is the main tamplate:
<!DOCTYPE html>
<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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>..:: XXXXX ::..</title>
<meta http-equiv="Pragma" content="no-cache" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/default.css"/>
<style type="text/css">
.ui-growl{
position:absolute;
top:20%;
left:50%;
z-index:9999;
}
.ui-widget,.ui-widget .ui-widget {
font-family: Trebuchet MS;
}
</style>
</h:head>
<h:body style="background-color: #E1E1E1;">
<div id="page">
<div id="divHeader" style="height: 70px;">
<ui:insert name="header" >
<ui:include src="header.xhtml" />
</ui:insert>
</div>
<div id="divMenu" style="height: 50px;">
<ui:insert name="menu">
<ui:include src="menu.xhtml" />
</ui:insert>
</div>
<div id="divContent">
<ui:insert id="content" name="content" >
<ui:include src="content.xhtml" />
</ui:insert>
</div>
</div>
</h:body>
</html>
the converter:
#FacesConverter("toUpperCaseConverter")
public class ToUpperCaseConverter implements Converter {
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return (String) value;
}
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return (value != null) ? value.toUpperCase() : null;
}
}
any idea ???
Please help :(
Your question is not complete, since it does not provide all the elements to reproduce the bug. You haven't provided the page that calls your element, neither the converter, etc.
JSF's debugger best friend is firebug. Always check for javascript errors and enable the network tab to see each request response body, which may contain "silent" error messages.
I'll take my risk trying to guess your problem :-)
Here's your code, slightly changed to run in my primefaces 4.
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>You NEED a header</title>
</h:head>
<h:body>
<h:form>
<ui:include src="index2.xhtml" />
</h:form>
</h:body>
</html>
and
<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">
<p:growl
id="msg"
showDetail="true"
life="3000" />
<p:panelGrid
border="0"
id="panel">
<p:row>
<p:column width="350">
Title
</p:column>
<p:column colspan="2">
<p:inputText
id="someId"
value="#{someBean.somePropertie}">
<p:ajax
event="blur"
update="anotherInput"
listener="#{someBean.onEvent}" />
</p:inputText>
</p:column>
</p:row>
<p:row>
<p:column width="350">title 2</p:column>
<p:column colspan="2">
<p:inputText
id="anotherInput"
value="#{someBean.somePropertie2}"
disabled="#{someBean.bDisabled}" />
</p:column>
</p:row>
</p:panelGrid>
</ui:composition>
The managed bean is pretty much the same
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
#ManagedBean
#SuppressWarnings("serial")
public class SomeBean implements Serializable {
private boolean bDisabled;
private String somePropertie;
private String somePropertie2;
public void onEvent() {
System.out.println("DO SOMETHING");
this.bDisabled = true;
}
public boolean isbDisabled() {
return this.bDisabled;
}
public void setbDisabled(boolean bDisabled) {
this.bDisabled = bDisabled;
}
public String getSomePropertie() {
return this.somePropertie;
}
public void setSomePropertie(String somePropertie) {
this.somePropertie = somePropertie;
}
public String getSomePropertie2() {
return this.somePropertie2;
}
public void setSomePropertie2(String somePropertie2) {
this.somePropertie2 = somePropertie2;
}
}
I've noticed that if you don't omit the HEAD section from the caller page, it seems to render and work.
But if you forget the HEAD section (you must not, see Primefaces FAQ item #2), you'll render the page (quite) but you'll get some javascript errors and your page won't work. The HEAD section I am talking about is this
<h:head>
<title>You NEED a header</title>
</h:head>
This is how it looks without the HEAD section.
With the HEAD section, it seems to work. Also notice the subtle primefaces look and feel.
When I click on the button New <p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>, a new row is added to my dataTable on only the first click and the page is refreshed. Several cliques except the first were not refreshes the dataTable. So to see my newly added rows, I use the F5 key to refresh my page. Certainly my update="dataTableSaisiePiece" not work or only works rather the first click.
Here is my page home.xhtml :
<?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://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">
<script type="text/javascript">
function addRowOnComplete() {
jQuery('#supercoolnewrow').trigger('click');
}
</script>
<ui:composition template="/resources/template/all.xhtml">
<ui:define name="titre">Saisie</ui:define>
<ui:define name="content">
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<h:outputScript library="js" name="frenchLocale.js" />
<h:form id="formPiece">
<p:panel id="panelSaisie" header="Saisir" style="color: brown;font-size: 15px">
<h:panelGrid columns="3" >
<p:outputLabel for="description" value="Description:" ></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}" required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:" ></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date" value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant" ></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}" required="true" >
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br/>
<p:dataTable var="line" value="#{ecritureCtrl.lignes}" id="dataTableSaisiePiece" >
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%"/>
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>
</h:form>
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</html>
My ManagedBean:
#ManagedBean (name = "ecritureCtrl")
#SessionScoped
public class EcritureCtrl {
private List<Avant> lignes = new ArrayList<Avant>();
Avant unUser;
private String description;
private Date date;
private String code;
public EcritureCtrl() {
lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent){
lignes.add(new Avant());
}
}
Could you please help me ?
Thanks in advance.
this seems to work for me
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
#ManagedBean
#SessionScoped
public class EcritureCtrl implements Serializable {
private static final long serialVersionUID = 1L;
private String code;
private Date date;
private String description;
private List<Avant> lignes = new ArrayList<Avant>();
private Avant unUser;
public String getCode() {
return this.code;
}
public Date getDate() {
return this.date;
}
public String getDescription() {
return this.description;
}
public List<Avant> getLignes() {
return this.lignes;
}
public Avant getUnUser() {
return this.unUser;
}
#PostConstruct
private void init(){
this.lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent) {
this.lignes.add(new Avant());
}
public void setCode(String code) {
this.code = code;
}
public void setDate(Date date) {
this.date = date;
}
public void setDescription(String description) {
this.description = description;
}
public void setLignes(List<Avant> lignes) {
this.lignes = lignes;
}
public void setUnUser(Avant unUser) {
this.unUser = unUser;
}
}
and
<!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://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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sorry</title>
</h:head>
<h:body>
<script type="text/javascript">
function addRowOnComplete() {
alert();
}
</script>
<h:form id="formPiece">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<p:panel id="panelSaisie" header="Saisir"
style="color: brown;font-size: 15px">
<h:panelGrid columns="3">
<p:outputLabel for="description" value="Description:"></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}"
required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:"></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date"
value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant"></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}"
required="true">
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br />
<p:dataTable var="line" value="#{ecritureCtrl.lignes}"
id="dataTableSaisiePiece">
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%" />
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}"
value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()"
ajax="true" />
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
I'm having a problem when I include dynamically a page with <ui:include>, the action and actionlistener associated with the <p:commandButton> component is not being invoked.
I've tried to remove the tag <h:form> from the included page but the problem persists.What can I do to solve this problem?
The source code:
hello.xhtm (Main Page)
<!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://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">
<f:view>
<h:head>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<f:view contentType="text/html" />
</h:head>
<h:body>
<h:form id="helloForm">
<p:growl id="messages" />
<p:panelGrid id="panelGridPrincipal" styleClass="panelGridPrincipal">
<p:row>
<p:column colspan="2">
<div style="width: 100%; height: 25px; padding-left: 230px;">
<p:commandButton id="botao1" value="Bookmark" styleClass="button"/>
<p:commandButton id="botao2" value="Bookmark2" styleClass="button"
actionListener="#{mainBean.renderMenuVendas}" update="panel" >
<f:setPropertyActionListener value="2" target="#{mainBean.menuType}" />
</p:commandButton>
</div>
</p:column>
</p:row>
<p:row>
<p:column id="column2" style="width:200px;background-color: #5A5858;">
<h:panelGrid id="panel" styleClass="panelGridMenu" columns="1">
<p:menu id="dynamicMenu" model="#{mainBean.sideMenu}" rendered="#{mainBean.showMenuVendas}" style="width:189px;margin-right:100%;"/>
<p:spacer width="50px" height="700px" />
</h:panelGrid>
</p:column>
<p:column style="background-color: white">
<p:panelGrid style="border:1px;">
<p:row>
<p:column>
<p:outputPanel id="outputPanelConteudo">
<ui:include src="#{mainBean.paginaAtual}" />
</p:outputPanel>
</p:column>
</p:row>
<p:row/>
</p:panelGrid>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
</h:body>
</f:view>
</html>
pagina1.xhtml (Included Page)
<?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">
<ui:composition 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">
<p:dataTable id="avioes" var="aviao" value="#{listaAvioesBean.aviao}"
rowKey="#{aviao.numeroSerie}"
selection="#{listaAvioesBean.selectedAviao}" selectionMode="single"
style="width:500px">
<p:column style="width:75px">
<f:facet name="header">
<h:outputText value="Numero de Serie" />
</f:facet>
<h:outputText value="#{aviao.numeroSerie}" />
</p:column>
<p:column style="width:100px">
<f:facet name="header">
<h:outputText value="Marca" />
</f:facet>
<h:outputText value="#{aviao.marca}" />
</p:column>
<p:column style="width:75px">
<f:facet name="header">
<h:outputText value="Modelo" />
</f:facet>
<h:outputText value="#{aviao.modelo}" />
</p:column>
<p:column style="width:75px">
<p:commandButton id="insertAviao" value="Inserir" title="Visualizar">
<f:setPropertyActionListener value="#{aviao}"
target="#{listaAvioesBean.selectedAviao}" />
</p:commandButton>
<!--THESE ACTION DOESN'T CALL THE BEAN METHOD!!! -->
<p:commandButton id="removerAviao" style="width:50px" value="P"
title="Deletar" action="#{listaAvioesBean.removerAviao}"
update=":helloForm:outputPanelConteudo">
<f:setPropertyActionListener value="#{aviao}"
target="#{listaAvioesBean.selectedAviao}" />
</p:commandButton>
</p:column>
</p:dataTable>
</ui:composition>
Managed bean (ListaAvioesBean.java)
package br.com.erp.beans;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import br.com.erp.object.Aviao;
#ManagedBean(name="listaAvioesBean")
#ViewScoped
public class ListaAvioesBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8076960891132613195L;
private Aviao selectedAviao;
private List<Aviao> aviao;
public ListaAvioesBean(){
aviao = new ArrayList<Aviao>();
System.out.println("ListaAvioesBean Criado!");
}
#PostConstruct
public void init(){
System.out.println("Iniciando o bean!");
populateListAvioes();
}
public void executa(){
System.out.println("Executou");
}
private void populateListAvioes(){
Aviao av1 = new Aviao();
av1.setMarca("Marca1");
av1.setModelo("M1");
av1.setNumeroSerie("1234");
aviao.add(av1);
av1 = new Aviao();
av1.setMarca("Marca2");
av1.setModelo("M2");
av1.setNumeroSerie("1111");
aviao.add(av1);
av1 = new Aviao();
av1.setMarca("Marca3");
av1.setModelo("M3");
av1.setNumeroSerie("4321");
aviao.add(av1);
}
public Aviao getSelectedAviao() {
return selectedAviao;
}
public void setSelectedAviao(Aviao selectedAviao) {
this.selectedAviao = selectedAviao;
}
public List<Aviao> getAviao() {
return aviao;
}
public void setAviao(List<Aviao> aviao) {
this.aviao = aviao;
}
public void removerAviao(){
boolean removeu = aviao.remove(selectedAviao);
if(removeu)
System.out.println("Avião removido com sucesso");
}
public void executa(ActionEvent e){
System.out.println();
}
}