I can't set value into policyCriteria. When I click the Search commandButton, the value in <p:inputText> doesn't set to the poliyCriteria.
I already tried with process="#this" , gave commandButton ajax="false".
Here's my XHTML code.
<table width="100%">
<tr>
<td colspan="3">
<h:outputText styleClass="table-title" value="Life Policy Endorsement Management" />
<p:separator style="height:5px" />
</td>
</tr>
<tr>
<td>
<h:outputText value="" />
</td>
<td>
<p:message for="selectPolicyCriteria" id="lifePolicyMsgSelect" />
</td>
<td>
<p:message for="policyCriteria" id="lifePolicyMsg" />
</td>
</tr>
<tr>
<td style="font-weight: bold;" width="130px;">
<h:outputText value="Select Policy Number: " />
</td>
<td width="120px;">
<p:selectOneMenu converter="omnifaces.SelectItemsIndexConverter" id="selectPolicyCriteria" value="#{LifePolicyEndorsementActionBean.policyCriteria.policyCriteria}">
<f:selectItem itemLabel="Select Criteria" />
<f:selectItems value="#{LifePolicyEndorsementActionBean.policyCriteria.policyCriteriaItemList}" />
</p:selectOneMenu>
</td>
<td>
<p:inputText id="policyCriteria" style="height:20px;width: 200px;" value="#{MotorPolicyEndorsementActionBean.policyCriteria.criteriaValue}" />
</td>
</tr>
<tr>
<td colspan="2">
<h:panelGrid cellpadding="5" columns="2">
<p:commandButton action="#{LifePolicyEndorsementActionBean.search()}" id="searchBtn" update="lifePolicyTablePanel lifePolicyMsg lifePolicyMsgSelect" value="Search"/>
<p:commandButton action="#{LifePolicyEndorsementActionBean.reset()}" id="resetBtn" update="LifePolicyEndorsementForm" value="Reset"/>
</h:panelGrid>
</td>
</tr>
</table>
Here's backingBean
public void search() {
if (inputCheck(policyCriteria)) {
lifePolicyList = lifePolicyService.findLifePolicyByPolicyCriteria(policyCriteria, 30);
}
}
public void reset() {
policyCriteria.setCriteriaValue(null);
policyCriteria.setPolicyCriteria(null);
lifePolicyList.clear();
}
private boolean inputCheck(PolicyCriteria policyCriteria) {
boolean result = true;
String formId = "LifePolicyEndorsementForm";
if ((policyCriteria.getPolicyCriteria() == null) || (policyCriteria.getPolicyCriteria().toString().equals("Select"))) {
addErrorMessage(formId + ":selectPolicyCriteria", MessageId.PLEASE_SELECT_POLICY_CRITERIA);
result = false;
}
if (StringUtils.isBlank(policyCriteria.getCriteriaValue())) {
addErrorMessage(formId + ":policyCriteria", MessageId.CRITERIA_VALUE_REQUIRED);
result = false;
}
return result;
}
Related
I have a form with an attachment.When I tried to view my document,It is doing form validation and is asking to fill the respective fields,But i don't want to validate the form to view my file.I have changed the link from hcommand link to acommand link and tried a few more.But it's not working.Can someone help me out.
My code is
<h:form id="mailForm">
<span class = "clasMpnlErr" style="color:Blue"><h:messages id="mailFormErrorMessages" for="mailForm"/></span>
<table width="100%">
<tr>
<td style="width: 60px;">
<h:outputText value="#{labels['view.order.ordersummary.email.label.to']}"/>:
</td>
<td>
<h:inputText id="to" value="#{action.currentEditingEmail.toAddressList}" style="width: 685px;margin-left: 10px;" required="true" maxlength="255">
<f:validateLength maximum="255"/>
</h:inputText>
<span class="clasFormElemErr"><h:message for="to"/></span>
</td>
</tr>
<tr>
<td style="width: 60px;">
<h:outputText value="#{labels['view.order.ordersummary.email.label.cc']}"/>:
</td>
<td>
<h:inputText id="cc" value="#{action.currentEditingEmail.ccAddressList}" style="width: 685px;margin-left: 10px;" maxlength="255">
<f:validateLength maximum="255"/>
</h:inputText>
<span class="clasFormElemErr"><h:message for="cc"/></span>
</td>
</tr>
<tr>
<td style="width: 60px;">
<h:outputText value="#{labels['view.order.ordersummary.email.label.bcc']}"/>:
</td>
<td>
<h:inputText id="bcc" value="#{action.currentEditingEmail.bccAddressList}" style="width: 685px;margin-left: 10px;" maxlength="255">
<f:validateLength maximum="255"/>
</h:inputText>
<span class="clasFormElemErr"><h:message for="bcc"/></span>
</td>
</tr>
<tr>
<td style="width: 60px;">
<h:outputText value="#{labels['view.order.ordersummary.email.label.subject']}"/>:
</td>
<td>
<h:inputText id="subject" value="#{action.currentEditingEmail.subject}" style="width: 685px;margin-left: 10px;" maxlength="100">
<f:validateLength maximum="100"/>
</h:inputText>
<span class="clasFormElemErr"><h:message for="subject"/></span>
</td>
</tr>
<tr>
<td> </td>
<td>
<h:inputTextarea readonly="true" value="#{action.currentEditingEmail.contentNoComments}" rows="10" style="width: 685px;background: white;border: 0;margin-left: 10px;" />
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<h:outputText value="#{labels['view.order.ordersummary.email.label.comments']}"/>:
</td>
<td>
<h:inputTextarea id="comments" value="#{action.currentEditingEmail.comments}" rows="5" style="width: 685px;margin-left: 10px;" />
<span class="clasFormElemErr"><h:message for="comments"/></span>
</td>
</tr>
<tr>
<td align="right" valign="bottom">
<int:status id="editingEmailStatus" />
</td>
</tr>
</table>
<h:commandButton id="previousEmailLink" action="#{action.previousEmail}" style="visibility:hidden;display: none;">
<a:support event="onclick" disableDefault="true" action="#{action.previousEmail}" rendered="#{useAjax}" reRender="editingEmailOuter" onsubmit="ScnUtil.Status.start('editingEmailStatus');" oncomplete="ScnUtil.Status.end('editingEmailStatus');" />
</h:commandButton>
<h:commandButton id="nextEmailLink" action="#{action.nextEmail}" style="visibility:hidden;display: none;">
<a:support event="onclick" disableDefault="true" action="#{action.nextEmail}" rendered="#{useAjax}" reRender="editingEmailOuter" onsubmit="ScnUtil.Status.start('editingEmailStatus');" oncomplete="ScnUtil.Status.end('editingEmailStatus');" />
</h:commandButton>
<s:div id="viewAttachDocument" style="clear: both;width: 780px;">
<s:div style="clear: both;font: normal 12px Verdana">
<h:outputText value="#{labels['view.transport.label.attachments']}" rendered = "#{action.showPopUpDialog == true}"/>
</s:div>
<table style=" margin-left: 135px; width: 510px;background-color: white;">
<thead>
<tr>
<th style="color: lightslategrey;text-align: left;">
<h:outputText value="#{labels['view.tender.confirmation.include.documents']} " rendered = "#{action.showPopUpDialog == true}"/>
</th>
<th style="color: lightslategrey;text-align: left;">
<h:outputText value="#{labels['view.tender.confirmation.documentId']}" rendered = "#{action.showPopUpDialog == true}"/>
</th>
<th style="color: lightslategrey;text-align: left;">
<h:outputText value="#{labels['view.tender.confirmation.view']}" rendered = "#{action.showPopUpDialog == true}"/>
</th>
</tr>
</thead>
<tbody>
<a:repeat var="document" value="#{action.documentDetailsList}" varStatus="status">
<h:panelGroup>
<tr>
<td>
<h:selectBooleanCheckbox styleClass="checkbox" id="check_doc" value="#{document.selectChkBox}">
<a:support event="onclick"
ajaxSingle="true"
action="#{action.getSelectedIds(document.fileNetId,document.fileName)}"/>
</h:selectBooleanCheckbox>
</td>
<td>
<h:outputText value="#{document.fileName}"/>
</td>
<td>
<a:commandLink value="#{labels['view.base.button.value.view']}"
action="#{action.viewDocumentContent(document.fileNetId,document.fileName)}" />
</td>
</tr>
</h:panelGroup>
</a:repeat>
</tbody>
</table>
</s:div>
You can skip the validation by attribute "immediate" set to true.
e.g.
<h:commandLink immediate="true" value="" action="" />
Details how immediate attribute works:
https://cwiki.apache.org/confluence/display/MYFACES/How+the+immediate+attribute+works
I have two froms in my JSF page the first one to change the language of this page and the second from to submit the form to welcome page.
<h:form>
<h:selectOneMenu onchange="submit()"
valueChangeListener="#{lang.currentLanguage}" immediate="true">
<font color="blue"><f:selectItems value="#{lang.localeMap}" /> </font>
</h:selectOneMenu>
</h:form>
<h:form>
<table width="50%" align="left" border="1" cellpadding="5"
cellspacing="2">
<tr>
<td width="30%"><h:outputLabel value="#{msg.FName}" /></td>
<td width="70%"><h:inputText value="#{registerBeans.FName}"
id="FName" required="true" requiredMessage=" first name inValid"
validatorMessage="firt name out of range">
<f:validateLength minimum="3" maximum="10" />
</h:inputText></td>
</tr>
<tr>
<td width="30%"><h:outputLabel value="#{msg.SName}" /></td>
<td width="70%"><h:inputText value="#{registerBeans.sname}"
id="SName" required="true" requiredMessage=" second name inValid"
validatorMessage="second name out of range">
<f:validateLength minimum="3" maximum="10" />
</h:inputText></td>
</tr>
<tr>
<td width="30%"><h:outputLabel value="#{msg.mail}" /></td>
<td width="70%"><h:inputText value="#{registerBeans.mail}"
id="e-mail" required="true" requiredMessage=" e-mail inValid"
>
</h:inputText> </td>
</tr>
<tr>
<td width="30%"><h:outputLabel value="#{msg.password}" /></td>
<td width="70%"><h:inputSecret
value="#{registerBeans.password}" id="password" required="true"
requiredMessage="password not found"
validatorMessage="pasword out of range">
<f:validateLength maximum="20" minimum="4" />
</h:inputSecret></td>
</tr>
<tr>
<td width="30%"><h:outputLabel value="#{msg.Birthday}" /></td>
<td width="70%"><h:inputText value="#{registerBeans.birthday}"
id="birthday" required="true" requiredMessage="birthday invalid"
converterMessage="enter your birthday As dd/mm/yyyy">
<f:convertDateTime pattern="dd/mm/yyyy" />
</h:inputText></td>
</tr>
<tr>
<td width="30%"><h:outputLabel value="#{msg.GENDER}" /></td>
<td width="70%"><h:selectOneRadio
value="#{registerBeans.gender}" required="true" id="radio"
requiredMessage="please choose male OR femal">
<f:selectItem itemLabel="#{msg.male}" itemValue="male" />
<f:selectItem itemLabel="#{msg.Female}" itemValue="female" />
</h:selectOneRadio></td>
</tr>
<tr>
<td align="right" colspan="2">
<h:commandButton action="#{registerBeans.addStudent()}" value="#{msg.register}" /></td>
</tr>
<tr>
<td colspan="2">
<h:messages style="color:red"/></td>
</tr>
</table>
</h:form>
Here my Managed bean:
#ManagedBean
#SessionScoped
public class lang {
private Map<String,Locale> localeMap;
public Map<String, Locale> getLocaleMap() {
localeMap = new LinkedHashMap<String, Locale>();
localeMap.put("English", Locale.ENGLISH);
localeMap.put("Arabic", new Locale("ar"));
return localeMap;
}
public void setCurrentLanguage(ValueChangeEvent evt) {
String newLang = evt.getNewValue().toString();
System.out.println(newLang);
for (Map.Entry<String, Locale> entry : localeMap.entrySet()) {
if (entry.getValue().toString().equals(newLang)) {
FacesContext.getCurrentInstance().getViewRoot().setLocale((Locale)entry.getValue());
}
}
}
}
But I got the following exception when I add immediate attribute:
javax.faces.event.AbortProcessingException caught during processing of APPLY_REQUEST_VALUES 2 : UIComponent-ClientId=j_idt5:j_idt6, Message=Method not found: mypackage.language.lang#172134f.currentLanguage()
SEVERE: Method not found: mypackage.language.lang#172134f.currentLanguage() mypackage.language.lang#172134f.currentLanguage()
This work for me:
<h:form>
<h:selectOneMenu value="#{registerBeans.locale}" >
<f:selectItems value="#{registerBeans.localeMap}"/>
<f:ajax listener="#{registerBeans.addCurrentLanguage()}" render="fname sname mail pass birth gender reg"/>
</h:selectOneMenu>
<h:panelGrid columns="2">
<h:outputLabel value="#{msg.FName}" id="fname"/>
<h:inputText value="#{registerBeans.FName}"
id="FName" required="true" requiredMessage=" first name inValid"
validatorMessage="firt name out of range">
<f:validateLength minimum="3" maximum="10" />
</h:inputText>
<h:outputLabel value="#{msg.SName}" id="sname"/>
<h:inputText value="#{registerBeans.LName}"
id="LName" required="true" requiredMessage=" last name inValid"
validatorMessage="last name out of range">
<f:validateLength minimum="3" maximum="10" />
</h:inputText>
<h:outputLabel value="#{msg.mail}" id="mail" />
<h:inputText value="#{registerBeans.mail}"
id="e-mail" required="true" requiredMessage=" e-mail inValid"
>
</h:inputText>
<h:outputLabel value="#{msg.password}" id="pass"/>
<h:inputSecret
value="#{registerBeans.password}" id="password" required="true"
requiredMessage="password not found"
validatorMessage="pasword out of range">
<f:validateLength maximum="20" minimum="4" />
</h:inputSecret>
<h:outputLabel value="#{msg.Birthday}" id="birth"/>
<h:inputText value="#{registerBeans.birthday}"
id="birthday" required="true" requiredMessage="birthday invalid"
converterMessage="enter your birthday As dd/mm/yyyy">
<f:convertDateTime pattern="dd/mm/yyyy" />
</h:inputText>
<h:outputLabel value="#{msg.GENDER}" id="gender" />
<h:selectOneRadio
value="#{registerBeans.gender}" required="true" id="radio"
requiredMessage="please choose male OR femal">
<f:selectItem itemLabel="#{msg.male}" itemValue="male" />
<f:selectItem itemLabel="#{msg.Female}" itemValue="female" />
</h:selectOneRadio>
</tr>
</h:panelGrid>
<h:commandButton id="reg" action="#{registerBeans.addStudent()}" value="#{msg.register}" />
<h:messages style="color:red"/>
</h:form>
And I change bean to be like this:
#ManagedBean
#SessionScoped
public class RegisterBeans {
private String FName;
private String SName;
private String mail;
private String pass;
private String gender;
private Date birth;
private String locale;
// here getters and setters
public Map<String, Locale> getLocaleMap() {
localeMap = new LinkedHashMap<String, Locale>();
localeMap.put("English", Locale.ENGLISH);
localeMap.put("Arabic", new Locale("ar"));
return localeMap;
}
public void addCurrentLanguage() {
for (Map.Entry<String, Locale> entry : localeMap.entrySet()) {
if (entry.getValue().toString().equals(locale)) {
FacesContext.getCurrentInstance().getViewRoot().setLocale((Locale)entry.getValue());
}
}
}
}
Hello I have a problem with the following code. The Validator works correctly and everything is fine, my only problem is that the error messages for the validation are not displayed. Am I missing something or the problem is with the popup?
<rich:popupPanel id="popup" modal="true" height="280" width="200" resizeable="true" onmaskclick="#{rich:component('popup')}.hide()">
<f:facet name="header">
<h:outputText value="Simple popup panel" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide(); return false;"> X </h:outputLink>
</f:facet>
<h:form id="newmssform">
<table class="position">
<tr>
<td>
<h:outputText class="output_text" value="New MSS Name:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssusernamefield" value="#{NetworkBean.newMss}">
<f:validator validatorId="NewMssValidator"/>
<f:attribute name="mssaddressfield" value="#{mssaddressfield}"/>
</h:inputText>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:message for="mssusernamefield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="IP Address:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssaddressfield" value="#{NetworkBean.address}" binding="#{mssaddressfield}"/>
<h:message for="mssaddressfield" errorClass="errors"/>
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="User:"/>
</td>
</tr>
<tr>
<td>
<h:inputText id="mssuserfield" value="#{NetworkBean.mssUser}" />
</td>
</tr>
<tr>
<td>
<h:outputText class="output_text" value="Password:"/>
</td>
</tr>
<tr>
<td>
<h:inputSecret id="msspwdfield" value="#{NetworkBean.mssUserPass}" />
</td>
</tr>
<tr>
<td>
<a4j:commandButton style="border-radius: 5px; color: #FF6E00; font-weight: bold; font-size: 12px; margin-top: 5px;" value="Add New MSS"render="table,mss_table,oldIP" action="#{NetworkBean.addNewMss()}" />
</td>
</tr>
</table>
Here is the validator:
public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
String mssName = o.toString();
UIInput addressComponent = (UIInput)uic.getAttributes().get("mssaddressfield");
String address = addressComponent.getSubmittedValue().toString();
UIInput userNameComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String userName = userNameComponent.getSubmittedValue().toString();
UIInput passwordComponent = (UIInput) uic.getAttributes().get("mssaddressfield");
String password = passwordComponent.getSubmittedValue().toString();
if(mssName.isEmpty() || address.isEmpty() || userName.isEmpty() || password.isEmpty()){
addressComponent.setValid(false);
userNameComponent.setValid(false);
passwordComponent.setValid(false);
throw new ValidatorException(
new FacesMessage("Error!"));
}
}
As my prediction your message not rerender ontime
for h:message change code like below example
<a4j:outputPanel ajaxRendered="true">
<h:message for="mssusernamefield" errorClass="errors"/>
<a4j:outputPanel>
this may help you
FacesMessage consists of two Strings: summary and detail. When you call new FacesMessage("Error!") you're setting up the summary.
h:message's default behaviour is to show the detail, but not the summary. You can either tell it to show the summary: showSummary="true" or provide the detail in the FacesMessage: new FacesMessage("Error!", "Validation produced an error.")
I have this JSF table which I use to display data and to edit data:
<table>
<ui:repeat var="ud" value="#{DCProfileTabGeneralController.dcData}">
<tr>
<td>Datacenter Type</td>
<td>
<h:outputText value="#{ud.type}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.type}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Date Added</td>
<td>
<h:outputText value="#{ud.dateAdded}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText styleClass="datepicker" value="#{ud.dateAdded}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Hour Added</td>
<td>
<h:outputText value="#{ud.hourAdded}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.hourAdded}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Date Deployed</td>
<td>
<h:outputText value="#{ud.dateDeployed}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText styleClass="datepicker" value="#{ud.dateDeployed}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Hour Deployed</td>
<td>
<h:outputText value="#{ud.hourDeployed}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.hourDeployed}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
</ui:repeat>
</table>
This solution works fine but I want to extend it this way: I want to click on button which sets the edit flag to true. When I move the mouse over the value of the table the outputText to change to inputText.
And one more simple question. How I can add bottom padding to all fields globally?
I suggest you to use Richfaces library and use <rich:inplaceInput> component as below.
<rich:inplaceInput value="hhhh" editEvent="onmouseover"/>
However if you still like to stick to javascript this is a concept.
<h:form id="myForm">
<h:outputText value="aaa" id="outText"/><br/>
<h:inputText value="aaa" style="display:none;" id="inText" />
</h:form>
This is the javascript code
<script>
window.onload = function() {
var outputText = document.getElementById("myForm:outText");
var inputText = document.getElementById("myForm:inText");
outputText.onmouseover = function() {
outputText.style.display = 'none';
inputText.style.display = '';
}
inputText.onblur = function() {
outputText.style.display = '';
inputText.style.display = 'none';
}
};
</script>
Since you are using a ui:repeat, you should change the javascript code accordingly.
I have this simple JSF table which is use to display data from Database and also to edit data.
<table>
<ui:repeat var="ud" value="#{DCProfileTabGeneralController.dcData}">
<tr>
<td>Datacenter Type</td>
<td>
<h:outputText value="#{ud.type}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.type}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Date Added</td>
<td>
<h:outputText value="#{ud.dateAdded}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText styleClass="datepicker" value="#{ud.dateAdded}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Hour Added</td>
<td>
<h:outputText value="#{ud.hourAdded}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.hourAdded}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Date Deployed</td>
<td>
<h:outputText value="#{ud.dateDeployed}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText styleClass="datepicker" value="#{ud.dateDeployed}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
<tr>
<td>Hour Deployed</td>
<td>
<h:outputText value="#{ud.hourDeployed}"
rendered="#{not DCProfileTabGeneralController.editable}" />
<h:inputText value="#{ud.hourDeployed}" rendered="#{DCProfileTabGeneralController.editable}" />
</td>
</tr>
</ui:repeat>
</table>
Now I want to extend the table in this way. When the Boolean flag is true I want to display the text in 12px. When the Boolean flag is false I want to display the text in 20 px. Is this possible in JSF?
You can simply use an EL expression to set the appropriate CSS style:
<table id="idTable"
style="font-size: #{DCProfileTabGeneralController.editable ? '12px' : '20px' }">