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
Related
<a4j:form id="customerForm1" binding="#{customerForm.form}"
ajaxSubmit="false">
<h:inputHidden id="id" value="#{customerForm.customer.id}" />
<rich:panel id="purchaseOrderList"
styleClass="dataTablePanelStyle">
<a4j:outputPanel id="table">
<table border="1" width="100%">
<thead>
<tr align="center">
<th width="8%"><h:outputText id="headerq"
value="#{msg.distance}" styleClass="boldOutputTextStyle" /></th>
<th width="2%"><h:outputText id="ds8" value="" /></th>
</tr>
</thead>
<tbody>
<a4j:repeat
value="#{customerForm.customer.distanceTravelledList}"
var="purchaseOrderDetails" rowClasses="row1, row2">
<tr class="#{(rowIndex mod 2 eq 0)? 'row1' : 'row2'}">
<td align="center" width="10%">
<h:inputText id="distance" size="5" required="true"
value="#{purchaseOrderDetails.distance}"
styleClass="inputTextStyle">
</h:inputText>
</td>
<td><a4j:commandButton value="+"
action="#{customerForm.addDistanceTravelled}"
reRender="purchaseOrderList">
</a4j:commandButton></td>
</tr>
</a4j:repeat>
</tbody>
</table>
</a4j:outputPanel>
</rich:panel>
</a4j:form>
I have created a table where I have used a4j:repeat tag, so that the user can dynamically add the rows depending on his requirement..But when I remove this tag ie a4j:repeat frontend displays only one row ie both column name and input text field.. But when I add a4j:repeat` only the colum names are displayed ie Distance...Can any one tel Me what have I missed ??
Try this, I am using such a table for my process. It works fine for me it may help for you.
<table border="1" width="100%">
<thead>
<tr align="center">
<th width="8%"><h:outputText id="headerq"
value="#{msg.distance}" styleClass="boldOutputTextStyle" /></th>
<th width="2%"><h:outputText id="ds8" value="" /></th>
</tr>
</thead>
<tbody>
<a4j:repeat
value="#{customerForm.customer.distanceTravelledList}"
var="purchaseOrderDetails" rowKeyVar="rowIndex">
<tr>
<td align="center" width="10%">
<h:inputText id="distance" required="true"
value="#{purchaseOrderDetails.distance}"
styleClass="inputTextStyle">
</h:inputText>
</td>
<td><a4j:commandButton value="+"
action="#{customerForm.addDistanceTravelled}"
reRender="purchaseOrderList">
</a4j:commandButton></td>
</tr>
</a4j:repeat>
</tbody>
I am working on j2ee web application (jsf2 and primefaces) and i wonder how to display form depending on the item selected from select one menu.
I tried this but it didn't work.
<h:form id="global">
<p:panel header="Association">
...
<p:outputLabel value="Travel Class" />
<p:selectOneMenu id="associationType" style="width: 230px" value="#{associationMBean.travelClass}">
<f:selectItem itemLabel="Select one" itemValue="" />
<f:selectItem itemLabel="Seminar" itemValue="Seminar" />
<f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" />
<f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
<p:ajax update=":hidePanel"/>
</p:selectOneMenu>
</p:panel>
</h:form>
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)" rendered="#{associationMBean.travelClass eq Seminar}">
<h:form>
<p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
Update
<html
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Visa Application-Thailand</title>
</h:head>
<h:body>
<div align="center">
<div>
<img class="logo" src="images/banner.jpg"/>
</div>
<p:panel style="width: 61%; border-color: indianred; border-width: 2px; margin-top: 10px">
<h:form id="global">
<p:panel style="margin-top: 20px; font-size: 14px ; border: 0" header="Association">
<table border="0" >
<tbody >
<tr>
<td align="right">
<p:outputLabel value="Association Type" />
</td >
<td align="left">
<p:selectOneMenu id="selectmenu" style="width: 230px" value="#{associationMBean.type}">
<f:selectItem itemLabel="Select a Class" itemValue="" />
<f:selectItem itemLabel="Seminar" itemValue="Seminar" />
<f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
<f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" />
<p:ajax update=":hidePanel"/>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Date of Departure" for="departure" />
</td>
<td align="left">
<p:calendar value="#{associationMBean.departure}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="departure"></p:calendar>
<p:watermark value="01/01/2014" for="departure"/>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Date of Arrival" for="arrival" />
</td>
<td align="left">
<p:calendar value="#{associationMBean.arrival}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="arrival"></p:calendar>
<p:watermark value="01/01/2014" for="arrival"/>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Travel Agency " for="travelAgency"/>
</td>
<td align="left">
<p:inputText id="travelAgency" value="#{associationMBean.travelAgency}" style="width: 220px"></p:inputText>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Airline " for="airline"/>
</td>
<td align="left">
<p:inputText id="airline" value="#{associationMBean.airline}" style="width: 220px"></p:inputText>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Travel Class" />
</td >
<td align="left">
<p:selectOneMenu id="selectclass" style="width: 230px" value="#{associationMBean.travelClass}">
<f:selectItem itemLabel="Select a Class" itemValue="" />
<f:selectItems value="#{associationMBean.allClasses}" />
<!-- <p:ajax update=":hidePanel"/> !-->
</p:selectOneMenu>
</td>
</tr>
<tr >
<td align="right">
<p:outputLabel value="Hotels " for="hotels" />
</td>
<td align="left">
<p:inputTextarea id="hotels" value="#{associationMBean.hotels}" style="width: 220px"/>
</td>
</tr>
</tbody>
</table>
</p:panel>
<div align="right" style="margin-top: 20px ">
<p:commandButton type="reset" value="Reset" style="font-size: 14px;"/>
<p:commandButton value="Save" ajax="false" styleClass="ui-priority-primary" style="font-size: 14px;" action="#{associationMBean.addAssociation()}" />
</div>
</h:form>
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)" >
<h:form rendered="#{associationMBean.type == 'Seminar'}" >
<p:inputTextarea style="width: 100% ; height: 100px" value="#{visaMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
</p:panel>
</div>
</h:body>
</html>
the code above is the whole html code after adding some updates <h:form rendered="#{associationMBean.type == 'Seminar'}" > But still can't display the hidePane when i select Seminar from the selectOneMenu.
Have you any idea what am i missing??
The following should work:
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)">
<h:form rendered="#{associationMBean.travelClass eq 'Seminar'}">
<p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
You can not update components which are not in the DOM and when a component is not rendered it is not in there. So you need to update the parent of the conditionally rendered component.
And as #{associationMBean.travelClass} is a String you need to wrap 'Seminar' with single quotes '.
I have designed a jsf page and my scenario is to render output panel based on changing the dopdown in selectonemenu. My problem here is required=true in inputtext box. It dosnt allow other components to render and when i give value in textbox , then it allows the selectonemenu to render . What is the mistake i have done.Please can someone solve my problem
Code
<a4j:outputPanel id="thapalSection" >
<ui:fragment>
<fieldset style="table-layout: fixed;">
<legend>#{msg.lbl_post_offSect}</legend>
<table border="0" cellpadding="1" cellspacing="15" width="100%"
style="border-width: 1px;border-spacing: 1px;border-style: solid;border-color:#c2c2c2">
<tr>
<td align="left" width="20%">#{msg.lbl_SenDTo}<span>
<font color="red"><b>*</b></font></span>
</td>
<td align="left" colspan="3" width="30%">
<a4j:outputPanel id="tapalSectionSendToPanel">
<h:inputText id="sendToId" value="#{DataBean.kabalSectionBean.sendTo}" class="createresizedTextbox"
readonly="true" required="true" requiredMessage="#{msg.labl_required}" />
<h:message for="sendToId" style="color:red" />
</a4j:outputPanel>
</td>
</tr>
<tr>
<td align="left" width="20%" >#{msg.lbl_lettRef}</td>
<td align="left" width="34%" >
<a4j:outputPanel id="letterReferenceIDPAnel">
<h:inputText id="lettRefId" value="#{DataBean.kabalSectionBean.letterFileRefNo}"
class="createresizedTextbox" required="true" requiredMessage="#{msg.labl_required}" immediate="true"/>
<h:message for="lettRefId" style="color:red" />
</a4j:outputPanel>
</td>
</tr>
<tr>
<td>#{msg.lbl_Sender_type}</td>
<td>
<a4j:outputPanel id="senderTypePanel" >
<h:selectOneMenu value="#{DataBean.kabalSectionBean.senderType}" class="createresizedTextbox" id="senderTypeID">
<a4j:ajax event="change" render="thapalSection internalPanel" listener="#{FileTrackAction.selectSenderType}" />
<f:selectItem itemValue="--select--" itemLabel="--Select--" />
<f:selectItem itemValue="internal" itemLabel="Internal" />
<f:selectItem itemValue="external" itemLabel="External" />
<f:validator validatorId="org.gov.tnwrd.bean.validation.DropdownValidation" />
</h:selectOneMenu>
<h:message for="senderTypeID" style="color:red" />
</a4j:outputPanel>
</td>
</tr>
<a4j:outputPanel id="internalPanel" >
<ui:fragment rendered="#{DataBean.kabalSectionBean.sendTypeIntEnabled==true}" >
<tr>
<td align="left" width="20%" >#{msg.lbl_office_name}</td>
<td align="left" width="34%">
<h:inputText id="internalType" value="#{DataBean.kabalSectionBean.officeName}" class="createresizedTextbox" readonly="true" />
</td>
<td align="left" width="17%" >#{msg.lbl_type_letter}</td>
<td align="left">
<h:selectOneMenu class="createresizedTextbox" value="#{DataBean.kabalSectionBean.typeOfletter}">
<f:selectItem itemValue="--" itemLabel="--Select--" />
<f:selectItem itemValue="ordinaryLetter" itemLabel="Ordinary Letter" />
<f:selectItem itemValue="doLetter" itemLabel="D.O Letter" />
<f:selectItem itemValue="confidentialLetter" itemLabel="Confidential Letter" />
<f:selectItem itemValue="OtherLetter" itemLabel="Other Letter" />
</h:selectOneMenu>
</td>
</tr>
</ui:fragment>
</a4j:outputPanel>
</table>
</fieldset>
</ui:fragment>
</a4j:outputPanel>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="1" cellpadding="15" width="100%" border="0">
<tr>
<td></td>
<td colspan="6" align="right">
<div class="buttons">
<a4j:commandButton id="addThapal" value="#{msg.btn_send}" type="button" render="thapalPanel savePopUp" action="#{FileTrackAction.saveThapalDetails}" oncomplete="if(#{DataBean.kabalSectionBean.statusCode eq 'Success'}) #{rich:component('savePopUp')}.show();"/>
<a4j:commandButton id="clearId" value="#{msg.btn_clear}" render="thapalPanel" action="#{FileTrackAction.clearTapalSection}" type="button" />
</div>
</td>
</tr>
</table>
</a4j:outputPanel>
The problem is, that the validation fails. This causes JSF to interrupt its lifecycle and jump from validation directly to rendering without changing anything in between.
I don't know exactly when you set DataBean.kabalSectionBean.sendTypeIntEnabled but you can check that this value will not be set to true and thus your panel will not be changed.
You have different options here. Either you can use the immediate="true" attribute to skip validation, or you can use execute="list of components you want to execute". Execute means, that the data will be sent to the backing bean, will be validated and the setXXX(...) methods will be called for this input. Here you would NOT list the required field and thus its validation won't be a problem.
If you use execute="#none" it has the same effect like immediate="true".
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 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' }">