I have a jsf page having a popup button that opens a following dialog popup:
</h:form>
<p:dialog id="dialog" header="Select different user"
widgetVar="dlg" appendToBody="true">
<h:form id="form23">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" />
</f:facet>
</h:panelGrid>
</h:form>
</h:form>
But instead of opening as popup it is getting displayed outside the page itself. the dialog is outside the main form. Help!!
I tried that but still the same problem persists..below is my modified code..
<h:form id="create-ticket">
<p:dialog id="dialog" header="Select different user" widgetVar="dlg" appendToBody="true">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login"
/>
</f:facet>
</h:panelGrid>
</p:dialog>
<h:panelGroup>
<h:outputLabel value="#{I18N['Create_Ticket_for_other_users']}" styleClass="atf-header"></h:outputLabel>
</h:panelGroup>
<h:panelGroup id="search_section" layout="block"
styleClass="atf-content-area atf-separarot-botton"> <!-- This is the section where we get the grey background -->
<h:panelGroup id="input_search_section" styleClass="">
<h:outputText id="name" value="Siddharth Mishra"
labelStyleClass="atf-label">
</h:outputText>
</h:panelGroup>
<h:panelGroup styleClass="atf-right atf-inline-block">
<p:commandButton id="btn_search" value="select different user"
styleClass="atf-button-search" onclick="dlg.show();" type="button"
>
</p:commandButton>
</h:panelGroup>
</h:panelGroup>
Now i only have one form you can see the popup dialog section + the button which is calling the popup under h:panelgroup.Atached is the image how the form currently looks Thanks in advance
You need to restructure your code.
*Don't nest forms inside other forms.
*You dont have the end-tag of your p:dialog.
<h:form>
<p:dialog id="dialog" header="Select different user"
widgetVar="dlg" appendToBody="true">
//Content ex inputtext
</p:dialog>
<p:commandButton value="Show Dialog" onclick="dlg.show();" type="button" />
</h:form>
Related
I have a simple CRUD application written in JSF 2.2 and PrimeFaces 3.5. The database consists of two tables - Clients and Orders. I have a view with datatable where all clients are listed and in the last column are three buttons - for eidt, delete and showing the orders for each client. When edit button is clicked the data for the selected client should be loaded in a modal dialog form but no matter which button is pressed in the dialog always is loaded data for the client in the first row. Same for the delete button.
Here is the code of the view:
<h:form id="form">
<p:growl id="msgs" showDetail="true" />
<p:commandButton id="addNewClientButton" type="button"
onclick="add.show();" value="Add new client"
action="clientBeans.newClient" />
<br />
<p:dataTable var="client" value="#{clientBeans.getAllClients()}"
border="true">
<p:column headerText="Client Id">
<h:outputText value="#{client.clientId}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{client.name}" />
</p:column>
<p:column headerText="Address">
<h:outputText value="#{client.address}" />
</p:column>
<p:column headerText="Email">
<h:outputText value="#{client.email}" />
</p:column>
<p:column headerText="Options">
<p:commandButton value="Edit" id="editClientButton"
action="#{clientBeans.editClient}" type="button"
update=":form:editClient" onclick="edit.show();">
<f:setPropertyActionListener
target="#{clientBeans.client}"
value="#{client}" />
</p:commandButton>
<p:commandButton action="#{clientBeans.deleteClient}"
value="Delete"
id="deleteClientButton" type="button"
onclick="remove.show();"
icon="ui-icon-circle-close">
<f:setPropertyActionListener
target="#{clientBeans.client.clientId}"
value="#{client}" />
</p:commandButton>
<p:commandButton
action="#orderBeans.getSpecificOrders(client.clientId)}"
value="Orders">
<f:setPropertyActionListener
target="#{clientBeans.client.clientId}"
value="#{client.clientId}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<h:form>
<p:dialog id="addNewClient" header="Add new client" widgetVar="add"
modal="true" resizable="false">
<p:panelGrid columns="2" border="false">
<h:outputLabel for="name" value="Name: " />
<p:inputText id="name" value="#{clientBeans.client.name}"
label="name" required="true" />
<h:outputLabel for="address" value="Address: " />
<p:inputText id="address"
value="#{clientBeans.client.address}"
label="address" required="true" />
<h:outputLabel for="email" value="Email: " />
<p:inputText id="email" value="#{clientBeans.client.email}"
label="email" required="true" />
<f:facet name="footer">
<p:commandButton
action="#{clientBeans.createClient}" value="Save"
icon="ui-icon-check" style="margin:0">
</p:commandButton>
</f:facet>
</p:panelGrid>
</p:dialog>
</h:form>
<h:form>
<p:dialog id="editClient" header="Edit client" widgetVar="edit"
modal="true" resizable="false">
<h:panelGrid columns="2" id="displayClient">
<h:outputLabel for="id" value="Id: " />
<h:outputText id="id" value="#{client.clientId}" label="id" />
<h:outputLabel for="name" value="Name: " />
<p:inputText id="name" value="#{client.name}" label="name"
required="true" />
<h:outputLabel for="address" value="Address: " />
<p:inputText id="address" value="#{client.address}" label="address"
required="true" />
<h:outputLabel for="email" value="Email: " />
<p:inputText id="email" value="#{client.email}" label="email"
required="true" />
<f:facet name="footer">
<p:commandButton
action="#{clientBeans.updateClient}" value="Save"
icon="ui-icon-check" style="margin:0">
</p:commandButton>
</f:facet>
</h:panelGrid>
</p:dialog>
</h:form>
<h:form>
<p:dialog id="deleteClient"
header="Are you sure you want to delete this client?"
widgetVar="remove" modal="true" resizable="false">
<p:panelGrid columns="2">
<h:outputLabel for="id" value="Id: " />
<h:outputText id="id" value="#{client.clientId}" label="id" />
<h:outputLabel for="name" value="Name: " />
<h:outputText id="name" value="#{client.name}" label="name" />
<h:outputLabel for="address" value="Address: " />
<h:outputText id="address" value="#{client.address}" label="address" />
<h:outputLabel for="email" value="Email: " />
<h:outputText id="email" value="#{client.email}" label="email" />
<f:facet name="footer">
<p:commandButton action="#{clientBeans.confirmDeleteClient}"
value="Delete" icon="ui-icon-circle-close" />
</f:facet>
</p:panelGrid>
</p:dialog>
</h:form>
I haven't gone through all the code, but I could quickly spot that you have misused <p:commandButton>: the attribute type="button" should only be used for invoking custom JavaScript (client) code, it is therefore not compatible with action and actionListener, that are suitable for invoking server actions. Remove this attribute and ensure that the managed beans's method #{clientBeans.editClient} is invoked.
Look at PrimeFaces documentation, commandButtons with type="button" are called "Push Buttons".
Second, use oncomplete instead of onclick, in order to show the dialog after the ajax method has completed its job.
I have a primefaces dialog and what I want to do is process inputtext before commandbutton action starts. Inside myController.sendToPostBox method, myController.rejectionReason string returns null. Here is my view code.When I remove process attribute, commandbutton doesn't works.
<h:form>
....
<p:dialog id="myPanel"
widgetVar="myPanelId"
resizable="true"
appendToBody="true"
draggable="true"
height="200"
width="300">
<p:panelGrid id="myPanelGridId" style="width: 250px;" styleClass="panelGridWithoutBorder">
<p:row>
<p:column colspan="2">
<p:inputTextarea style="width: 250px;" value="#{myController.rejectionReason}"/>
</p:column>
</p:row>
<p:row>
<p:column>
<p:commandButton value="Save"
oncomplete="if (!args.validationFailed) myPanel.hide();"
process="myPanelId"
action="#{myController.sendToPostBox()}"/>
</p:column>
<p:column>
<p:commandButton value="Close" />
</p:column>
</p:row>
</p:panelGrid>
</p:dialog>
</h:form>
Just place the <h:form> inside the dialog (instead dialog inside the <h:form>)
Explanation:
When you use appendToBody="true" you dialog is being transferred outside of the form that wraps it to the body of the generated html , and since there is no form inside the dialog you can't really submit it.
Also take a look at this thread: Proper Construct for Primefaces Dialog
You need something like this:
<h:form id="formDialog">
<p:commandButton id="basic" value="Basic Dialog" onclick="PF('dlg1').show();" type="button" />
</h:form>
<p:dialog id="basicDialog" header="Basic Dialog" widgetVar="dlg1">
<h:form id="formUser">
<h:panelGrid id="grid" columns="2">
<h:outputLabel value="Username:" />
<p:inputText id="user" value="#{user.name}" />
<h:outputLabel value="Password:" />
<p:inputText id="password" value="#{user.password}" />
<h:commandButton value="Login" id="btn" process="#formUser" actionListener="#{user.login}" />
</h:panelGrid>
</h:form>
</p:dialog>
"login" in the actionListener tag is a method in the User(bean) class, that needs the #ManagedBean annotations.
I am facing a problem in p:tabView with dynamic="true" which i am stuck in for days.
I have three tabs each having separate form and p:fileUpload with command button for submitting the form and upload file.
The problem is my first form or tab works fine but the other two are not working or firing command button action at all, instead ti refreshes the page. They are invoked only when second time form filled and button pressed.
And to add one thing more the fileUploadListeners even work fine in all these tabs but the command button wont work or fire action method for other two tabs(only the first time form filled and submitted after that works fine):
Is there something wrong with this primefaces tag(i m using latest version of primefaces 3.5 also) or i am mistaking or missing something?? any kind of guidance will be helpful.
Here is the page code which is included in another main page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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"
template="/MasterPage/Master.xhtml">
<ui:define name="Search">
<div class="searchBarDiv"></div>
<br class="clear" />
<div class="resultMainDiv" style="background-color: white;">
<p:layout style="width:1218px;height:558px;" id="layout">
<p:ajax event="toggle" />
<p:layoutUnit position="west" size="300" header="UPDATES"
resizable="true" collapsible="true" styleClass="sliderDiv"
style="color:pink;">
</p:layoutUnit>
<p:layoutUnit position="center" styleClass="resultDiv">
<div class="uploadDiv">
<p:tabView id="tabview" cache="false" dynamic="true">
<p:tab id="docTab" title="Document">
<h:form id="docf" >
<h:panelGrid id="grid" columns="1">
<h:panelGroup>
<h:outputLabel styleClass="advLabel"
for="mId" value="Title ">
</h:outputLabel><h:outputLabel style="color: red;">*</h:outputLabel>
<h:inputText id="mId"
styleClass="txtfield"
value="#{documentInsertController.documentTitle}">
</h:inputText>
</h:panelGroup>
<h:panelGroup>
<h:outputLabel class="advLabel">Dated </h:outputLabel>
<p:calendar styleClass="txtfield" id="dtxtOrginated"
mode="popup" navigator="true" yearRange="1900:2015"
pattern="dd-MMM-yyyy"
converter="CalendarDateStringConverter"
value="#{documentInsertController.documentOriginatedOn}" />
</h:panelGroup>
<h:panelGroup>
<h:outputLabel class="advLabel">KeyWord</h:outputLabel><h:outputLabel
style="color: red;"> *</h:outputLabel>
<h:inputText id="dtxtKeywordsList"
value="#{documentInsertController.documentKeywords}"
styleClass="txtfield" />
</h:panelGroup>
<h:panelGrid rendered="#{renderBean.viewLoad}">
<h:panelGroup> <h:outputLabel class="advLabel">Select Document</h:outputLabel><h:outputLabel
style="color: red;"> *</h:outputLabel>
<p:fileUpload id="fu" allowTypes="/(\.|\/)(DOC|DOCX|doc|docx|ppt|xls|xlsx|pdf)$/"
multiple="false" mode="advanced" sizeLimit="41949000" showButtons="false"
fileUploadListener="#{documentInsertController.uploadPListener}" label="Browse"
value="#{documentInsertController.file}" >
<h:message id="docMSG" for="fu"></h:message>
</p:fileUpload>
</h:panelGroup>
<h:panelGroup>
<p:commandButton id="DocUpoadLoad" styleClass="btn"
value="Load File For Preview" ajax="false"
action="#{documentInsertController.loadDocForPreview}"
style="background-color:#FEAA41;background-image:none;color:white;font-weight:bold;width:170px; height:25px;">
</p:commandButton>
</h:panelGroup>
</h:panelGrid>
</h:panelGrid>
</h:form>
<p:commandButton id="DocUploadbtn" value="Upload"
action="#{documentInsertController.saveDocument}"
ajax="false"
style="background-color:#FEAA41;background-image:none;color:white;font-weight:bold; ">
</p:commandButton>
</h:panelGrid>
</p:tab>
<p:tab id="imgTab" title="Image">
<h:form id="imagef" >
<h:panelGrid id="grid" columns="1">
<h:panelGroup> <h:outputLabel class="advLabel">Title </h:outputLabel> <h:outputLabel
style="color: red;"> *</h:outputLabel>
<h:inputText id="txtImgTitle"
value="#{mediaInsertController.mediaTitle}"
styleClass="txtfield" >
</h:inputText>
</h:panelGroup>
<h:panelGroup> <h:outputLabel class="advLabel">Taken Date</h:outputLabel>
<p:calendar styleClass="txtfield"
id="imgtxtOrginated" mode="popup" navigator="true"
yearRange="1900:2015" pattern="dd-MMM-yyyy"
converter="CalendarDateStringConverter"
value="#{mediaInsertController.mediaTakenOn}" />
</h:panelGroup>
<h:panelGroup> <h:outputLabel class="advLabel">Description</h:outputLabel>
<h:inputTextarea id="txtImgDescription"
value="#{mediaInsertController.mediaDescription}"
styleClass="txtImgDescription" /></h:panelGroup>
<h:panelGroup> <h:outputLabel class="advLabel">Select Image</h:outputLabel><h:outputLabel
style="color: red;"> *</h:outputLabel>
<p:fileUpload id="fuImage" allowTypes="/(\.|\/)(jpeg|jpg|png|bmp|gif|GIF|PNG)$/"
multiple="false" mode="advanced" sizeLimit="6291456" showButtons="false"
label="Browse" invalidSizeMessage="File exceeds limmit 6 MB "
value="#{mediaInsertController.file}" fileUploadListener="#{mediaInsertController.uploadPListener}" />
<h:message id="imgMSG" for="fuImage"></h:message>
</h:panelGroup>
<p:commandButton styleClass="btn" id="btnUploadImage_Click" ajax="false"
value="Upload" actionListener="#{mediaInsertController.saveImage}"
style="background-color:#FEAA41;background-image:none;color:white;font-weight:bold; ">
</p:commandButton>
</h:panelGrid>
</h:form>
</p:tab>
<p:tab id="vidTab" title="Video">
<h:form id="videof" >
<h:panelGrid id="grid" columns="1">
<h:panelGroup>
<h:outputLabel class="advLabel">Title </h:outputLabel> <h:outputLabel
style="color: red;"> *</h:outputLabel>
<h:inputText id="vtxtTitle"
value="#{mediaInsertController.mediaTitle}"
styleClass="txtfield" maxlength="50" >
</h:inputText></h:panelGroup>
<h:panelGroup> <h:outputLabel class="advLabel">Taken Date</h:outputLabel>
<p:calendar styleClass="txtfield" id="vtxtOrginated"
mode="popup" navigator="true" yearRange="1900:2015"
pattern="dd-MMM-yyyy"
converter="CalendarDateStringConverter"
value="#{mediaInsertController.mediaTakenOn}" />
</h:panelGroup>
<h:panelGroup> <h:outputLabel for="txtVidDescription"
value="Description" styleClass="advLabel"></h:outputLabel>
<h:inputTextarea id="txtVidDescription"
value="#{mediaInsertController.mediaDescription}"
styleClass="txtUploading" style="height:40px" />
</h:panelGroup>
<h:panelGroup> <h:outputLabel class="advLabel">Select Video</h:outputLabel><h:outputLabel
style="color: red;"> *</h:outputLabel>
<p:fileUpload id="fuVideo" allowTypes="/(\.|\/)(mp4|flv|swf)$/" invalidFileMessage="Invalid file content"
multiple="false" mode="advanced" sizeLimit="629145699" showButtons="false" update="vidMSG"
fileUploadListener="#{mediaInsertController.uploadPListener}" label="Browse" invalidSizeMessage="Size exeeds limit 600MB"
value="#{mediaInsertController.file}" />
<h:message id="vidMSG" for="fuVideo"></h:message>
</h:panelGroup>
<p:commandButton styleClass="btn" id="btnUploadVideo_Click" ajax="false"
value="Upload" action="#{mediaInsertController.saveVideo}"
style="background-color:#FEAA41;background-image:none;color:white;font-weight:bold; ">
</p:commandButton>
</h:panelGrid>
</h:form>
</p:tab>
</p:tabView>
</div>
</p:layoutUnit>
</p:layout>
<p:growl autoUpdate="true" sticky="true" id="uploadMSG"></p:growl>
</div>
</ui:define>
</ui:composition>
Your commandButton id="DocUploadbtn" is outside the h:form, that could be affecting things. There also seem to be three closing h:panelGrid tags around the same area; could it be malformed XHTML?
I copied the exact code from this Primefaces http://blog.primefaces.org/?p=1512 blog about easy password validation
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{registerMB.password}"
feedback="false" match="pwd2" label="Password 1" required="true" />
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{registerMB.password}"
feedback="false" label="Password 2" required="true" />
<f:facet name="footer">
<p:commandButton value="Register" action="/pages/public/login" />
<p:commandButton value="Cancel" immediate="true"
action="/pages/public/login" />
</f:facet>
Validation works but I am only able to get the Validation Error. The message Password 1 should match Password 2 is never displayed. Is there anymore configuration for this?
I have Primefaces 3.4.1 downloaded
Try to add the following
validatorMessage atribute inside p:password tag id="pwd2":
<p:password id="pwd2" value="#{registerMB.password}"
feedback="false" label="Password 2" required="true"
validatorMessage="password 1 should match password 2"/>
add p:message tag to show the error below the h:form tag
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
add <p:messages id="messages" showDetail="true" autoUpdate="true"/>
just like int Primefaecs Password Showcase
<h:form id="form">
<p:panel header="Match Mode">
<p:messages id="messages" showDetail="true" autoUpdate="true"/>
<h:panelGrid columns="2" id="matchGrid">
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{passwordBean.password5}" match="pwd2" label="Password 1" required="true"/>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{passwordBean.password5}" label="Password 2" required="true"/>
</h:panelGrid>
<p:commandButton id="saveButton" update="matchGrid" value="Save" />
</p:panel>
</h:form>
I have a form with 4 fields (2 dates, 2 selectOne).
My Bean is SessionScoped.
When I change the values in the form once, and click on submit, the applications works fine.
But when I want to change the values in form again, nothing happens. no change nor execution.
My Form looks like:
<ui:define name="sidebar">
<p:panel header="Select Values">
<h:form id="graphform">
<p:growl id="msg" />
<p:panelGrid columns="1">
<h:outputLabel for="servervalue" value="Servervalue: " />
<p:selectOneMenu value="#{graph.servervalue }" id="servervalue">
<f:selectItems value="#{formconst.SERVERVALUES}" />
</p:selectOneMenu>
<h:outputLabel for="startdate" value="Startdate: " />
<p:calendar disabledWeekends="false" size="10" pattern="dd.MM.yyyy"
showOtherMonths="true" maxlength="10"
mindate="#{formconst.MINDATE }" maxdate="#{formconst.MAXDATE}"
showButtonPanel="true" navigator="true" readOnlyInputText="true"
id="startdate" value="#{graph.startdate }" showOn="button"
required="true" />
<h:outputLabel for="enddate" value="Enddate: " />
<p:calendar disabledWeekends="false" size="10" pattern="dd.MM.yyyy"
showOtherMonths="true" maxlength="10"
mindate="#{formconst.MINDATE }" maxdate="#{formconst.MAXDATE }"
showButtonPanel="true" navigator="true" readOnlyInputText="true"
id="enddate" value="#{graph.enddate }" showOn="button"
required="true" />
<h:outputLabel for="filter" value="Filter: " />
<p:selectOneMenu value="#{graph.filter }" id="filter">
<f:selectItems value="#{formconst.GENERALFILTER}" />
</p:selectOneMenu>
</p:panelGrid>
<p:separator />
<p:panelGrid columns="2">
<p:commandButton value="Submit" update="#all"
action="#{ graph.updateChart }" />
<p:commandButton value="Reset" update="#all"
action="#{ graph.resetChart }" />
</p:panelGrid>
</h:form>
</p:panel>
</ui:define>
<ui:define name="content">
<h:form id="linechart">
<p:lineChart value="#{graph.cartesianChartBean.chartmodel }"
enhancedLegend="true" legendPosition="nw" xaxisAngle="50" />
</h:form>
</ui:define>
The same happens when I change SessionScoped to ViewScoped or RequestScoped.
I can change the values only one time.
I use primefaces 3.2 with apache myFaces 2.0.2 on WebSphere Application Server 8.0
Best Regards Veote