Do you have any idea why this part of code isn't working:
View:
<a4j:commandButton value="#{labels.comments}"
action="#{reservation.displayComments}"
render="dataComments" />
<h:panelGroup id="dataComments" rendered="#{reservation.showComments}" >
...
<h:panelGroup/>
Bean:
public String displayComments(){
showComments = !showComments;
return "";
}
Click on the link simply do nothing.
Try something like this:
<a4j:commandButton value="#{labels.comments}"
action="#{reservation.displayComments}"
render="dataComments" />
<h:panelGroup id="dataComments">
<h:panelGroup id="innerPanel" rendered="#{reservation.showComments}" >
...
<h:panelGroup/>
<h:panelGroup/>
Always show your dataComments element, unless you will have nothing on the page to refresh.
Related
I use a p:overlayPanel on several places. It offers values from which the user can choose. This overlay panel is parameterized and used on several places. Therefore I show the panel with a click on a button like this:
<p:commandButton oncomplete="PF('overlayPanelVar').loadContents('#{component.clientId}');" immediate="true" actionListener="#{myController.setSelectedObject(curMaskElement, curDummyCssClass)}" process="#this" />
This works but only in one case I get a NullPointerException in JSF implementation mojarra this commandButton was created inside ui:repeat.
When the user clicks on the button it works and overlay panel appears, but if a value is chosen from the overlay panel (which is a link) this happens:
15:16:30,873 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] (http-/0.0.0.0:9090-5) null: java.lang.NullPointerException
at com.sun.faces.facelets.component.UIRepeat.restoreChildState(UIRepeat.java:433) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.component.UIRepeat.restoreChildState(UIRepeat.java:448) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.component.UIRepeat.restoreChildState(UIRepeat.java:415) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:546) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.facelets.component.UIRepeat.invokeOnComponent(UIRepeat.java:695) [jsf-impl-2.2.12.jar:2.2.12]
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:714) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:1503) [jsf-api-2.2.12.jar:2.2]
at javax.faces.component.UIComponentBase.invokeOnComponent(UIComponentBase.java:714) [jsf-api-2.2.12.jar:2.2]
at com.sun.faces.facelets.component.UIRepeat.invokeOnComponent(UIRepeat.java:697) [jsf-impl-2.2.12.jar:2.2.12]
The code in mojarra UIReapeat.class:
private void restoreChildState(FacesContext faces, UIComponent c) {
// reset id
String id = c.getId();
c.setId(id);
// hack
if (c instanceof EditableValueHolder) {
EditableValueHolder evh = (EditableValueHolder) c;
String clientId = c.getClientId(faces);
SavedState ss = this.getChildState().get(clientId);
if (ss != null) {
ss.apply(evh);
} else {
String childId = clientId.substring(initialClientId.length() + 1);
childId = childId.substring(childId.indexOf(getSeparatorChar(faces)) + 1);
childId = initialClientId + getSeparatorChar(faces) + childId;
if (initialChildState.containsKey(childId)) {
SavedState initialState = initialChildState.get(childId);
initialState.apply(evh);
} else {
NullState.apply(evh);
}
}
}
// continue hack
Iterator itr = c.getFacetsAndChildren();
while (itr.hasNext()) {
restoreChildState(faces, (UIComponent) itr.next());
}
}
The initialClientId member is null.
This appears with version 2.2.12.
If I change the JSF implementation of JBoss 6.2 to bundled which comes with JBoss this exception does not occur. The jars are jboss-jsf-api_2.1_spec-2.1.19.1.Final-redhat-1.jar and jsf-impl-2.1.19-redhat-2.jar.
In another usage of the overlay panel I create the commandButton inside a h:dataTable iteration and it works.
This is probably a mojarra bug?
The NPE occurs when the commandButton is created like this:
<p:panelGrid styleClass="searchMaskFieldsGrid">
<ui:repeat value="#{curSearch.getSearchMaskDescription().getRows()}" var="curRow" varStatus="rowStatus">
<p:row styleClass="searchMaskRow">
<ui:repeat value="#{curRow.elements}" var="curMaskElement" varStatus="colStatus">
<p:column colspan="#{curMaskElement.columnSpan}"
styleClass="#{curMaskElement.isLabel() ? 'searchMaskLabelColumn' : 'searchMaskInputColumn'}">
<!-- this includes one field and here can be the commandButton be added -->
<ui:include src="/sections/search/searchFields.xhtml">
<ui:param name="curMaskElement" value="#{curMaskElement}" />
<ui:param name="curRowIndex" value="#{rowStatus.index}" />
<ui:param name="curColumnIndex" value="#{colStatus.index}" />
</ui:include>
</p:column>
</ui:repeat>
<ui:param name="unfilledColumnsCount" value="#{searchBL.determinedUnfilledColumns(curSearch.getSearchMaskDescription(), curRow)}" />
<p:column colspan="#{unfilledColumnsCount}" rendered="#{unfilledColumnsCount gt 0}">
<h:outputLabel value="" />
</p:column>
</p:row>
</ui:repeat>
</p:panelGrid>
Is it maybe a known limitation with PF('overlayPanelVar').loadContents('#{component.clientId}'); and ui:repeat and someone knows a workaround?
I have a Primefaces dialog, and inside it there is a tabView. In this tabView I have 3 tabs, each one called towards ui:include. In the first tab I have a selectOneMenu which defines a property called tipoProprietario from class ProprietarioORM. The navigation between tab is done not by tabs themselves (in this stage they're disabled) but towards commandButtons at bottom of dialog. When I click in a commandButton to pass from the first to second tab tipoProprietario is filled correctly. However, when I click to pass from second do third tab (or even to the first one), I found that the selectItem value is changed to null. Consequently, the tipoProprietario property is also changed to null. Debugging, I saw that first it is called the Select Item listener method and after the tipoProprietario setter.
Can someone explain why this it is happening? How to correct it?
dialog.xhtml
<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:dialog id="dlgEdicao" widgetVar="dlgEdicao" resizable="false"
closable="true" modal="true" closeOnEscape="true"
header="#{(proprietarioMB.edicao)? msg['proprietario.titulo.editar']: msg['proprietario.titulo.incluir']}">
<p:tabView id="tabEdicao" widgetVar="tabEdicao" dynamic="true"
styleClass="tabEdicaoProprietario" cache="false"
binding="#{proprietarioMB.tabEdicao}">
<p:tab id="tabProprietario" title="#{msg['proprietario.titulo']}"
disabled="#{not proprietarioMB.edicao}" titleStyleClass="">
<ui:include src="./aba_proprietario.xhtml" />
</p:tab>
<p:tab id="tabEnderecoContato"
title="#{msg['proprietario.titulo.aba.endereco']}"
disabled="#{not proprietarioMB.edicao}">
<ui:include src="./aba_endereco_contato.xhtml" />
</p:tab>
<p:tab id="tabVeiculo"
title="#{msg['proprietario.titulo.aba.veiculo']}"
disabled="#{not proprietarioMB.edicao}">
<ui:include src="./aba_veiculo.xhtml" />
</p:tab>
</p:tabView>
<f:facet name="footer">
<p:commandButton id="btnDialogoAnterior"
value="#{msg['titulo.anterior']}"
rendered="#{not proprietarioMB.edicao}" immediate="true"
disabled="#{not proprietarioMB.btnAnteriorHabilitado}"
actionListener="#{proprietarioMB.doEventClickBtnAnterior}"
update="#this tabEdicao btnDialogoSeguinte btnDialogoConcluir"
style="margin-right: 20px;" />
<p:commandButton id="btnDialogoSeguinte"
value="#{msg['titulo.proximo']} #{(not proprietarioMB.btnConcluirVisivel)? '': 'display: none;'}"
rendered="#{not proprietarioMB.edicao}"
actionListener="#{proprietarioMB.doEventClickBtnSeguinte}"
update="#this tabEdicao btnDialogoAnterior btnDialogoConcluir"
style="margin-right: 20px; #{(not proprietarioMB.btnConcluirVisivel)? '': 'display: none;'}" />
</f:facet>
</p:dialog>
</ui:composition>
aba_proprietario.xhtml (the first tab)
<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:panel id="pnlDadosProprietario">
<p:focus for="selTipoEdicao" />
<p:fieldset id="fieldDadosProprietario"
legend="#{msg['proprietario.titulo']}"
rendered="#{not empty proprietarioMB.proprietario}">
<p:panelGrid id="pnlDadosProprietarioEdicao">
<p:row>
<p:column>
<p:outputLabel id="lblTipoEdicao"
value="#{msg['proprietario.titulo.tipo']}" for="selTipoEdicao" />
</p:column>
<p:column>
<p:selectOneMenu id="selTipoEdicao"
value="#{proprietarioMB.proprietario.tipoProprietario}"
valueChangeListener="#{proprietarioMB.doEventTipoDocumentoPesquisaChanged}"
immediate="true">
<f:selectItems value="#{proprietarioMB.tiposProprietarios}" />
<p:ajax event="change" update="txtDocumentoEdicao" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:outputLabel id="lblDocumentoEdicao"
value="#{msg['proprietario.titulo.documento']}"
for="txtDocumentoEdicao" />
</p:column>
<p:column>
<p:inputMask id="txtDocumentoEdicao"
value="#{proprietarioMB.proprietario.documento}"
mask="#{proprietarioMB.mascaraDocumento}" />
</p:column>
</p:row>
</p:panelGrid>
</p:fieldset>
</p:panel>
</ui:composition>
The Managed Bean
#ManagedBean
#ViewScoped
public class ProprietarioMB {
private static final String MASCARA_CPF = "999.999.999-99";
private static final String MASCARA_CNPJ = "99.999.999/9999-99";
private static final SelectItem[] tiposProprietarios = new SelectItem[] {
new SelectItem(JURIDICA, JURIDICA.getDescricao()),
new SelectItem(FISICA, FISICA.getDescricao()), };
private ProprietarioORM proprietario;
private String mascaraDocumento;
private TabView tabEdicao;
/**
* Select Item listener method: Changes inputMask mask
*/
public void doEventTipoDocumentoPesquisaChanged(ValueChangeEvent event) {
this.mascaraDocumento = (event.getNewValue() == FISICA) ? MASCARA_CPF
: MASCARA_CNPJ;
}
public void doEventClickBtnAnterior() {
System.out.println("ProprietarioMB.doEventClickBtnAnterior(): "
+ this.tabEdicao.getActiveIndex());
this.tabEdicao.setActiveIndex(this.tabEdicao.getActiveIndex() - 1);
}
public void doEventClickBtnSeguinte() {
System.out.println("ProprietarioMB.doEventClickBtnSeguinte(): "
+ this.tabEdicao.getActiveIndex());
System.out.println("ProprietarioMB.doEventClickBtnSeguinte(): "
+ this.proprietario);
if (this.tabEdicao.getActiveIndex() == 0) {
if (this.validarProprietario()) { // Validation method
this.tabEdicao.setActiveIndex(1);
}
} else if (this.tabEdicao.getActiveIndex() == 1) {
this.tabEdicao.setActiveIndex(2);
}
}
// Other methods + getters & setters
}
ProprietarioORM
public class ProprietarioORM {
private String nome;
private TipoProprietarioEnum tipoProprietario;
// getters & setters
}
It's most likely because of the binding="#{proprietarioMB.tabEdicao}"
For one thing, you don't appear to need the binding at all. Even if you did, you failed to initialize the component in your backing bean, a bug that'll result in the <p:tabView/> attempting to bind to a null variable tabEdicao.
As you don't appear to be using the tabview variable in the backing bean, my recommendation would be to get rid of it. If you really need it, just initialize it:
private TabView tabEdicao = new TabView();
Kolossus:
This issue was resolved when I added the attibute dynamic="true" to dialog. Actually, the real value was dynamic=#{empty proprietarioMB.proprietario}, because I was geting NullPointerException when loading the page. proprietario property is loaded towards #PostConstruct method.
I am trying to replicate primefaces ajax dialog form as in Primefaces showcase
My JSF code snippet is as below
<h:body>
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="PF('dlg').show()" />
<p:dialog header="Enter FirstName" widgetVar="dlg" appendToBody="true"
resizable="false">
<h:form id="form">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstName" value="firstName:" />
<p:inputText id="firstName" value="#{backingBean.firstName}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" update=":display"
oncomplete="PF('dlg').hide();" />
</h:form>
</p:dialog>
<p:outputPanel id="display" style="display:block;margin-top:10px;">
<h:outputText id="name" value="Hello #{backingBean.firstName}"
rendered="#{not empty backingBean.firstName}" />
</p:outputPanel>
My managed bean
#ManagedBean
#ViewScoped
public class BackingBean implements Serializable{
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
No dialog is getting displayed on clicking submit button :(. I have also included appendToBody="true" but no result.In ie i get javascript error as "Object Expected". Please help me out to solve this issue.
which version of primefaces you use ?
If you use Primefaces 3.5 or older:
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="dlg.show()" />
For Primefaces 4.0 :
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="PF('dlg').show()" />
In my case I had a script link to jquery in header. I droped it and primefaces started to work correctly
I have a Prime Faces p:dialog that has been resized while new components are inserted when opened ('show' state). However its position doesn't change and it's size is increasing from the down left corner until the page bottom.
I need to reposition it every time I render new components dynamically. Is there any JavaScript function I can call to its widget to reposition?
I'm using PrimeFaces 3.5 with Mojarra 2.1.13.
I had a similar situation with a TabView inside a dialog. The TabView content was dynamically loaded.
<p:dialog widgetVar="dialogWidgetVar">
<p:tabView value="#{tabBean.tabs}" var="tabsVar"
onTabShow="PF('dialogWidgetVar').initPosition();" dynamic="true">
<p:tab id="Tab#{tabsVar.id}" title="#{tabsVar.name}">
...
</p:tab>
</p:tabView>
</p:dialog>
As you can see it will call the function initPosition() with every change of a Tab. This function will reposition your dialog. You can use this function in several cases.
http://forum.primefaces.org/viewtopic.php?f=3&t=16893
This is a method that should work in your case :
Bean code :
#ManagedBean
#ViewScoped
public class Bean
{
private boolean visible;
public void setVisible(boolean visible)
{
this.visible = visible;
}
public boolean getVisible()
{
return this.visible;
}
public void onBeforeShowDialog(AjaxBehaviorEvent event)
{
visible = true;
}
public void onBeforeHideDialog(AjaxBehaviorEvent event)
{
visible = false;
}
}
View code :
<h:commandButton value="Show dialog">
<f:ajax listener="#{bean.onBeforeShowDialog}" render="dialog" />
</h:commandButton>
<p:dialog id="dialog" visible="#{bean.visible}">
content
<h:commandButton value="Hide dialog">
<f:ajax listener="#{bean.onBeforeHideDialog}" render="dialog" />
</h:commandButton>
</p:dialog>
A second method should also work is by JavaScript :
To add in <h:head /> :
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<script>
function centerAndShowDialog(dialog)
{
$(dialog).css("top",Math.max(0,(($(window).height() - $(dialog).outerHeight()) / 2) + $(window).scrollTop()) + "px");
$(dialog).css("left",Math.max(0, (($(window).width() - $(dialog).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
dialog.show();
}
</script>
View code :
<p:commandButton id="basic" value="Show Dialog" onclick="centerAndShowDialog(dlg);" type="button" />
<p:dialog id="dialog" header="Dynamic Dialog" widgetVar="dlg" dynamic="true">
Content
</p:dialog>
Note : Since I'm not using PrimeFaces, I've not tested this code so I hope it work well, but the idea is here!
Is it possible to update view parameter without redirecting the page? For instance
I have a managed bean which checks if an ID exist
public void signIn(){
Client c = clientFacade.loginDetail(client.getID());
if (c != null) {
loggedIn = true;
}
else{
loggedIn = false;
}
}
and a view which renders just fine if the ID exist.
<h:panelGroup rendered="#{not applicationManager.loggedIn}">
<p:commandLink value="Sign In" onclick="loginDialog.show()" styleClass="login-link"></p:commandLink>
</h:panelGroup>
<h:panelGroup rendered="#{applicationManager.loggedIn}">
<p:menuButton value="#{applicationManager.client.firstname}" />
</h:panelGroup>
<p:dialog widgetVar="loginDialog" >
<h:panelGrid columns="2" cellpadding="5">
ID : <p:inputText value="#{applicationManager.client.id}" />
<p:commandButton value="submit" action="#{applicationManager.signIn()}" update=":loginForm" />
</h:panelGrid>
</p:dialog>
Is it possible to insert the code below at the top of the view and still have an update on the url?
<f:metadata>
<f:viewParam name="input" value="#{applicationManager.client.id}" />
<f:event listener="#{applicationManager.signIn()}" type="preRenderView"/>
</f:metadata>
I tried it, but it's not working, so I guess I might be missing something or doing something wrong.