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.")
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 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;
}
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' }">
I have input fields and datatable in the same page, in such a way that when user adds a new data, data should be added to the datatable without refreshing the page.
To achieve this I tried the following code
xhtml part
<table border="0">
<tr>
<td width="700" height="100px">Customer Name: <h:inputText
immediate="true" id="customername" autocomplete="false" value="#{salesBean.customerName}">
</h:inputText>
</td>
</tr>
<tr>
<td width="900" height="160px">
<table border="1">
<tr>
<td align="left">Product Name</td>
<td align="left">Rate</td>
<td align="left">Quantity</td>
<td align="left">Total Price</td>
<td align="left">Paid</td>
<td align="left">Date of Sales</td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><h:inputText immediate="true"
id="productname" autocomplete="false" value="#{salesBean.productName}">
</h:inputText></td>
<td align="left"><h:outputText id="rate"
binding="#{salesBean.productRate}" /></td>
<td align="left"><h:inputText size="2"
onkeyup="return calculateTotalRate(event);" id="quantity" value="#{salesBean.quantity}"/></td>
<td align="left"><h:outputText id="totalprice" /></td>
<td align="left"><h:selectOneRadio id="sor"
title="Select any one of the choice" value="#{salesBean.paidFlag}">
<f:selectItem id="si1" itemLabel="Yes" itemValue="yes" />
<f:selectItem id="si2" itemLabel="No" itemValue="no" />
</h:selectOneRadio></td>
<td align="left"><rich:calendar id="salesDate" value="#{salesBean.salesDate}"></rich:calendar></td>
<td align="center">
<h:commandButton value="Submit">
<a4j:support action="#{salesBean.submit}" reRender="table"></a4j:support>
</h:commandButton>
<h:commandButton value="Cancel" /></td>
</tr>
</table>`
</td>
</tr>
<tr>
<td>
<h:outputText id="errormessage" style="display:inline-block;color:Red;width:300px;"/>
</td>
</tr>
<tr>
<td>
<h:panelGroup id="panel">
<rich:dataTable var="data" id="table" binding="#{salesBean.table}" rendered="#{salesBean.salesHistoryRendered}">
<h:column>
<f:facet name="header">
<h:outputText value="Product Name"/>
</f:facet>
<h:outputText value="#{data.productName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date of Sale"/>
</f:facet>
<h:outputText value="#{data.dateOfSales}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Is Paid?"/>
</f:facet>
<h:outputText value="#{data.paidCheck}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Quantity?"/>
</f:facet>
<h:outputText value="#{data.quantity}"/>
</h:column>
</rich:dataTable>
<h:outputText id="text" binding="#{salesBean.checkValueChangeListener}"/>
</h:panelGroup>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
Please help me to solve this. Please update me if my question is not clear.
I am using JSF 1.2 and Richfaces 3.3.2
Thanks in advance
You have missed event attribute in a4j:support. Should be like this (disableDefault="true" is to prevent h:commandButton standard behavior):
<h:commandButton value="Submit">
<a4j:support event="onclick" disableDefault="true" action="#{salesBean.submit}" reRender="table"/>
</h:commandButton>
Or even better like this (will do the same as the lines above, but in more a4j-style):
<a4j:commandButton value="Submit" action="#{salesBean.submit}" reRender="table"/>
"Without refreshing the page" means AJAX.
RichFaces 3.3 has AJAX support, and their documentation explains how to use it in chapters 5.1 through 5.7.