multiple forms JSF + primefaces 3.5 - forms

My question is similar like this one How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?, I have a main Page which has a panelMenu with menuitems, when I click in some menuitems, it refresh the middle part of my page called "centro" is like a template if I click in the "left content", only I want to refresh the "content".
I download a template but I wasn't in jsf so I create "layaout" inside that CSS template, but I have a form here that evaluates a case to redirect another page and show it in the middle of id "centro"
I have a problem in my middle page, which has other's forms. I read nest forms is not a valid concept but I need to redirect my page only in the middle, but when I run the project.
My button doesn't invoke my methods, but if I only run my middle page its works fine.
The nest forms are main which and the forms of my middle page, any help?
this is my main page
<h:form id="main" onsubmit="#{beanSec.setPer()}">
<p:layout style="height: 500px;" id="layout">
<p:layoutUnit position="west" resizable="false" size="188">
<p:menu style="width: 175px; border:0px ;background: #660000 ;">
<!-- puse width para el efecto cuando pasa el mouse no altere a los demas solo a este y paddin para alinearlo a mi gusto -->
<p:menuitem value="Interesados" update="centro"
ajax="false"
style="font-size:17px; padding-left: 32px; width: 80%"
action="#{navBean.setPaginaSecretaria('interesados')}" />
</p:menu>
<p:panelMenu style="width:180px;">
<p:submenu label="Académico">
<p:menuitem value="Matrícula"
style="color: black; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('matricula')}" />
<p:menuitem value="Alumnos"
style="color:black ; font-weight: bold;" update="centro"
ajax="false" async="true"
action="#{navBean.setPaginaSecretaria('alumno')}" />
<p:menuitem value="Programación"
style="color: black ; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('programacion')}" />
<p:menuitem value="Cursos"
style="color:black ; font-weight: bold;" update="centro"
ajax="false" url="ListarCursos.xhtml" />
<!--action="{navBean.setPaginaSecretaria('cursos')}"-->
<p:menuitem value="Docentes"
style="color:black ; font-weight: bold;" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('docente')}" />
<p:menuitem value="Laboratorios"
style="color:black ; font-weight: bold ;" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('laboratorio')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Recaudación">
<p:menuitem value="Cuentas Bancarias"
style="color:black ; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('cuentas')}" />
<p:menuitem value="Pagos"
style="color:black; font-weight: bold;" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('pagos')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Acreditaciones">
<p:menuitem value="Convenios"
style="color:black ; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('convenios')}" />
<p:menuitem value="Certificaciones"
style="color:black; font-weight: bold;" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('certificaciones')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Eventos y noticias">
<p:menuitem value="Eventos"
style="color: black ; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('eventos')}" />
<p:menuitem value="Noticias"
style="color: black ; font-weight: bold" update="centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('noticias')}" />
</p:submenu>
</p:panelMenu>
<!-- puse width para el efecto cuando pasa el mouse no altere a los demas solo a este y paddin para alinearlo a mi gusto -->
<p:menu style="width: 175px; border:0px ;background:#660000;">
<p:menuitem value="Datos Personales" update="centro"
style="font-size:17px; padding-left: 32px; width: 80%;"
ajax="false"
action="#{navBean.setPaginaSecretaria('datos')}" />
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center" id="centro"
style="padding-left: 20px">
<c:if test="#{navBean.paginaSecretaria eq 'interesados'}">
<ui:include src="ListarInteresados.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'matricula'}">
<ui:include src="Matricula.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'alumno'}">
<ui:include src="ListarAlumnos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'programacion'}">
<ui:include src="ListarProgramacion.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'cursos'}">
<ui:include src="ListarCursos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'docente'}">
<ui:include src="ListarDocentes.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'laboratorio'}">
<ui:include src="ListarLaboratorios.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'cuentas'}">
<ui:include src="CuentasBancarias.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'pagos'}">
<ui:include src="Pagos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'convenios'}">
<ui:include src="ListarConvenios.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'certificaciones'}">
<ui:include src="ListarCertificaciones.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'eventos'}">
<ui:include src="ListarEventos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'noticias'}">
<ui:include src="ListarNoticias.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'datos'}">
<ui:include src="DatosPersonalesSecretaria.xhtml" />
</c:if>
</p:layoutUnit>
</p:layout>
</h:form>
this is my middle page
<h:form>
<p:dataTable id="dt1" value="#{DAOCurso.listarTodosCursos()}"
var="datos">
<f:facet name="header">Listado de Cursos</f:facet>
<p:column filterBy="#{datos.nombre}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputLabel value="Curso" />
</f:facet>
<h:outputText value="#{datos.nombre}" style="color: black">
</h:outputText>
</p:column>
<p:column filterBy="#{datos.siglas}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputLabel value="Siglas" />
</f:facet>
<h:outputText value="#{datos.siglas}" style="color: black">
</h:outputText>
</p:column>
<p:column filterBy="#{datos.certificacion.nombre}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputLabel value="Certificación" />
</f:facet>
<h:outputText value="#{datos.certificacion.nombre}"
style="color: black"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Modificar" />
</f:facet>
<p:commandLink value="Modificar" oncomplete="dlg2.show();"
update=":main:modalDialog2" style="color: black"
action="#{beanCurso.traerDatos()}">
<f:setPropertyActionListener target="#{beanCurso.codigo}"
value="#{datos.codigo}" />
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="modalDialog2" header="Modificar Datos Personales"
widgetVar="dlg2" dynamic="true">
<h:form id="form2">
<table>
<tr>
<td>
<h:outputLabel value="Nombre Curso" />
<p:inputText id="nombre" value="#{beanCurso.nombre}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel value="Siglas" />
<p:inputText value="#{beanCurso.siglas}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel value="Certificación" />
<p:selectOneMenu id="cboCentro"
value="#{beanCurso.certificacion.codigo}" required="true"
requiredMessage="Debe seleccionar una certificacion">
<f:selectItem itemLabel="Seleccione Certificacion"
id="cert" />
<f:selectItems value="#{DAOCert.listaCertificaciones()}"
id="combocert" var="cert" itemValue="#{cert.codigo}"
itemLabel="#{cert.nombre}" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td>
<p:selectBooleanCheckbox value="#{beanCurso.vigencia}" />
<h:outputText value="Vigencia"
style="font-weight:bold" />
</td>
</tr>
<tr>
<td>
<p:commandButton value="Modificar"
action="#{DAOCurso.modificarCurso()}" ajax="false" />
</td>
</tr>
</table>
</h:form>
</p:dialog>
<p />
<h:form>
<p:commandButton value="Agregar" oncomplete="dlg.show();" />
<p:dialog header="Datos Personales" widgetVar="dlg"
resizable="false" id="dialogo" dynamic="true">
<table>
<tr>
<td>
<h:outputLabel value="Nombre Curso" />
<p:inputText id="nombre" value="#{beanCurso.nombre}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel value="Siglas" />
<p:inputText value="#{beanCurso.siglas}" />
</td>
</tr>
<tr>
<td>
<h:outputLabel value="Certificación" />
<p:selectOneMenu value="#{beanCurso.codCert}"
required="true"
requiredMessage="Debe seleccionar una certificacion">
<f:selectItem itemLabel="Seleccione Certificacion"
id="cert" itemValue="" />
<f:selectItems value="#{DAOCert.listaCertificaciones()}"
id="combocert" var="cert" itemValue="#{cert.codigo}"
itemLabel="#{cert.nombre}" />
</p:selectOneMenu>
</td>
</tr>
<tr>
<td>
<h:commandButton value="Registrar Curso"
action="#{DAOCurso.insertarCurso()}" />
</td>
</tr>
</table>
</p:dialog>
</h:form>

As Luiggi said, you should split your main form into multiple forms:
<p:layout style="height: 500px;" id="layout">
<p:layoutUnit position="west" resizable="false" size="188">
<h:form id="main" onsubmit="#{beanSec.setPer()}">
<p:menu style="width: 175px; border:0px ;background: #660000 ;">
<!-- puse width para el efecto cuando pasa el mouse no altere a los demas solo a este y paddin para alinearlo a mi gusto -->
<p:menuitem value="Interesados" update=":centro"
ajax="false"
style="font-size:17px; padding-left: 32px; width: 80%"
action="#{navBean.setPaginaSecretaria('interesados')}" />
</p:menu>
<p:panelMenu style="width:180px;">
<p:submenu label="Académico">
<p:menuitem value="Matrícula"
style="color: black; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('matricula')}" />
<p:menuitem value="Alumnos"
style="color:black ; font-weight: bold;" update=":centro"
ajax="false" async="true"
action="#{navBean.setPaginaSecretaria('alumno')}" />
<p:menuitem value="Programación"
style="color: black ; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('programacion')}" />
<p:menuitem value="Cursos"
style="color:black ; font-weight: bold;" update=":centro"
ajax="false" url="ListarCursos.xhtml" />
<!--action="{navBean.setPaginaSecretaria('cursos')}"-->
<p:menuitem value="Docentes"
style="color:black ; font-weight: bold;" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('docente')}" />
<p:menuitem value="Laboratorios"
style="color:black ; font-weight: bold ;"
update=":centro" ajax="false"
action="#{navBean.setPaginaSecretaria('laboratorio')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Recaudación">
<p:menuitem value="Cuentas Bancarias"
style="color:black ; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('cuentas')}" />
<p:menuitem value="Pagos"
style="color:black; font-weight: bold;" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('pagos')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Acreditaciones">
<p:menuitem value="Convenios"
style="color:black ; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('convenios')}" />
<p:menuitem value="Certificaciones"
style="color:black; font-weight: bold;" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('certificaciones')}" />
</p:submenu>
</p:panelMenu>
<p:panelMenu style="width:180px;">
<p:submenu label="Eventos y noticias">
<p:menuitem value="Eventos"
style="color: black ; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('eventos')}" />
<p:menuitem value="Noticias"
style="color: black ; font-weight: bold" update=":centro"
ajax="false"
action="#{navBean.setPaginaSecretaria('noticias')}" />
</p:submenu>
</p:panelMenu>
<!-- puse width para el efecto cuando pasa el mouse no altere a los demas solo a este y paddin para alinearlo a mi gusto -->
<p:menu style="width: 175px; border:0px ;background:#660000;">
<p:menuitem value="Datos Personales" update=":centro"
style="font-size:17px; padding-left: 32px; width: 80%;"
ajax="false"
action="#{navBean.setPaginaSecretaria('datos')}" />
</p:menu>
</h:form>
</p:layoutUnit>
<!-- Since you have a form inside each included xhtml file, you don't need following code to be inside the main form-->
<p:layoutUnit position="center" id="centro"
style="padding-left: 20px">
<c:if test="#{navBean.paginaSecretaria eq 'interesados'}">
<ui:include src="ListarInteresados.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'matricula'}">
<ui:include src="Matricula.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'alumno'}">
<ui:include src="ListarAlumnos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'programacion'}">
<ui:include src="ListarProgramacion.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'cursos'}">
<ui:include src="ListarCursos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'docente'}">
<ui:include src="ListarDocentes.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'laboratorio'}">
<ui:include src="ListarLaboratorios.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'cuentas'}">
<ui:include src="CuentasBancarias.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'pagos'}">
<ui:include src="Pagos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'convenios'}">
<ui:include src="ListarConvenios.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'certificaciones'}">
<ui:include src="ListarCertificaciones.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'eventos'}">
<ui:include src="ListarEventos.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'noticias'}">
<ui:include src="ListarNoticias.xhtml" />
</c:if>
<c:if test="#{navBean.paginaSecretaria eq 'datos'}">
<ui:include src="DatosPersonalesSecretaria.xhtml" />
</c:if>
</p:layoutUnit>
</p:layout>
Last remark, you should avoid using JSTL with JSF, try to use rendered attribute instead.

Related

How to get rid of warnings such as "attrs cannot be resolved as a member of cc"?

How can I get rid of warnings for tags having "cc.attrs.onCompleteJS", "cc.attrs.updateAjax" and "cc.attrs.imageValue"? Each warning has same explanation as "attrs cannot be resolved as a member of cc". I use JSF 2.x as a framework and Eclipse as an editor.
<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:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui">
<composite:interface>
<composite:attribute name="imageValue"></composite:attribute>
<composite:attribute name="updateAjax"></composite:attribute>
<composite:attribute name="onCompleteJS"></composite:attribute>
</composite:interface>
<composite:implementation>
<h:outputStylesheet library="css" name="regionTreeComponent.css"></h:outputStylesheet>
<table style="width: 100%" cellspacing="0" cellpadding="5">
<tr>
<td style="width: 100%">
<p:autoComplete forceSelection="true" id="sTxtRegionName" value="#{regionTreeBean.sRegionName}"
completeMethod="#{regionTreeBean.completeRegionName}" styleClass="sTxtRegionName" />
</td>
<td>
<p:commandButton styleClass="rSearchButton" id="iconOnly" icon="ui-icon-search" actionListener="#{regionTreeBean.searchSelectNode}"
oncomplete="#{cc.attrs.onCompleteJS}" update=":mainForm:treeComponent:regionTree #{cc.attrs.updateAjax}"/>
</td>
</tr>
</table>
<hr style="width: 100%;"></hr>
<div style="text-align: center;">
<h:graphicImage styleClass="headerImage" library="images" name="#{cc.attrs.imageValue}"></h:graphicImage>
<p:outputLabel styleClass="headerLabel" value="#{msgs['treeComponent.regions']}"></p:outputLabel>
</div>
<p:tree value="#{regionTreeBean.rootNode}" var="node"
animate="true" selection="#{regionTreeBean.selectedNode}"
selectionMode="single" styleClass="tree" id="regionTree">
<p:ajax event="select" listener="#{regionTreeBean.onNodeSelect}" update="#{cc.attrs.updateAjax}" oncomplete="#{cc.attrs.onCompleteJS}" />
<p:treeNode styleClass="slTreeNode" icon="region">
<h:outputText value="#{node.REGION_NAME}"/>
</p:treeNode>
</p:tree>
</composite:implementation>
</html>

JBoss/RichFaces: Action not called if first selectOneMenu in DataTable is empty

I have a problem with richfaces page on JBoss. The page contains (among other things) a list of projects that are to be closed. Before the project can be closed a reason has to be selected. Not all projects need to be filled out. The ones that are left blank are not closed and remain in the table.
Now the problem: If the first row is left blank (no matter which other rows are filled out), the page reloads but the function specified as action on the command button (adminInformationBean.startClosingProjects()) is never called. If a reason is selected at least for the first row, everything is working fine.
This is the xhtml file:
<!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:s="http://jboss.org/schema/seam/taglib"
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:rich="http://richfaces.org/rich"
template="/layout/template.xhtml"
xmlns:a4j="http://richfaces.org/a4j">
<ui:define name="body">
<div id="cku1405090004">
<h:form id="uma1407080001">
<div>
<rich:panel styleClass="PanelHeader">
<f:facet name="header">
#{messages.adminInfo_table_header}
</f:facet>
<rich:tabPanel id="myTabPanelAdminInfo" styleClass="PanelHeader">
[...]
<!-- closed Projects -->
<rich:tab id="closedProjects">
<f:facet name="header">#{messages.adminInfo_table_type_close}
<h:outputText value="#{adminInformationBean.closedProjectsSize}"/>
</f:facet>
<div class="actionButtons">
<div class="ViewButtonLeft" />
<h:commandButton id="cku1405090011" styleClass="ViewSubmitButtonBody" value="#{messages['adminInfo_table_button_check']}" action="#{adminInformationBean.startClosingProjects()}" onclick="doPostBack();"/>
<div class="ViewButtonRight" />
</div>
<rich:dataTable id="closedProjectsTableId" styleClass="rich-datatable" value="#{adminInformationBean.infoListClosedProjects}" var="adminInfo" iterationStatusVar="iterator" rows="#{adminInformationBean.selectedItem}" rowKeyVar="row" rowClasses="ViewOddLine, ViewEvenLine">
<f:facet name="noData">#{messages.team_table_filter_message}</f:facet>
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<span>
<h:outputText value="#{messages.adminInfo_table_header_projectName} " />
</span>
</rich:column>
<rich:column>
<span>
<h:outputText value="#{messages.adminInfo_table_header_reason}" />
</span>
</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column filterValue="#{filterBean.projectNameFilter}" filterExpression="#{fn:containsIgnoreCase(adminInfo.projectName, filterBean.projectNameFilter)}">
<f:facet name="header">
<h:panelGroup>
<h:inputText id="projectNameClose" value="#{filterBean.projectNameFilter}">
<a4j:ajax render="closedProjectsTableId#body, tgrid2Id4#body" execute="#this" event="keyup" />
</h:inputText>
</h:panelGroup>
</f:facet>
<span>
<h:outputText value="#{adminInfo.projectName}" rendered="#{adminInfo.projectName != null}"/>
</span>
</rich:column>
<rich:column>
<div align="center">
<h:selectOneMenu class="selectReason" value="#{adminInfo.reason}">
<s:selectItems value="#{adminInformationBean.possibleReasons}" var="reason" label="#{reason.name}" itemValue="#{reason.id}" noSelectionLabel="" />
</h:selectOneMenu>
</div>
</rich:column>
</rich:dataTable>
<h:panelGrid id="tgrid2Id4" columns="3">
#{messages.team_table_rows_selectonemenu}
<h:selectOneMenu value="#{adminInformationBean.selectedItem}" onchange="submit()" valueChangeListener="#{adminInformationBean.pageSizeValueChanged}">
<f:selectItems value="#{adminInformationBean.selectItemsMap}"/>
</h:selectOneMenu>
<rich:dataScroller for="closedProjectsTableId" page="#{adminInformationBean.page}" maxPages="" fastControls="hide">
<f:facet name="first">
<h:outputText value="<<"/>
</f:facet>
<f:facet name="previous">
<h:outputText value="<"/>
</f:facet>
<f:facet name="next">
<h:outputText value=">"/>
</f:facet>
<f:facet name="last">
<h:outputText value=">>"/>
</f:facet>
</rich:dataScroller>
</h:panelGrid>
<div class="actionButtons" style="padding-bottom: 20px">
<div>
<div class="ViewButtonLeft" />
<h:commandButton id="cku1405090012" styleClass="ViewSubmitButtonBody" value="#{messages['adminInfo_table_button_check']}" action="#{adminInformationBean.startClosingProjects()}" onclick="doPostBack();"/>
<div class="ViewButtonRight" />
</div>
</div>
</rich:tab>
[...]
</rich:tabPanel>
</rich:panel>
</div>
</h:form>
</div>
</ui:define>
</ui:composition>

JSF : how to refresh current workspace programmatically

EDITED
I'm using <p:uploadfile> to upload a image into my project directory for my article, the upload is successful, but i can't view the image right away, but after refreshing my workspace it appers in my article.
UPLOAD methode:
public void upload(FileUploadEvent event) {
try {
new FileUpload().copyFile(event.getFile().getFileName(), event
.getFile().getInputstream());
} catch (IOException e) {
e.printStackTrace();
}
}
COPYFILE methode :
public void copyFile(String fileName, InputStream in) {
try {
OutputStream out = new FileOutputStream(new File(destination
+ fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
.XHTML: [EDITED PART]
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<style>
.topAligned {
vertical-align: top;
}
</style>
</h:head>
<h:body>
<p:tooltip />
<h:form id="form">
<p:growl id="notification" showDetail="true" />
<h:panelGrid columns="2" style="width:1220px;">
<h:outputText value="Nos Actualités :"
style="font-size: 30px;line-height: 40px;" />
<p:commandLink title="Ajouter" id="add" onclick="PF('dlg1').show();">
<h:graphicImage value="../img/add.png"
style="width:55px;height:55px;float:right;" />
</p:commandLink>
</h:panelGrid>
<div style="margin-left: 25px;">
<h:panelGrid columns="1">
<ui:repeat value="#{actualiteMBean.actualites}" var="actualite">
<h:outputText value="#{actualite.titreActualite}"
style="font-weight:bold;" />
<h:panelGrid columns="2" styleClass="topAligned"
style="display:block;" cellpadding="10">
<h:graphicImage value="#{actualite.imageActualite}"
style="width:150px; height:150px;" />
<h:panelGrid columns="1">
<div style="text-align: justify;">
<h:outputText value="#{actualite.descriptionActualite}" />
</div>
<h:panelGrid columns="2" style="float:right;">
<p:commandLink title="Modifier" id="modif"
actionListener="#{actualiteMBean.redirect(actualite)}">
<h:graphicImage value="../img/edit.png"
style="width:30px; height:30px;" />
</p:commandLink>
<p:commandLink title="Supprimer" update=":form" id="delete"
actionListener="#{actualiteMBean.delete(actualite)}">
<h:graphicImage value="../img/delete.jpg"
style="width:40px;height:33px;" />
<p:confirm header="Confirmation" message="etes vous sur?"
icon="ui-icon-alert" />
</p:commandLink>
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
<p:separator />
</ui:repeat>
</h:panelGrid>
</div>
</h:form>
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<p:commandButton value="Oui" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="Non" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
<p:dialog widgetVar="dlg1" modal="true" resizable="true"
appendTo="#(body)" showEffect="slide" hideEffect="slide"
header="Ajouter une Nouvelle Actualité" showHeader="true">
<h:form id="form1">
<p:wizard widgetVar="wiz" style="width:900px;height:500px;">
<p:tab id="titre" title="titre d'actualite">
<p:panel header="Titre d'actualite">
<h:panelGrid columns="3" cellspacing="10">
<p:outputLabel value=" Titre :" />
<p:inputText id="tit"
value="#{actualiteMBean.nouvelleActualite.titreActualite}"
required="true" requiredMessage="Champ Obligatoir" />
<p:message for="tit" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="image" title="image d'actualite">
<p:panel header="Image d'actualite">
<h:panelGrid columns="4" cellspacing="10">
<p:outputLabel value="Choisir Image :" />
<p:fileUpload id="up" multiple="true"
fileUploadListener="#{actualiteMBean.upload}"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
description="Select Images" required="true"
requiredMessage="Image Obligatoire" update=":form1:message" />
<p:message for="up" />
<p:message for="up" display="Chargement reussi" id="message" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="descrition" title="decsription d'actualite">
<p:panel header="Description d'actualite">
<h:panelGrid columnClasses="topAligned" columns="3"
cellspacing="10" style="margin:0 none;">
<p:outputLabel value=" Description :" />
<p:inputTextarea id="desc" cols="60" rows="10"
value="#{actualiteMBean.nouvelleActualite.descriptionActualite}"
required="true" requiredMessage="Champ Obligatoir" />
<p:message for="desc" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="validation" title="validation">
<p:panel header="Validation">
<h:outputText
value="#{actualiteMBean.nouvelleActualite.titreActualite}" />
<h:panelGrid columns="2">
<h:graphicImage style="width:150px;height:150px;"
value="#{actualiteMBean.nouvelleActualite.imageActualite}" />
<h:outputText
value="#{actualiteMBean.nouvelleActualite.descriptionActualite}" />
</h:panelGrid>
<h:panelGrid columns="2">
<p:commandButton value="Valider" update=":form :form1"
icon="ui-icon-check" action="#{actualiteMBean.save}"
oncomplete="PF('dlg1').hide();wiz.loadStep (wiz.cfg.steps [0], true)" />
<p:commandButton value="Annuler" icon="ui-icon-cancel"
action="#{actualiteMBean.cancel}"
oncomplete="PF('dlg1').hide();wiz.loadStep (wiz.cfg.steps [0], true)"
update=":form1" />
</h:panelGrid>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
</p:dialog>
</h:body>
</html>
Images of the problem:
after refreshing the project in eclipse and restarting tomcat :
what i want is the result above without refshing project manually every time, is there a way to do it programmatically??

checkbox selection datatable jsf2 primefaces

I use the datatable with checkbox selection feature, but when I click on footer button after selecting some rows, thoses rows don't be affected to my object selectedCommandes[], and the proof is that I added a row in the method that show me the lenght of selectedCommandes[] but it return 0, I don't know why,
I think all my codes are good
here is the datatable :
<p:dataTable id="cars" var="car" value="#{commandesUserController.mediumCommandesModel}" selection="#{commandesUserController.selectedCommandes}" tableStyle="width:auto">
<f:facet name="header">
Checkbox Based Selection
</f:facet>
<p:column selectionMode="multiple" style="width:18px" />
<p:column headerText="Model" style="width:100px">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year" style="width:100px">
<h:outputText value="#{car.dateEnvoi}" />
</p:column>
<p:column headerText="Manufacturer" style="width:100px">
<h:outputText value="#{car.dateLivraisonRecommande}" />
</p:column>
<p:column>
<p:commandLink ajax="false" value="Editer" action="updateUser_v1" >
<f:setPropertyActionListener value="#{car}" target="#{editUserController.u1}" />
</p:commandLink>
</p:column>
<p:column>
<p:commandLink value="Supprimer" oncomplete="confirmation.show()" >
<f:setPropertyActionListener value="#{car}" target="#{commandesUserController.selectedCommande}" />
</p:commandLink>
</p:column>
<p:column style="width:40px">
<p:commandButton id="selectButton" update=":myform:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{car}" target="#{commandesUserController.selectedCommande}" />
</p:commandButton>
</p:column>
<f:facet name="footer">
<p:commandButton id="supprion" value="supprimer selection" oncomplete="confirmation2.show()" />
</f:facet>
</p:dataTable>
and here is the button where there is the problem :
<f:facet name="footer">
<p:commandButton id="supprion" value="supprimer selection" oncomplete="confirmation2.show()" />
</f:facet>
and here is the dialog that appears when I click in the button above :
<p:confirmDialog id="confirmDialog2" message="etes vous sur de vouloir supprimer ces commande avec tous les données et fichiers correspondants !"
header="confirmation de suppression" severity="alert" widgetVar="confirmation2">
<p:commandButton id="confirm2" value="oui" update="cars" oncomplete="confirmation2.hide()"
action="#{commandesUserController.deleteCommandes()}" />
<p:commandButton id="decline2" value="non" onclick="confirmation2.hide()" type="button" />
</p:confirmDialog>
and here is the method in the managedBean :
public String deleteCommandes(){
System.out.println("je suis dans delete l ensemble avec tous = "+selectedCommandes.length);
for(int j = 0;j<selectedCommandes.length;j++){
selectedCommandes[j].setListFichiers(uh.getFichiersById(this.selectedCommandes[j].getId()));
for(int i = 0; i<selectedCommandes[j].getListFichiers().size();i++){
//System.out.println("alors "+selectedCommande.getListFichiers().get(i).getId());
uh.deleteFichier(selectedCommandes[j].getListFichiers().get(i));
}
uh.deleteCommande(selectedCommandes[j]);
}
return "commandesUser";
}
this line : System.out.println("je suis dans delete l ensemble avec tous = "+selectedCommandes.length); always return 0
I already created the class that implement SelectableDataModel
I hope I explained the problem
do you have any idea
thank you
Is there a h:form placed around the p:dataTable? If this is not the case this is probably the cause of your problem.
On PrimeFaces' showcase page the structure looks like this:
<h:form>
<p:dataTable>
<!-- content of data table -->
</p:dataTable>
<p:confirmDialog>
<!-- content of dialog -->
</p:confirmDialog>
</h:form>
Putting the p:dataTable and the p:confirmDialog in a separate form should work too I guess:
<h:form>
<p:dataTable>
<!-- content of data table -->
</p:dataTable>
</h:form>
<h:form>
<p:confirmDialog>
<!-- content of dialog -->
</p:confirmDialog>
</h:form>
You can set a breakpoint on the setter of selectedCommandes to check is this is called. (Don't worry is the setter is called multiple times, this is normal.)
as you told me, I tested with two form and in a separate page:
here is the new xhtml 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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<ui:composition template="./template_utilisateur.xhtml">
<ui:define name="tohead">
</ui:define>
<ui:define name="content">
Bienvenue #{userController.u1.nom} #{userController.u1.prenom}
<br></br><br></br><br></br>
<h:form id="form">
<p:dataTable id="cars" var="car" value="#{acceuilUserController.lc_maj}" tableStyle="width:auto" rowStyleClass="#{(car.lu == false) ? 'red' : null}" >
<p:column headerText="Commande N° : " style="width:100px">
<h:outputText value="#{car.commande.id}" />
</p:column>
<p:column headerText="Date de mise à jour : " style="width:100px">
<h:outputText value="#{car.dateMaj}" />
</p:column>
<p:column headerText="Decision : " style="width:100px">
<h:outputText value="#{car.decison}" />
</p:column>
<p:column headerText="Etat : " style="width:100px">
<h:outputText value="#{car.etat}" />
</p:column>
<p:column style="width:40px">
<p:commandButton id="selectButton" update=":form:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="plus de détails">
<f:setPropertyActionListener value="#{car}" target="#{acceuilUserController.selectedMajCommande}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Commande editée le #{acceuilUserController.selectedMajCommande.dateMaj} par l'#{acceuilUserController.selectedMajCommande.utilisateur.type} #{acceuilUserController.selectedMajCommande.utilisateur.nom} #{acceuilUserController.selectedMajCommande.utilisateur.prenom}" widgetVar="carDialog" resizable="false" id="carDlg"
showEffect="fade" hideEffect="explode" modal="true">
<f:ajax event="close" execute="#this" render="cars" listener="#{acceuilUserController.refreshDatatable()}"/>
<table id="gradient-style" >
<tr style="border: hidden;">
<th>
<h:outputLabel value="Model:" />
</th>
<td>
<h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.id}" />
</td>
</tr>
<tr style="border: hidden;">
<th>
<h:outputLabel value="Year:" />
</th>
<td>
<h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.etat}" />
</td>
</tr>
<tr style="border: hidden;">
<th>
<h:outputLabel value="Manufacturer:" />
</th>
<td>
<h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.dateEnvoi}" />
</td>
</tr>
<tr style="border: hidden;">
<th>
<h:outputLabel value="Color:" />
</th>
<td>
<h:outputLabel style="font-weight: bold;" value="#{acceuilUserController.selectedMajCommande.commande.dateLivraisonRecommande}" />
</td>
</tr>
</table>
<table id="gradient-style" >
<th>Nom Fichier</th><th>Taille</th><th>Télécharger</th>
<ui:repeat value="#{acceuilUserController.selectedMajCommande.commande.listFichiers}" var="jjjjj">
<tr>
<td>
<h:outputLabel style="font-weight: bold;" value="#{jjjjj.nom}" />
</td>
<td>
<h:outputLabel style="font-weight: bold;" value="#{jjjjj.taille}" />
</td>
<td>
<h:commandLink value="Télécharger">
<p:fileDownload value="#{jjjjj.convertFichier}" />
</h:commandLink>
</td>
</tr>
</ui:repeat>
</table>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
and here is the set method from selectedCommandes :
public void setSelectedCommandes(Commande[] selectedCommandes) {
System.out.println("je suis la dans son set tous : :"+selectedCommandes.length);
this.selectedCommandes = selectedCommandes;
}
I noticed that when I check one line the method above doesn't be run, it run only once when I click on :
<f:facet name="footer">
<p:commandButton id="supprion" value="supprimer selection" update=":form2:displayMulti" oncomplete="confirmation2.show()" />
</f:facet>
in footer to datatable, and it is written :
Infos: je suis la dans son set tous : :0
do you have any idea, thanks
add
<p:ajax event="cellEdit" listener="#{tableBean.onCellEdit}" update=":form:messages" />
under
<p:datatTable>

render a form from another form in a layoutUnit, not work, primefaces

I'm using primefaces 3.2, Mojarra JSF 2.1.3-FCS
Perform a basic example to prove that you can render a form from another form
<h:form id="one" rendered="#{test.enable}">
<p:panelGrid id="panelGrid" style="margin-top:10px">
<f:facet name="header">
<p:row>
<p:column colspan="2" style="font-size: 12px !important;
font-weight: bold;">data</p:column>
</p:row>
</f:facet>
</p:panelGrid>
</h:form>
<h:form id="two">
<p:commandButton value="change" update=":one" actionListener="#{test.see}"></p:commandButton>
</h:form>
After basic example, I try to do with primefaces, using the same idea in p: layoutUnit
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" id="top">
</p:layoutUnit>
<p:layoutUnit position="west" size="200" id="left">
<h:form id="nom">
<h:outputLabel id="nombre2" value="#{home.num}">
</h:outputLabel>
</h:form>
<h:form>
<p:commandButton value="cambia" update=":nom"
actionListener="#{home.ver}"></p:commandButton>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
</p:layoutUnit>
<p:layoutUnit size="50" position="south" id="bottom">
</p:layoutUnit>
</p:layout>
But not work... Any Idea