Linebreak/Textwrap in p:messages - primefaces

I have a p:messages Element in a Dialog. When the Message added by a Validator in this Element is too long, the Dialog gets wider, but stays in the same Position, which looks weird. Is there a way to get the Message to fit the dialog instead of the dialog changing size to fit the message?
The xhtml:
<p:dialog header="Benutzer erstellen / verwalten" id="userManageDialog"
widgetVar="userManageDialog"
modal="true"
showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="userData" rendered="#{not empty userDetailController.user}">
<!-- this is needed to be able to display validation messages from controller -->
<p:messages id="messages" closable="true">
<p:autoUpdate/>
</p:messages>
<div class="ui-fluid p-grid">
<div class="p-field p-col-12 p-md-12">
<p:outputLabel id="passwordLabel" for="password" value="Passwort: "/>
<p:password id="password" value="#{userDetailController.user.password}"
disabled="#{not userDetailController.newUser}" redisplay="true"
required="true"
requiredMessage="Bitte geben Sie ein Passwort ein."/>
</div>
</div>
</p:outputPanel>
</p:dialog>
The Validator:
public boolean isValid(String password) {
boolean valid = true;
if(StringUtils.isEmpty(password)) {
validationMsgs.add("Passwort ist leer!");
valid = false;
}
Matcher m = p.matcher(password);
if(!m.matches()) {
validationMsgs.add("Das Passwort muss zwischen 6 und 20 Zeichen lang sein und mindestens einen Buchstaben und eine Zahl enthalten!");
valid = false;
}
return valid;
}

Related

TomEE Plume 7 - JSF 2.2 navigation rules and redirects don't work - primefaces 6.1 + omnifaces 2.6.4

I have the following jsf login page:
<h:form id="frmAdmLogin" styleClass="form-horizontal">
<div class="ui-layout-center" style="margin-left: 15px;">
<p:messages id="messagesLogin" autoUpdate="true" closable="true" />
<h:panelGrid cellpadding="5">
<p:inputText id="txtUsuario" required="true" value="#{loginDataManager.usuario}" />
<p:password id="pssClave" required="true" value="#{loginDataManager.password}" />
<h:selectOneMenu id="lstSucursales" required="true" value="# {loginDataManager.idSucursal}">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{loginController.listadoCatalogos()}" var="sucursal" itemLabel="#{sucursal.nomCatalogo}" itemValue="#{sucursal.id}" />
</h:selectOneMenu>
<p:commandButton id="loginButton" value="Ingresar" action="#{loginController.login()}" />
</h:panelGrid>
</div>
<div id="barras">
<ui:include src="/templates/main/barras.xhtml" />
</div>
</h:form>
After user logs in the application, it should redirect to the main page. But It doesn't work.
For navigate I use the following navigation rules:
<navigation-rule>
<from-view-id>/login/login.xhtml</from-view-id>
<navigation-case>
<from-action>#{loginController.login()}</from-action>
<from-outcome>login</from-outcome>
<to-view-id>/login/login.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-action>#{loginController.login()}</from-action>
<from-outcome>exito</from-outcome>
<to-view-id>/login/main.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
I have a CDI bean which has the login method:
public String login() {
validarUsuario();
try {
obtenerMenu(sessionDataManagerBase.getUserDto());
return "exito";
} catch (Exception e) {
log.error("", e);
MessagesController.addError(null, "Error al consultar las opciones de menú para el usuario");
FacesContext.getCurrentInstance().validationFailed();
return "login";
}
}
Tomee starts with no errors, and when I click the login button nothing happens: no navigation, no errors in the browser and no errors in Tomee log.
There's something I'm missing in my configuration.
Thanks.

passing value from data table to dialog

I have a problem with passing data from dataTable witch is populated from database to dialog for editing values.
izmenaPredmeta.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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Obrada predmeta</title>
</h:head>
<h:body>
<center>
<h:form>
<p:growl id="msgs" showDetail="true"/>
<h:dataTable var="list" value="#{pred.getPredmets()}" border="1" cellpadding="3" cellspacing="3" bgcolor="lightgray">
<h:column>
<f:facet name="header">Naziv</f:facet>
<h:outputText value="#{list.naziv}"/>
</h:column>
<h:column>
<f:facet name="header">Akronim</f:facet>
<h:outputText value="#{list.akronim}"/>
</h:column>
<h:column>
<f:facet name="header">Semestar</f:facet>
<h:outputText value="#{list.semestar}"/>
</h:column>
<h:column>
<f:facet name="header">Godina</f:facet>
<h:outputText value="#{list.god}"/>
</h:column>
<h:column>
<f:facet name="header">Odsek</f:facet>
<h:outputText value="#{list.odsek}"/>
</h:column>
<h:column>
<f:facet name="header">Aktivan</f:facet>
<h:outputText value="#{list.drzise}"/>
</h:column>
<h:column>
<f:facet name="header">Edit</f:facet>
<h:commandButton value="Edit" action="#{pred.edit()}" onclick="PF('dlg3').show();">
<f:param name="idp" value="#{list.idpred}"/>
</h:commandButton>
<p:dialog header="Edit" widgetVar="dlg3" showEffect="explode" hideEffect="bounce" height="350">
<h:panelGrid id="panel" columns="2" cellpadding="5" border="1" bgcolor="gray">
<h:outputText value="Naziv"/>
<p:inputText style="width: 97%" value="#{pred.naziv}" required="true" requiredMessage="Naziv je obavezan"/>
<h:outputText value="Akronim"/>
<p:inputText style="width: 97%" value="#{pred.akronim}" required="true" requiredMessage="Akronim je obavezan"/>
<h:outputText value="Semestar"/>
<p:inputText style="width: 97%" value="#{pred.semestar}" required="true" requiredMessage="Semestar je obavezan"/>
<h:outputText value="Godina"/>
<p:inputText style="width: 97%" value="#{pred.god}" required="true" requiredMessage="Godina je obavezna"/>
<h:outputText value="Odsek"/>
<p:inputText style="width: 97%" value="#{pred.odsek}" required="true" requiredMessage="Odsek je obavezan"/>
<h:outputText value="Drzi se"/>
<p:inputText style="width: 97%" value="#{pred.drzise}" required="true" requiredMessage="Drzi se je obavezno"/>
<p:commandButton value="Save" action="#{pred.upPredmet()}" />
</h:panelGrid>
</p:dialog>
</h:column>
<h:column>
<f:facet name="header">Delete</f:facet>
<h:commandButton value="Delete" action="#{pred.delPredmet()}">
<f:param rendered="msgs" name="id" value="#{list.idpred}"/>
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
</center>
</h:body>
and function from PredmetBean.java #ViewScoped implements Serializable
// getter's, setter's and other functions
public void edit(){
ArrayList<Predmet> PrList = Predmet.getPredmets();
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
int id = Integer.parseInt(request.getParameter("idp"));
for(Predmet pr : PrList){
if( pr.getIdpred() == id ){
this.setIdPred(pr.getIdpred());
this.setNaziv(pr.getNaziv());
this.setAkronim(pr.getAkronim());
this.setSemestar(pr.getSemestar());
this.setGod(pr.getGod());
this.setOdsek(pr.getOdsek());
this.setDrzise(pr.getDrzise());
}
}
}
when clicked on edit button dialog should open with values from row in witch the button is click. But only thing i get is dialog try to open and break and then requiredMessages pops up all over.
When in dialog for value is list.somename dialog shows and populate the fileds with the last object value in list.
If someone have idea how to solve this or some other method for editing user values without going to other page it would be great.
Keep the p:dialog outside the form and use binding attribute in your dataTable show in below Example.
Declare the below line your managed bean
private HtmlDataTable dataTable;
Add the below line in your dataTable
binding="#{managedBean.htmlDataTable}"
Then your edit method would be like this
public void edit(){
Predmet selectedObject = (Predmet) getDataTable().getRowData();
}
Hope this can help you

Primefaces dialog fields not filled after click in CommandLink

I am using Primefaces 3.5 with Weblogic 11. I have a page where a dialog to edit a 'profile' entity ('perfil' in Portuguese) which is called from two places. First from a commandButton to insert a new profile. The second from a dataTable to edit a specific profile. Below, I show the code:
Snippet of XHTML page
<p:fieldset legend="Pesquisa de Perfil">
<p:panelGrid columns="2">
<f:facet name="footer">
<p:commandButton id="btnPesquisar"
actionListener="#{perfilAcessoMB.pesquisar}" value="Pesquisar"
immediate="true" update="pnlPerfis" styleClass="ui-icon-search" />
<p:spacer width="20"></p:spacer>
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(null)}"
oncomplete="dlgPerfil.show();">
</p:commandButton>
</f:facet>
</p:panelGrid>
</p:fieldset>
<br />
<p:outputPanel id="pnlPerfis" layout="block">
<p:fieldset id="resultadoPesquisa" legend="Resultado da Pesquisa"
rendered="#{not empty perfilAcessoMB.perfis}">
<p:dataTable id="tblPerfis" value="#{perfilAcessoMB.perfis}"
var="perfil" emptyMessage="Nenhum perfil encontrado.">
<p:column headerText="Nome do Perfil">
<h:outputText value="#{perfil.nome}"></h:outputText>
</p:column>
<p:column headerText="Descrição do Perfil">
<h:outputText value="#{perfil.descricao}"></h:outputText>
</p:column>
<p:column headerText="Situação do Perfil"
style="text-align: center; width: 100px;">
<h:outputText value="Ativo" rendered="#{perfil.situacao}" />
<h:outputText value="Inativo" rendered="#{not perfil.situacao}" />
</p:column>
<p:column headerText="Editar"
style="text-align: center; width: 50px;">
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="Editar" />
</p:commandLink>
</p:column>
<p:column headerText="Excluir"
style="text-align: center; width: 50px;">
</p:column>
</p:dataTable>
</p:fieldset>
</p:outputPanel>
<p:dialog id="dlgPerfil" widgetVar="dlgPerfil" resizable="false"
closable="true" modal="true" closeOnEscape="true"
header="#{(empty perfilAcessoMB.perfil)? 'Incluir': 'Editar'} Perfil">
<h:outputText value="#{perfilAcessoMB.perfil}"></h:outputText>
<h:panelGroup id="pnlPerfilEdicao" layout="block">
<p:fieldset legend="Dados do Perfil">
<p:panelGrid columns="2">
<h:outputLabel id="lblNomePerfilEdicao" value="Nome do Perfil"
for="txtNomePerfilEdicao" />
<p:inputText id="txtNomePerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Nome do Perfil."
value="#{perfilAcessoMB.perfil.nome}" maxlength="20" size="20"></p:inputText>
<h:outputLabel id="lblDescricaoPerfilEdicao"
value="Descrição do Perfil" for="txtDescricaoPerfilEdicao" />
<p:inputText id="txtDescricaoPerfilEdicao" required="true"
requiredMessage="É obrigatório preencher o campo Descrição do Perfil."
value="#{perfilAcessoMB.perfil.descricao}" maxlength="20"
size="20"></p:inputText>
<h:outputLabel id="lblSituacaoPerfilEdicao" value="Situação"
for="selSituacaoPerfilEdicao" />
<p:selectOneMenu id="selSituacaoPerfilEdicao"
value="#{perfilAcessoMB.perfil.situacao}">
<f:selectItems value="#{perfilAcessoMB.situacoesEdicao}" />
</p:selectOneMenu>
</p:panelGrid>
</p:fieldset>
<br />
<p:fieldset legend="Permissões">
<p:pickList id="pickFuncoes" value="#{perfilAcessoMB.funcoes}"
var="funcao" itemValue="#{funcao}"
itemLabel="#{funcao.descricao}" required="true"
requiredMessage="É obrigatório associar ao menos uma funcionalidade ao perfil."
converter="funcaoConverter" />
<p:column>#{funcao.descricao}</p:column>
</p:fieldset>
<p:panelGrid columns="2">
<p:commandButton id="btnSalvarPerfil" value="Salvar"
actionListener="#{perfilAcessoMB.salvar}"
oncomplete="if(args && !args.validationFailed) dlgPerfil.hide();" />
<p:commandButton id="btnCancelarPerfil" value="Cancelar"
immediate="true" onclick="dlgPerfil.hide();" />
</p:panelGrid>
</h:panelGroup>
</p:dialog>
MangedBean (perfilAcessoMB)
#ManagedBean
#ViewScoped
public class PerfilAcessoMB extends BaseMB {
private PerfilAcessoORM perfil;
private List<PerfilAcessoORM> perfis;
private String nomePerfil;
private Boolean situacao;
private DualListModel<FuncaoORM> funcoes;
private SelectItem[] situacoesPesquisa = new SelectItem[] {
new SelectItem(null, "Todos"), SELECT_ITEM_ATIVO,
SELECT_ITEM_INATIVO };
private SelectItem[] situacoesEdicao = new SelectItem[] {
SELECT_ITEM_ATIVO, SELECT_ITEM_INATIVO };
private FuncaoORM funcaoA = new FuncaoORM(1L, "FUNÇÃO A"), //
funcaoB = new FuncaoORM(2L, "B Function"), //
funcaoC = new FuncaoORM(10L, "Se Funssaum");
public void abrirDialogoEdicao(PerfilAcessoORM p) {
this.perfil = (p == null)? new PerfilAcessoORM(): p;
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
List<FuncaoORM> funcoesDisponiveis = new ArrayList<FuncaoORM>(
Arrays.asList(funcaoA, funcaoB, funcaoC));
// Remove from funcoesDisponiveis those whose are present in perfil.
if (this.perfil.getFuncoes() == null) {
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
Lists.<FuncaoORM> newArrayList());
} else {
funcoesDisponiveis.removeAll(this.perfil.getFuncoes());
this.funcoes = new DualListModel<FuncaoORM>(funcoesDisponiveis,
this.perfil.getFuncoes());
}
}
// Getters & Setters
}
PerfilAcessoORM (Profile) Entity
public class PerfilAcessoORM {
private Long id;
private String nome;
private String descricao;
private Boolean situacao = null;
private List<FuncaoORM> funcoes;
// Getters & Setters
}
FuncaoORM Entity:
public class FuncaoORM {
private Long id;
public String descricao;
// Getters & Setters
}
What is my problem? Apparently, when I want insert a new Profile, all seems OK. However, when I click to edit an existent profile to open the dialog, although the outputText and pickList are correctly filled, the inputText's and selectOneMenu are not.
Looking for solutions, I found here a suggestion to use appendToBody="true" in dialog. When I tried, the inputText's and selectOneMenu are correctly filled. However, the validation is not working as waited. When I click to save it is showed a message indicating that pickList is not filled, even if it is really filled. Actually, even if inputText's are not filled, there is no message about these inputTexts although they are required.
Another alternative would be use <f:setPropertyActionListener> inside commandLink:
<!-- OPEN DIALOG TO CREATE A NEW PROFILE -->
<p:commandButton id="btnIncluir" value="Incluir"
update="dlgPerfil" immediate="true"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{null}"/>
</p:commandButton>
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="Editar Perfil" update=":formPrincipal:dlgPerfil :formPrincipal:pnlPerfilEdicao"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao}"
oncomplete="dlgPerfil.show();">
<f:setPropertyActionListener target="#{perfilAcessoMB.perfil}" value="#{perfil}"/>
<h:outputText value="Editar" />
</p:commandLink>
The actionListener method would changed to:
public void abrirDialogoEdicao() {
if(this.perfil == null) {
this.perfil = new PerfilAcessoORM();
}
System.out.println("PerfilAcessoMB.onAbrirDialogoEdicao(): "
+ this.perfil);
// The rest remains the same ...
}
Now, when I click to create a new perfil, although in actionListener method the perfil attribute is filled, I got a NullPointerException when the dialog is renderized. It is like first is called perfilAcessoMB.setPerfil(), after the dialog is opened and finally actionListener method. On the other hand, if I click to edit an existent profile, I return to initial situation.
Therefore, I am lost, without idea how to solve this issue.
Thanks,
Rafael Afonso
The solution was incredible simple: just added process="#this" to both commandButtons.
<!-- OPEN DIALOG TO EDIT A NEW PROFILE -->
<p:commandLink id="lnkEditar" immediate="true"
title="#{msg['titulo.edicao']}" process="#this"
update=":formPrincipal:dlgPerfil"
actionListener="#{perfilAcessoMB.abrirDialogoEdicao(perfil)}"
oncomplete="dlgPerfil.show();">
<h:outputText value="#{msg['titulo.edicao']}" />
</p:commandLink>

Update form from dialog

I have a dataTable within a form; in the dataTable I have a button which pops up a dialog if clicked; after editing(or not) I want to close the dialog and refresh the datatable.
I want to to this through the ajax event "close", so even if the clicks on cancel button, or closes the dialog by clicking escape or the "x" in the bar -> he should land in my closeDialog()-method and refresh the dataTable.
The only issue is that i don't know how to refresh the dataTable.
Here is my dataTable(in the header is my button which pops up the dialog):
<p:dataTable id="nzTable" widgetVar="nzTableW" emptyMessage="Keine Todos gefunden"
var="currentTableItem" value="#{nichtZugTableController.dataModel}" paginator="true" rows="15"
rowsPerPageTemplate="5,10,15,20, 25, 30, 1000" lazy="false" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="( Treffer {totalRecords} ) ( Seite {currentPage} von {totalPages} )"
filteredValue="#{nichtZugTableController.filteredTodos}" filterDelay="500" filterEvent="keyup"
editable="true" sortBy="#{currentTableItem.angelegtAm}" sortOrder="descending"
rendered="#{loginBean.loggedIn and mitViewController.leiterViewActiv and leiterTreeController.nzTableActive}"
selection="#{nichtZugTableController.selectedNZTodos}" rowKey="#{currentTableItem.meldungId}"
resizableColumns="false" style="min-width:1200px !important; ">
<f:facet name="header">
<p:commandButton value="Zuordnen" id="nzAllTableOrdeZuButton" ajax="true" partialSubmit="true"
process="#this" label="ToDo einem Mitarbeiter zuordnen" oncomplete="zuordnenDialogW.show();"
disabled="#{not nichtZugTableController.hasSelectedNZTodos}"
action="#{nichtZugTableController.doToDoArrayToList()}" style="float: left;" />
<pe:tooltip for="nzAllTableOrdeZuButton" value="Ausgwählte ToDos einem Benutzer zuweisen"
myPosition="left center" atPosition="right center" showEffect="fadeIn" hideEffect="fadeOut"
showDelay="700" />
<h:outputText value="#{nichtZugTableController.tableHeaderName}"
style="color:#cf0008; font-size: 22px;" />
</f:facet>
...
</p:dataTable>
Here is my dialog:
<body>
<ui:composition>
<h:form id="zuordnenDialogForm">
<p:dialog id="zuordnenDialog" widgetVar="zuordnenDialogW" closeOnEscape="true" dynamic="true"
header="Zuordnung" appendToBody="false" draggable="true" modal="true" resizable="false">
<p:ajax event="close" listener="#{zuordnenDialogController.closeDialog()}" />
...
</p:dialog>
EDIT 1:
Here is a picture, maybe it helps
http://i.stack.imgur.com/pGjes.jpg
Did you try
<p:ajax event="close" listener="#{zuordnenDialogController.closeDialog()}" update=":nzTable"/>
update=":nzTable" with full path, may be: :form_main:nzTable
i want to comment, but i don't have enought reputation.
You can managed ajax event for each component inside dialog for example:
<p:dialog id="zuordnenDialog" widgetVar="zuordnenDialogW" closeOnEscape="true" dynamic="true"
header="Zuordnung" appendToBody="false" draggable="true" modal="true" resizable="false">
<p:selectOneMenu id="idp" value="#{...}" converter="clientesConverter" panelStyle="width:500px"
effect="fade" var="p" style="width:500px" filter="true" filterMatchMode="contains">
<f:selectItems value="#{comunMB.itemsClientes}"/>
<f:ajax execute="#this" listener="#{...}" render="table1 table2 table..." />
</p:selectOneMenu>
</p:dialog>
In this way change is showing in the table (or other component) while dialog is edited. Also you can use inplace component.

Primefaces Facesmessage disappears after hiding dialog

I have a page with a dialog like below. I want to show the user an error message in case the info already exists on the same dialog. This part works fine.
However, if all goes well the dialog should close AND the "success" message should show on the calling page (e.g. in the JSF template p:messages).
I can't get this to work, the message disappears. I tried several options including the remote command.
<p:dialog id="dialogNewMailingList" header="New Mailing List"
modal="true" resizable="false" widgetVar="dialogList">
<h:form id="newMailingListForm">
<p:messages id="listMessages" />
<h:panelGrid columns="2">
<h:outputLabel value="Name :" for="listName"
style="font-weight: bold;" />
<p:inputText id="listName"
value="#{mailingListsEditController.newMailingList.name}"
required="true" requiredMessage="Please fill in a Name" size="50" />
<h:outputLabel value="Description :" for="description"
style="font-weight: bold;" />
<p:inputText id="description"
value="#{mailingListsEditController.newMailingList.description}"
required="true" requiredMessage="Please fill in a Description"
size="50" maxlength="100" />
</h:panelGrid>
<br />
<p:remoteCommand name="updateMessages" update=":messages" />
<p:commandButton
action="#{mailingListsEditController.saveMailingList}"
update="#form,:mailinglists:selectMailingList"
oncomplete="listSaveRequest(xhr, status, args); updateMessages()"
value="Save" icon="ui-icon-disk" />
<p:commandButton onclick="dialogList.hide()" value="Cancel"
immediate="true" icon="ui-icon-cancel" />
</h:form>
</p:dialog>
<script type="text/javascript">
function listSaveRequest(xhr, status, args) {
if(args.validationFailed) {
jQuery('#dialogNewMailingList').effect("shake", { times:3 }, 100);
} else {
//alert('List created successfully.')
dialogList.hide();
}
}
</script>
The bean method save()
public void saveMailingList() {
log.debug("Saving new MailingList :" + newMailingList.getName());
emailService.save(newMailingList);
// show message to the user
FacesContext.getCurrentInstance().addMessage("Save Mailing List",
new FacesMessage("Mailing List successfully created."));
}
I feel I am close to the solution :)
Thanks for any help,
Coen
The p:messages element should be placed outside of the p:dialog. By closing the dialog all child elements get hidden, including the messages.