I would like to have some help on the following problem and right now I am very grateful for the help and attention.
I have a form in JSF 2 / Primefaces 5.1 where a component updates another component in selection, both components are required.
My problem occurs after validation, is after I fill one of the fields, when this happens the component automatically populates the other field, however the validation style continues in the second component.
Please see the SS, for better better understanding:
Before the submit:
Stopping the fields required
Filling of the fields and re submit:
How can I change this behavior and make the style stay right in the second field, I've tried many ways and I am out of ideas, everything else works perfectly except the validation css
My Code:
<h:form id="stepInsertFormId" acceptcharset="UTF-8">
<p:panelGrid id="stepInsertPanelId" styleClass="formPanelGridPage" cellpadding="7" >
<p:row>
<p:column styleClass="adrGridLabel">
<p:outputLabel for="stageCodeInsertSelectId"
value="#{myMsg['common.stage']}"
title="#{myMsg['common.stage.title']}"
styleClass="myGridLabel" />
</p:column>
<p:column styleClass="adrGridInput" style="vertical-align: bottom;">
<p:selectOneMenu id="stageCodeInsertSelectId"
value="#{Step.stepInsert.selectedStage}"
var="stage"
converter="basedEntityConverter"
label="#{myMsg['common.stageCode.title']}"
filter="true"
required="true"
filterMatchMode="startsWith" >
<f:selectItem itemLabel="#{myMsg['common.select']}" itemValue="" />
<f:selectItems value="#{Step.stages}"
var="stageInsert"
itemLabel="#{stageInsert.id.stageCode}"
itemValue="#{stageInsert}" />
<p:column>
<h:outputText value="#{stage.id.stageCode}" />
</p:column>
<p:column>
<h:outputText value="#{stage.description}" />
</p:column>
<p:ajax event="change" process="#this"
update="stepInsertPanelId, :myMessagesId"
listener="#{Step.doReloadStepsInsert}" />
</p:selectOneMenu>
<p:spacer width="5px" height="1px"/>
<p:selectOneMenu id="stageDescriptionInsertSelectId"
value="#{Step.stepInsert.selectedStage}"
var="stage"
converter="basedEntityConverter"
filter="true"
required="true"
filterMatchMode="startsWith"
style="width:260px"
label="#{myMsg['common.stageDescription.title']}">
<f:selectItem itemLabel="#{myMsg['common.select']}" itemValue="" />
<f:selectItems value="#{Step.stages}"
var="stageInsert"
itemLabel="#{stageInsert.description}"
itemValue="#{stageInsert}" />
<p:column>
<h:outputText value="#{stage.id.stageCode}" />
</p:column>
<p:column>
<h:outputText value="#{stage.description}" />
</p:column>
<p:ajax event="change" process="#this"
update="stepInsertPanelId"
listener="#{Step.doReloadStepsInsert}" />
</p:selectOneMenu>
</p:column>
The problem is related to the life cycle of the update phase, the moment the ajax will upgrade the second field it loses the reference of ids, this behavior is already provided and there is a tag resetValue Primefaces, to work around this behavior:
this the final solution:
<p:ajax event="change" process="#this"
update="stageCodeInsertLabelId, stageCodeInsertSelectId
, stageDescriptionInsertSelectId
, :myMessagesId"
resetValues="true"
listener="#{Step.doReloadStepsInsert}" />
The default value is false.
This post helped me to understand and solve this problem behavior
How can I populate a text field using PrimeFaces AJAX after validation errors occur?
Related
Versions :
Aapche MyFaces 2.1.14
RichFaces 4.3.5
Issue :
I am facing an issue to insert space between rows of h:panelGid. Below is the general layout for the page :
User Id : <empty space>
<INPUT-BOX> <empty space>
<!-- space here -->
Password 1 : <empty space>
<INPUT-BOX> Description Text
<!-- space here -->
Password 2 : <empty space>
<INPUT-BOX> Description Text
To get above layout , i have used below code. Each inner panel grid holds 4 elements in two columns.
Top panel grid wraps all inner panel grids with column as 1.
The issue is , I am not able to get space betwen two inner panel grids or more specifically between table cells.
I have tried using :
1)cellspacing
2)rowClasses
But none of the two approches are working. The style used for rowClasses is given below.
When debugged through browser , it seems that rowClasses does get applied to each <tr> of table.
Can anybody please help ?
Code :
<h:panelGrid columns="1" rowClasses="tableCell,tableCell,tableCell,tableCell" cellspacing="100px">
<h:panelGrid columns="2">
<h:outputText value="User ID:" styleClass="label"/>
<h:outputText value=""/>
<h:inputText id="userid" name="userid" styleClass="input"/>
<h:outputText value=""/>
</h:panelGrid>
<!-- space here -->
<h:panelGrid columns="2">
<h:outputText value="Password1:" styleClass="label"/>
<h:outputText value=""/>
<h:inputText id="passwd1" name="passwd1" styleClass="input"/>
<h:outputText value="This is password 1"/>
</h:panelGrid>
<!-- space here -->
<h:panelGrid columns="2">
<h:outputText value="Password2:"/>
<h:outputText value=""/>
<h:inputText id="passwd2" name="passwd2" styleClass="input"/>
<h:outputText value="This is password 2 ."/>
</h:panelGrid>
<!-- space here -->
<h:commandButton id="submit" styleClass="button" value="Submit" action="#{bean.action}"/>
</h:panelGrid>
<!-- style -->
.tableCell{
margin-top : 100px;
}
In our web project we use JSF Myfaces, Primefaces 3.5. We have created our own primefaces theme for the project.
I find the following odd problems, which I suspect are due the css/library etc,
Multiple selection checkbox on p:dataTable works on odd tries. I.e on the first load of the page the selection works. If I visit one other page and comeback, the select check box doesn't work. If I visit one more page and comeback it works again. When it doesn't work, if I do a page reload from browser it works again. (the problem is the same in all browsers)
p:ajaxStatus onstart js function fires only for the first ajax call. For all subsequent calls this event is not fired. If I reload the page it again fires for the first ajax call and stops. We have not set any global setting on any ajax calls, I presume all calls default to global = true (the problem is the same in all browsers)
for a p:barChart on chrome, the x and y-axis labels fall in to the axis, but when I reload the page the display is adjusted and correct (as it appears in firefox), and no further reload is need during the session, even when navigate back and forth from other pages.
Our application has a menu area on the top and ouputPanel that is updated using ui:include based on the ajax menu selection.
I am not sure what could be causing these issues, and why things seem to work fine on reload. Where could the problem be?
The view code for the first issue related to the multiple selection checkbox is below.
<?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">
<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"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
</h:head>
<h:body>
<h:form id="dataForm">
<p:messages id="tableMsgs" />
<h:panelGroup>
<p:dataTable value="#{usersBean.userDataModel}" var="user"
id="userDataModel" rows="20" paginator="true"
paginatorAlwaysVisible="false" editable="true"
selection="#{usersBean.selectedUsers}"
resizableColumns="false">
<f:facet name="header">
<p:commandButton value="Flag User" process="#form"
action="#{usersBean.flagUser}"
icon="ui-icon-custom-arrow" iconPos="right"
update=":dataForm:tableMsgs"></p:commandButton>
<p:spacer width="10"></p:spacer>
<p:commandButton value="Delete User" process="#form"
icon="ui-icon-custom-arrow" iconPos="right" update="#form"
action="#{usersBean.deleteUser}">
</p:commandButton>
</f:facet>
<p:ajax event="rowEdit" listener="#{usersBean.onEdit}"
oncomplete="resetCSS()"
update=":dataForm:tableMsgs />
<p:ajax event="rowEditCancel" oncomplete="resetCSS()" />
<p:column selectionMode="multiple" style="width:15px;" />
<p:column headerText="Department" sortBy="#{user.dept.name}"
style="white-space:pre-line;width:100px">
<h:outputText value="#{user.dept.name}"
style="white-space:pre-line;width:100px;display:block;">
</h:outputText>
</p:column>
<p:column headerText="UserName" sortBy="#{user.userLoginName}"
style="width:100px;">
<h:outputText value="#{user.userLoginName}"
style="width:100px;display:block;"></h:outputText>
</p:column>
<p:column headerText="Role" sortBy="#{user.role}"
style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.role}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{user.role}" style="width:95px" rendered="#{user.enabled eq true}" >
<f:selectItems
value="#{usersBean.rolesMap[user.dept.deptId]}"
var="role" itemLabel="#{role}" itemValue="#{role}"></f:selectItems>
</p:selectOneMenu>
<h:outputText value="#{user.role}" rendered="#{user.enabled eq false}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Manager" style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText
value="#{user.usermanagerByUserId.userByManagerId.userLoginName}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectOneMenu rendered="#{user.enabled eq true}"
value="#{usersBean.managerIdMap[user.userId]}"
style="width:95px;">
<f:selectItems
value="#{usersBean.managerMap[user.dept.deptId]}"
var="manager" itemLabel="#{manager.userLoginName}"
itemValue="#{manager.userId}"></f:selectItems>
</p:selectOneMenu>
<h:outputText
value="#{user.usermanagerByUserId.userByManagerId.userLoginName}" rendered="#{user.enabled eq false}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email" style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.email}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.email}" style="width:95px;"
validatorMessage="Enter Valid Email" maxlength="100">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Last Login" style="width:60px;">
<h:outputText value="#{user.lastLogin}"
style="width:60px;display:block;">
<f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime>
</h:outputText>
</p:column>
<p:column headerText="Status" style="width:40px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="Enable" rendered="#{user.enabled eq true}"></h:outputText>
<h:outputText value="Disable"
rendered="#{user.enabled eq false}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{user.enabled}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Locked" style="width:40px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="Locked" rendered="#{user.locked eq true}"
style="width:40px;display:block;" />
<h:outputText value="UnLocked" style="width:40px;display:block;"
rendered="#{user.locked eq false}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{user.locked}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:30px;">
<p:rowEditor>
</p:rowEditor>
</p:column>
</p:dataTable>
</h:panelGroup>
</h:form>
</div>
I have ajax functionality to add names and show on the same page in a table manner with one image(on left of text) and one "X" image(on right to delete). It should be added like, from left to right and after completing one row, it should start from next row.
So I need to show an arraylist of string in p:datagrid or any other tag which can be used with same functionality.
I tried with combination of ui:repeat and p:panelgrid but I was unable to get datagrid funtionallty. I did not used p:dataTable because it would add new element on bottom side not as I need.
P.S.
<h:form>
<h:selectOneMenu id="recepients" value="#{controller.selected}">
<f:selectItem itemLabel="Select" itemValue=""></f:selectItem>
<f:selectItem itemLabel="Info1" itemValue="Info1"></f:selectItem>
<f:selectItem itemLabel="Info2" itemValue="Info2"></f:selectItem>
<f:selectItem itemLabel="Info3" itemValue="Info3"></f:selectItem>
<f:selectItem itemLabel="Info4" itemValue="Info4"></f:selectItem>
<f:selectItem itemLabel="Info5" itemValue="Info5"></f:selectItem>
</h:selectOneMenu>
<p:commandButton value="Add" action="#{controller.submit}"
update="nameslist" />
<p:dataGrid id="nameslist" value="#{controller.tempNameList}"
var="name" columns="3">
<p:column>
<p:outputLabel value="%" />
</p:column>
<p:column>
<p:outputLabel value="#{name}" />
</p:column>
<p:column>
<p:commandLink value="X" action="#{controller.delete(name)}"
update="nameslist">
</p:commandLink>
</p:column>
</p:dataGrid>
</h:form>
The result should be like this...
% Abc X
% Xyz X
% dfd X
plz consider % as image and X as close symbol
The <p:dataGrid> doesn't support <p:column>. This column layout is only applicable to <p:dataTable>.
Replace all those <p:column> by a single grouping component, e.g. <h:panelGroup> or maybe <p:panel>, exactly as shown on showcase site.
<p:dataGrid id="nameslist" value="#{controller.tempNameList}" var="name" columns="3">
<h:panelGroup>
<p:outputLabel value="%" />
<p:outputLabel value="#{name}" />
<p:commandLink value="X" action="#{controller.delete(name)}" update="nameslist" />
</h:panelGroup>
</p:dataGrid>
Q: What syntax should i use to exclude a component when submitting a form using primefaces?
Using the process attribute i know how to include components.
<h:inputText id="included"/>
<p:commandButton value="button" process="included" actionListener="#{myBean.doStuff}/>
I've been trying to play around with syntax similiar to what is used in the answer here: How to exclude child component in ajax update of a parent component? but cant get it to work
<h:inputText id="notIncluded" styleClass="notIncluded"/>
<p:commandButton ... process="#(form :not(.notIncluded))"/>
Edit (doing the homework and adding an actual working example):
On glassfish 3.1.2.2 and primefaces 3.4.2
When i looked further, the exclusion works fine inside h:panelGrid
<h:form id="aForm">
<h:panelGrid columns="2">
<p:inputText id="inc" styleClass="included" required="true" />
<p:message for="inc" />
<p:inputText id="notInc" styleClass="notIncluded" required="true" />
<p:message for="notInc" />
<p:commandButton value="submit" process="#(form :not(.notIncluded))"
update=":aForm" />
</h:panelGrid>
</h:form>
But is no longer excluded inside a similar p:panelGrid
<h:form id="aForm">
<p:panelGrid columns="2">
<p:inputText id="inc" styleClass="included" required="true" />
<p:message for="inc" />
<p:inputText id="notInc" styleClass="notIncluded" required="true" />
<p:message for="notInc" />
<p:commandButton value="submit" process="#(form :not(.notIncluded))"
update=":aForm" />
</p:panelGrid>
</h:form>
I have checked your examples, if you review page source your will notice that p:panelGrid creates table with id. Little bit strange but jQuery selector doesnt access childs when table has an id. If I remove table Id then button works fine. So my solution was giving an id to panelGrid and using this id in selector. p:panelGrid will give same id to table but you need to make sure you add prependId="false" attribute into your h:form:
<h:form id="aForm" prependId="false">
<p:panelGrid columns="2" id="myGrid">
<p:inputText id="inc" styleClass="included" required="true" />
<p:message for="inc" />
<p:inputText id="notInc" styleClass="notIncluded" required="true" />
<p:message for="notInc" />
<p:commandButton value="submit" process="#(#myGrid :not(.notIncluded))"
update=":aForm" />
</p:panelGrid>
</h:form>
I need to make a simple align using p:outputLabel and p:selectOneMenu like this basic example
But, it's just working when I using p:inputText.
I need something like this:
<p:panelGrid columns="2">
<h:outputLabel for="idName" value="* #{msg.select_name}: " required="true" />
<p:selectOneMenu id="idSName" value="#{manage.name}">
<f:selectItems value="#{manage.listNames}" />
</p:selectOneMenu>
<h:outputLabel for="idCountry" value="#{msg.select_country}: " required="true" />
<p:selectOneMenu id="idCountryCustomer" value="#{manage.countrySelected}">
<f:selectItems value="#{manage.listCountryCustomer}" />
</p:selectOneMenu>
</p:panelGrid>
On p:selectOneMenu you should apply vertical-align:middle:
<p:selectOneMenu id="idSName" value="#{manage.name}" style="vertical-align:middle;">
<f:selectItems value="#{manage.listNames}" />
</p:selectOneMenu>
You used for="idName" in your <h:outputLabel>, however the id of <p:selectOneMenu> is "idSName". The names have to match.
You may also try <p:outputLabel> instead of <h:outputLabel>.