I have a form which contains a list in a datatable. To add a New record to the list, click "Add" and the dialog box <p:dialog> appears, in that any empty datatable with 2 columns having two input text boxes to fill. In the dialog box I have Save and Cancel buttons. Once we click on Save button, a new record should saved into the database and the list in the form should show with the new record. The datatable is of primefaces inline row editing functionality. I'm using growl to display the error messages. Once I update my record with empty data, it shows the required message. But when I click on the Add button, it is again showing the same required message. It is showing the previous error. I don't want to have that. Could anyone help me in this context. The "Add" is an ajax request.
<h:body>
<ui:composition template="/WEB-INF/facelets/template/adminLayout.xhtml">
<ui:define name="view">
<h:form id="myForm" prependId="false">
<div class="header" >
<div class="titleColor">
T_COD_Prefil
</div>
</div>
<div class="divPosition">
<p:dataTable var="profile" id="profileTable" value="#{profileView.profileModelList}" rowEditListener="#{profileView.rowEditListener}" onRowEditUpdate="buttonPanel" >
<p:column style="width:60px;">
<p:rowEditor/>
<h:commandButton style="padding-left:5px;" image="/resources/images/delete.jpeg" styleClass="spa" value="delete" immediate="true" actionListener="#{profileView.delete}" >
<f:attribute name="delteProfile" value="#{profile}" />
</h:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="IDprefil" />
</f:facet>
<h:outputText value="#{profile.profileId}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="description" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{profile.profileDescription}" />
</f:facet>
<f:facet name="input">
<h:inputText required="true" requiredMessage="#{msg.desProfileEmpty}" maxlength="255" value="#{profile.profileDescription}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</div>
<div class="divButPosition">
<h:panelGroup id="buttonPanel">
<p:commandButton id="buttons" value="Add" actionListener="#{profileView.addEmptyProfile}"
async="true" update="myForm" rendered="#{!profileView.addNewRow}" oncomplete="profileDialog.show();" />
</h:panelGroup>
</div>
<p:growl id="growl" showDetail="false" />
<p:dialog id="profileDialog" header="Profile Detail" prependId="false" widgetVar="profileDialog" resizable="false" width="500" showEffect="explode" hideEffect="explode" modal="false" closable="false">
<h:dataTable var="newProfile" value="#{profileView.newProfile}">
<h:column>
<f:facet name="header">
<h:outputText value="IDprefil" />
</f:facet>
<h:inputText value="#{newProfile.profileId}" required="true" requiredMessage="not empty" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="description" />
</f:facet>
<h:inputText value="#{newProfile.profileDescription}" required="true" requiredMessage="Desctiption should not be empty" />
</h:column>
</h:dataTable>
<p:commandButton value="Save" actionListener="#{profileView.saveProfile}" async="true" update="growl,buttonPanel,profileTable" oncomplete="handleRequest(args ,document.getElementById('profileDialog'))" />
<p:commandButton value="Cancel" immediate="true" update="buttonPanel" async="true" actionListener="#{profileView.cancelProfile}" oncomplete="profileDialog.hide();" />
</p:dialog>
</h:form>
Try writing your growl at the top of the code, and update it when clicking on the button.
Well, doesn't work on IE8.
After submit button click, all fields will be validated first so, if some of them empty then requried message will be popup. So keep submit related data under different tag. Basically different forms for different submit buttons
Related
I have a data table which I want to export as different from the UI.
For example, part of my data table is
<p:column sortBy="#{phi.patProtein}" width="130">
<f:facet name="header">
<h:outputText value="Pathogen Protein" />
</f:facet>
<h:outputText id="patProteinText" value="#{phi.patProtein}" />
<p:commandLink id="patBtn" value="[+]" type="button" />
<p:overlayPanel for="patBtn" hideEffect="fade" dynamic="true"">
<h:outputText value="#{phi.patProteinLong}"/>
</p:overlayPanel>
</p:column>
I want to export only the output text ("#{phi.patProtein}") from the column, not the command link ("[+]") and overlay panel. But Primefaces exports everything in column, and not gives me a chance to specify which fields of column to export.
How can I do this?
If you create two <p:column>s, one containing the <h:outputText> and the other one containing the <p:commandLink> and the <p:overlaypanel>, you can set the attribute "exportable" of the second column to false:
<p:column sortBy="#{phi.patProtein}" width="130">
<f:facet name="header">
<h:outputText value="Pathogen Protein" />
</f:facet>
<h:outputText id="patProteinText" value="#{phi.patProtein}" />
</p:column>
<p:column exportable="false">
<p:commandLink id="patBtn" value="[+]" type="button" />
<p:overlayPanel for="patBtn" hideEffect="fade" dynamic="true"">
<h:outputText value="#{phi.patProteinLong}"/>
</p:overlayPanel>
</p:column>
Then only the text should be exported.
I am trying to update a primefaces form (wizard-first step) after an ajax command button request with no success. The command button that makes the actual ajax call is on a dialog. I would like after submitting the request to force my view to refresh.
The command button deletes a record from a datatable. It works fine, record is deleted but when dialog is hidden the datatable keeps displaying the deleted record. I would like to force it somehow to refresh. Any ideas? Could I do it from my backing bean reviewManagerBean.deleteProtocol() method?
Here is the code (my BackBean is viewScoped):
<h:form id="reviewManagerForm">
...
<pe:masterDetail id="masterDetail" level="#{reviewManagerBean.currentLevel}" showBreadcrumb="false" selectLevelListener="#{reviewManagerBean.levelListener}" >
<f:facet name="header" >
<h:panelGroup layout="block" style="margin-top: 10px;" >
<h:panelGroup styleClass="levelTitle ui-state-default ui-corner-all wizard-breadcrumbs#{reviewManagerBean.currentLevel eq 1 ? 'ui-state-hover' : ''}">
<h:outputText value="1: Protocol picker"/>
</h:panelGroup>
...
<p:messages id="mainMessagesPanel" showDetail="true" closable="true" />
</h:panelGroup>
</f:facet>
<pe:masterDetailLevel level="1">
<p:panel id="panel1" header="List of available protocols">
<p:dataTable id="protocolsDataTable" var="cRProtocol" rowKey="#{cRProtocol.revProtId}" value="#{reviewManagerBean.cRReviewProtocolList}"
widgetVar="protocolsTable"
...
selection="#{reviewManagerBean.selectedReviewProtocol}"
selectionMode="single" >
...
<p:ajax event="rowSelect" listener="#{reviewManagerBean.setSelectedRow}" />
<p:ajax event="rowUnselect" listener="#{reviewManagerBean.unsetSelectedRow}"/>
...
<p:column sortBy="#{cRProtocol.revProtTitle}" headerText="Title" style="width:200px;text-align:center;">
<h:outputText value="#{cRProtocol.revProtTitle}" />
</p:column>
...
<p:column>
<p:commandButton value="Delete" onclick="dlg5.show()"
update=":reviewManagerForm:deleteSingleProtocol"
disabled="#{reviewManagerBean.checkifProtocolIsOpen(cRProtocol)}"
ajax="true" process=":reviewManagerForm:deleteSingleProtocol" />
</p:column>
</p:dataTable>
</p:panel>
...
<p:dialog id="dialog-deleteprotocol" header="Delete Image Type" widgetVar="dlg5" dynamic="true" modal="true" resizable="false">
<p:panelGrid id="deleteSingleProtocol">
<p:row>
<p:column>
<h:outputText value="Id:" style="font-weight:bold; padding-right:10px" />
</p:column>
<p:column>
<h:outputText value="#{reviewManagerBean.selectedReviewProtocol.revProtId}" />
</p:column>
</p:row>
...
<p:column>
<p:commandButton id='protocolDelete'
value='Delete'
action='#{reviewManagerBean.deleteProtocol()}'
ajax="true"
onclick="dlg5.hide()" icon="ui-icon-disk"
update=":reviewManagerForm:protocolsDataTable"
process=":reviewManagerForm:deleteSingleProtocol" />
</p:column>
</p:row>
</p:panelGrid>
</p:dialog>
Your datatable should be re-rendered properly, you would have gotten an exception otherwise (something like component with id :reviewManagerForm:protocolsDataTable could not be found).
This means that #{reviewManagerBean.cRReviewProtocolList} will get called again. You need to remove the item from that list. This is appropriately done from #{reviewManagerBean.deleteProtocol}.
When #{reviewManagerBean.cRReviewProtocolList} is called after the removal, your datatable will get updated.
In my crud application I want to select a row and then display that row data in a popup. navigating to another page works and it displays the data. when I try to display it in my popup no values are displayed. I could be wrong but I think the popup opens before the method prepareView is done.
code block:
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<h:commandLink id="myLink" value="Action" action="#{timeLoggingDetailController.prepareView}" rendered="#{item.timeLoggingId eq AdminTimeLogging.filteredId}" styleClass="auto-style5">
<rich:componentControl target="popup" operation="show"/>
</h:commandLink>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false" domElementAttachment="form">
<f:facet name="header">
<h:outputText value="Approval level" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide();
return false;">
Close
</h:outputLink>
</f:facet>
<h:form id="submitForm">
<h:panelGrid columns="2">
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_date}"/>
<h:outputText value="#{timeLoggingDetailController.selected.date}" title="#{bundle.ViewTimeLoggingDetailTitle_date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_description}"/>
<h:outputText value="#{timeLoggingDetailController.selected.description}" title="#{bundle.ViewTimeLoggingDetailTitle_description}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_normalHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.normalHours}" title="#{bundle.ViewTimeLoggingDetailTitle_normalHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_overtimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.overtimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_overtimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_doubleTimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.doubleTimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_doubleTimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_approvalLevelsId}"/>
<h:outputText value="#{timeLoggingDetailController.selected.approvalLevelsId}" title="#{bundle.ViewTimeLoggingDetailTitle_approvalLevelsId}"/>
</h:panelGrid>
<br />
<h:panelGrid class="auto-style4">
<h:commandLink action="#{timeLoggingDetailController.update}" value="#{bundle.EditTimeLoggingDetailSaveLink}" onclick="#{rich:component('popup')}.hide();" styleClass="linkbutton"/>
</h:panelGrid>
</h:form>
</rich:popupPanel>
</ui:define>
</ui:composition>
</html>
You may want to use <a4j:commandLink>, it provides oncomplete event which is fired when the action completes.
This should work for you:
<a4j:commandLink id="myLink" value="Action" actionListener="#{timeLoggingDetailController.prepareView}" rendered="#{item.timeLoggingId eq AdminTimeLogging.filteredId}" styleClass="auto-style5">
<rich:componentControl event="complete" target="popup" operation="show"/>
</a4j:commandLink>
I have a parent form as and this form contain 5 more form on my five tabs. The problem is when i submit my parent form the data on parent form is submitting but all child form is not going on server. As i think by submitting parent form all child form are ignored. if i am right then please suggest a solution for this problem. i be very thankfull to all of you guys.I am using jsf2.0 primefaces 3.4
I have some problems in my page after merging the parent and children forms into a single one. I cannot update the <h:textarea> on row selection event.suggest me where i am wrong on update event my code is below
<h:form id="mainForm">
<h:panelGrid>
<p:accordionPanel activeIndex="#{salesLetterProBean.activeIndex}">
<p:tab title="Product Introduction" id="productinfooTab">
<p:panel header="Please Fill In The Details" style="padding:5px;"
id="productInfoPanel">
<h:panelGrid cellpadding="1" cellspacing="0" columns="1"
columnClasses="a,b,c,d,e" rowClasses="plainRow,shadedRow">
<h:outputLabel value="Introductory HeadLine:" class="field-title"
id="proInfoPanelGrid"/>
<p:inputTextarea value="#{salesLetterProBean.productIntroductoryLineRow.description}"
id="proIntroductorySentence"
style="width:1060px;height:400px;" effectDuration="400" />
</h:panelGrid>
<p:dataTable var="productIntroSentenceList" first="1"
value="#{salesLetterProBean.productIntroductorySentenceList}"
paginator="true" rows="5" rowsPerPageTemplate="5,10,15,20,25"
rowIndexVar="rowIndex" rowKey="#{productIntroSentenceList.id}"
selection="#{salesLetterProBean.productIntroductoryLineRow}"
selectionMode="single" update="proIntroductorySentence">
<p:ajax event="rowSelect" listener="#{salesLetterProBean.onRowSelect}" />
<p:column headerText="#">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{rowIndex}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{rowIndex}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{productIntroSentenceList.description}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{productIntroSentenceList.description}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Select">
<p:commandLink process="#none">
<!-- -->
<span title="Select" class="ui-icon ui-icon-check"/>
</p:commandLink>
</p:column>
</p:dataTable>
<h:panelGrid cellpadding="1" cellspacing="0" columns="1"
columnClasses="a,b,c,d,e" rowClasses="plainRow,shadedRow">
<h:outputLabel value="Feature List:" class="field-title" />
<p:inputTextarea style="width:1060px;height:400px;"
effectDuration="400" id="featureList"
value="#{salesLetterProBean.featureList}"/>
<h:outputLabel value="How Your Product Solve The Problems :"
class="field-title" />
<p:inputTextarea style="width:1060px;height:400px;"
effectDuration="400" id="prbSolutions"
value="#{salesLetterProBean.problemSolutions}" />
</h:panelGrid>
<h:commandButton value="Previous"
actionListener="#{applicantManagedBean.changeActiveIndex}"
immediate="true" class="defaultButton" />
<h:commandButton value=" Next "
actionListener="#{applicantManagedBean.changeActiveIndex}"
immediate="true" class="defaultButton" />
</p:panel>
</p:tab>
</p:accordionPanel>
</h:panelGrid>
</h:form>
Regards.
nested forms are not allowed, but you can have a multiple forms as stack.
I'm currently working with a PrimeFaces dataTable and am trying endlessly to append a new to the dataTable immediately after the user adds it. Server-side, everything is working -- data is saved to both the database and hard disk. I'd like to see a partial-page update following the successful request, and I just can't seem to get it to work. Here is my XHTML code:
<div class="content">
<div id="mainContent">
<div class="topNav">
<h:form id="navForm">
<p:commandButton value="Upload"/>
<p:commandButton value="New Folder" onclick="createDlg.show();" />
<p:commandButton value="Delete Folder" action="#" />
</h:form>
</div>
<div id="filePanel">
<h:form id="dataTable" prependId="false">
<p:dialog header="Create" widgetVar="createDlg" modal="true" height="200">
<p:panel header="New Folder">
<h:panelGrid columns="2">
<h:outputLabel value="Name:" for="txt_name"></h:outputLabel>
<p:inputText id="txt_name" value="#{directoryController.newDir.name}" required="true" />
<p:commandButton value="Create" actionListener="#{directoryController.createNew}" update="dGrid" oncomplete="createDlg.hide();"/>
<p:ajaxStatus style="width:16px; height:16px;">
<f:facet name="start">
<h:outputText value="Saving..." />
</f:facet>
<f:facet name="">
<h:outputText value="Complete." />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</p:panel>
</p:dialog>
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
And finally, here is my backing bean.
public String createNew(){
newDir.setDateCreated(new Date());
newDir.setDateModified(new Date());
newDir.setId(BigDecimal.ZERO);
newDir.setLocation(ROOT_DIRECTORY + currentUser.getUsername() + "/");
newDir.setFilesCollection(f);
newDir.setDescription("");
newDir.setOwner(currentUser);
current = newDir;
create();
persistDirectoryFromObject(newDir);
newDir = new Directory();
RequestContext.getCurrentInstance().addPartialUpdateTarget("dGrid");
return null;
}
If you are using 3.0.M4 you could do:
...
...
<p:outputPanel autoUpdate="true">
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</p:outputPanel>
or you could simply:
<p:commandButton value="Create" action="#{directoryController.createNew}" oncomplete="createDlg.hide();" ajax="false" />