h:selectOneMenu default value issue when put it in h:dataTable - datatable

I have a problem with h:selectOneMenu.
If I put it in h:dataTable I'm unable to set the default value.
This is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<ui:component 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">
<h:dataTable value="#{utenteBean.listaUtenti}"
var="utente" >
<h:column>
<f:facet name="header">
<h:outputText value="#" />
</f:facet>
<h:outputText value="1"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{sW.headerUsername}" />
</f:facet>
<h:outputText escape="false"
value="#{utente.username}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{sW.headerEnabled}" />
</f:facet>
<h:form>
<h:commandLink action="#{utenteBean.updateAbilitato}">
<h:outputText value="#{utente.enabled}">
<f:converter converterId="abilitatoConverter"/>
</h:outputText>
<f:setPropertyActionListener target="#{utenteBean.utente}"
value="#{utente}"/>
</h:commandLink>
</h:form>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{sW.headerRuolo}" />
</f:facet>
<h:form>
<h:selectOneMenu value="ROLE_ADMIN"
valueChangeListener="#{utenteBean.updateRuolo}">
<f:selectItem itemLabel="Utente" itemValue="ROLE_USER"/>
<f:selectItem itemLabel="Admin" itemValue="ROLE_ADMIN"/>
</h:selectOneMenu>
</h:form>
</h:panelGroup>
</h:column>
</h:dataTable>
</ui:component>
If I move the h:form with selectOneMenu out of h:dataTable all works.
I'm using jsf2.0 on glassfish3
Any Ideas?

(Solved by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
I have solved it by myself, i think there is a bug in <h:selectOneMenu value="ROLE_ADMIN" i changed the value="" from static to dynamic with a reference to an istance in managed bean and all work perfectly.

Related

<p:ajax> for <h:selectBooleanCheckBox> not working

I am trying to call a method on the bean when the checkbox is selected/de-selected. When I select/deselect the checkbox inside the header it works fine and calls the method. But the second checkbox doesn't seem to work.
Below is my code (Note that this code is inside h:dataTable).
I am using
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
<h:column rendered="#{tableID.equals('approved-payments-table')}">
<f:facet name="header">
<h:selectBooleanCheckbox id="checkbox_select_all" value="false">
<p:ajax id="process_select_all"
process="checkbox_select_all"
actionListener="#{batchCreationHandler.selectAllCheckBoxListener()}"
event="click"/>
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="checkbox_ABCDEFG" value="#{false}">
<p:ajax id="processItemInvoice" process="checkbox_ABCDEFG"
partialSubmit="true"
listener="#{batchCreationHandler.selectAllCheckBoxListener()}"
event="click"/>
</h:selectBooleanCheckbox>
<f:facet name="footer">
 
</f:facet>
</h:column>

f:ajax doesn't render DataTable with a value choosen from selectOneMenu [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 4 years ago.
I'm trying to use a <f:selectOneMenu> to show a dataTable based on the previously chosen value. The DataTable doesn't be rendered, I tried also <f:ajax render="tabella"> or without the panelGroup or specifying event or excecute but it didn't works. I don't know how to solve it. Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://java.sun.com/jsf/core">
<ui:composition template="/template.xhtml">
<ui:define name="content">
<h:form id="form1">
<h:panelGroup id="pannello" >
<h:selectOneMenu id="marcaScelta" value="#{marcaController.marca}" >
<f:selectItem itemLabel="Scegli una marca"/>
<f:selectItems value="#{marcaController.listaMarche()}" var="m" itemLabel="#{m.nome}" itemValue="#{m.nome}">
</f:selectItems>
<f:ajax render="pannello form1" />
</h:selectOneMenu>
<h1 align="center"> Elenco prodotti #{marcaController.marca.nome} </h1>
<h:dataTable id="tabella" value="#{marcaController.marca.prodotti}" var="prodotto">
<h:column>
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{prodotto.nome}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Prezzo" />
</f:facet>
<h:outputText value="#{prodotto.prezzo}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Quantita" />
</f:facet>
<h:outputText value="#{prodotto.quantita}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Azioni" />
</f:facet>
<h:commandLink action="#{carrelloController.aggiungiAlCarrello(prodotto)}" value="Aggiungi al Carrello"></h:commandLink>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
</html>
I think that the listner is not added. So you can do:
Add a new method to marcaController, for example 'public void doChangeXX()'
Replace
< f:ajax render="pannello form1" />
With
<f:ajax listener="#{marcaController.doChangeXX}" render="pannello form1" />
Hope this help.

JSF Primefaces ajax on p:datatable

I am using JSF Primefaces for my UI. I have a specific requirement about ajax on p:datatable. This is a sample page of my project:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:comp="http://java.sun.com/jsf/composite/components/">
<ui:define name="content">
<h:form id="form1">
<p:growl id="messages" showDetail="false" />
<p:panel header="Available Rows" style="width: 15%;">
<p:dataTable id="table" value="#{rowBean.rows}" var="row"
widgetVar="50" style="width: 60px;" editable="true">
<p:ajax event="rowEdit" listener="#{rowBean.onEdit}"
update="form1:messages" />
<p:ajax event="rowEditCancel" listener="#{rowBean.onCancel}"
update=":form1:messages" />
<p:column>
<f:facet name="header">
<h:outputText value="Row ID" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.id}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.id}"
style="width:100%" label="Row ID">
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Row Value" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.value}" />
</f:facet>
<f:facet name="input">
<p:inputText disabled="true" value="#{row.value}"
style="width:100%" label="Row Value">
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:panel>
<p:spacer height="5px;"/>
<p:panel id="createPanel" header="Create Row" closable="false" toggleable="true"
collapsed="true" style="width: 15%;">
<p:panelGrid columns="6">
<h:outputLabel for="rowBean" value="Row ID" />
<p:inputText value="#{rowBean.row.id}"
required="true" label="Row ID" style="width:125px" />
<h:outputLabel for="rowBean" value="Row Value" />
<p:inputText value="#{rowBean.row.value}"
required="true" label="Row Value" style="width:125px" />
<f:facet name="footer">
<p:commandButton value="Create" action="#{rowBean.createRow}"
update=":form1" />
</f:facet>
</p:panelGrid>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
Here I have a data table which lists down all the rows created. Each row is having id and value. Value is editable. There is one more panel within the form which creates new rows. Backing bean is pre-populated with all the created rows with #PostConstruct. Backing bean is having other methods to edit, cancel and create. This page is working and given below is the new requirement.
In some cases there can be an error associated with each row. If there is an error attached with a row, then the value text needs to be updated like a link. While clicking on the link, the row ID and a parameter needs to be passed to backing bean. With these params, backing bean fetches the error details and passes it to the page. Then the error message needs to be shown on a pop-up.
Can you tell me how to do this?
On the XHTML side:
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
On the JAVA side, in the function you call when you press the button:
if(error) {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN, "Error",
"Your error message."));
}
PD: This is my first answer, i'm getting used to the post options, i'm sorry if you dont see my message properly ;)
Maybe like this?:
<f:facet name="output">
<h:outputText value="#{row.value}" rendered="#{!row.hasError}" />
<h:commandLink value="#{row.value}" rendered="#{row.hasError}" command="#{row.command(parameters..)}" />
</f:facet>

p:commandbutton update does not work

I have searched through forums and am aware of how id-generation of HTML-DOM-Elements work with NamingContainers and without them. Nonetheless, in this code i try to put a commandbutton in one side of the page, that should trigger an update of the other side of the page.
The 'viewWorkbenchButton' fires its action properly and the backend-data is fine. But :wbManageForm:wbMgmtPanel is not updated.
<ui:composition 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">
<f:view>
<p:panel id="dataGridPanel">
<p:panelGrid id="dataGridPanelGrid" styleClass="pGrid" columns="2"
columnClasses="alignTop, alignTop">
<p:column>
<h:form id="wbSelectForm">
<p:panel styleClass="noBorderPanel">
<p:dataTable var="workbench"
value="#{WorkbenchControllerBean.myWorkbenches}"
paginator="#{WorkbenchControllerBean.myWorkbenches.size() > 10}"
rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<f:facet name="header">
My Workbenches
</f:facet>
<p:column headerText="Id" sortBy="#{workbench.workbenchId}">
<h:outputText value="#{workbench.workbenchId}" />
</p:column>
<p:column headerText="Name" sortBy="#{workbench.name}">
<h:outputText value="#{workbench.name}" />
</p:column>
<p:column headerText="Actions">
<p:commandButton id="viewWorkbenchButton" icon="ui-icon-show"
title="View Workbench" update=":wbManageForm:wbMgmtPanel"
actionListener="#{WorkbenchControllerBean.viewWorkbench(workbench)}">
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</p:column>
<p:column>
<h:form id="wbManageForm">
<p:panel id="wbMgmtPanel" styleClass="noBorderPanel">
<h:outputText id="tabText" value="Active Wb: #{WorkbenchControllerBean.number}" />
<p:tabView id="tabView">
....
</p:tabView>
</p:panel>
</h:form>
</p:column>
</p:panelGrid>
</p:panel>
</f:view>
I already tried to update different components (:wbManageForm, :wbManageForm:tabText, :wbManageForm:tabView:treetable) but none of them was updated...
I am using Primefaces 3.5.
What am i missing here? Thanks a lot in advance!
Try using action instead of actionListener. Also, update only the wbmanageForm. If that doesn't work, try updating the component with your bean method.
You can do that by adding this to the end of your method: RequestContext.getCurrentInstance().update("wbManageForm");

Primefaces Button in Header

Is it possible to place a button inside of a header of a panel?
What I've read the following should work, but I haven't been able to get it to work.
<p:panel id="panel">
<f:facet name="header">
<p:commandButton value="Click"/>
</f:facet>
<p:panel>
Thanks to all who can help
Replace header to actions
<p:panel>
<f:facet name="actions">
<p:commandButton value="Click"/>
</f:facet>
<p:panel>
<h:form>
<p:panel id="panel">
<f:facet name="header">
<p:commandButton value="Click"/>
</f:facet>
</p:panel>
</h:form>
Try this, in header or footer...
<f:facet name="footer">
<p:commandButton value="Update Total" update="tabla_gral" styleClass="ui-priority-primary" id="ajax2" actionListener="#{consumoMaterial.actualizarSaldos}"/>
</f:facet>

Resources