Menu
Ajax behavior was introduced firstly by the jsf 2 specification, and Primefaces is one of those libraries built on, so you will not find a big difference between standard jsf ajax component f:ajax and Primefaces ajax component p:ajax except the latter used with the Primefaces components.
Ranch Hand
posted 6 years agoI am trying to do JSF/primefaces ajax update on the datatable on click of a command link using which i am deleting the records.On clicking the command link i the database get supdated but the datatable doesn't get refreshed even if i use update='@form' attribute.Any guidance on how to solve this problem would be very helpful.
My JSF code snippet
The variable lpcIdData is of the type of the class that implements DataModel.
Below is the Managed bean snippet that contains deleteRecords method.Managed bean is of RequestScoped
The variable selectedRows is the selection attribute of the datatable
My JSF code snippet
The variable lpcIdData is of the type of the class that implements DataModel.
Below is the Managed bean snippet that contains deleteRecords method.Managed bean is of RequestScoped
The variable selectedRows is the selection attribute of the datatable
Bartender
posted 6 years agoWhy are updating the '@form'? Is there an element with? I doubt.
In the p:commandLink you should use update='lpcDataTable'
Also in your deleteRecords() method, is it necessary to create a new connection every time? Why can't the connection be outside the for loop? And you should close such connection when done.
In the p:commandLink you should use update='lpcDataTable'
Also in your deleteRecords() method, is it necessary to create a new connection every time? Why can't the connection be outside the for loop? And you should close such connection when done.
Ranch Hand
posted 6 years agoThank you Tsang for your reply,but the result is the same, the datatable is not getting refreshed :( , but i need to manually refresh the web page.
Bartender
posted 6 years agoDoes the code get inside the for loop?
Is the method getting the 'correct' record for delete? Because I don't see any get values from request map stuff.
Further check, your for loop seems to be deleting each record one by one!!
Since you are using a link, try passing in the id of that row or some key instead of looping the entire collection/list or whatever.
If everything is working in the delete method, try reloading the data model.
Is the method getting the 'correct' record for delete? Because I don't see any get values from request map stuff.
Further check, your for loop seems to be deleting each record one by one!!
Since you are using a link, try passing in the id of that row or some key instead of looping the entire collection/list or whatever.
If everything is working in the delete method, try reloading the data model.
Greenhorn
posted 8 years agoI have a prime panel to display employee information and a datatable next to it, the datatable is getting populated and I am tyring to update the panel with that employee information when a row is selected. I am using dataTable and onRowSelect is getting the information that I want from the Backing bean but I can never get the inputtext fields to populate???
This is the page:
And this is my backing bean:
This is the page:
And this is my backing bean:
![Primefaces javascript Primefaces javascript](/uploads/1/2/5/8/125866343/925499276.png)
Ranch Hand
posted 8 years agoAbout 10 times a week I see someone on here or somewhere else who have multiple forms on a single
page and every time they're in trouble.
Use one form with prependId='false' and everything will start to become a lot simpler. Read up about
naming containers also.
Brendan.
![Jsf update input text ajax Jsf update input text ajax](http://i.stack.imgur.com/pGjes.jpg)
Greenhorn
posted 8 years agoRight and never mind separating concerns like putting parameters and returned data in separate forms.
While we're at it lets get rid of templates too. Just put everything in one page.
Why should primeFaces force me to stuff everything into one form? If it would not break this feature then maybe you wouldn't see this 10 times a week. It's not our fault PF breaks it.
Other frameworks work perfectly with multiple forms.
While we're at it lets get rid of templates too. Just put everything in one page.
Why should primeFaces force me to stuff everything into one form? If it would not break this feature then maybe you wouldn't see this 10 times a week. It's not our fault PF breaks it.
Other frameworks work perfectly with multiple forms.
Ranch Hand
posted 8 years agoHi David, my response was probably a little unhelpful, although I was genuinely trying to assist. I
stand by my original comment in that the use of multiple forms, whilst permissible (when not nested)
tends to cause more problems than it solves. I think it unlikely that PrimeFaces is causing the
problems you're experiencing, although there are some idiosynchracies related to referring to
component ids from within a p:datatable (i.e. you have to use form:compid when you otherwise
wouldn't need to). If you are still experiencing problems perhaps we could try and narrow down the
problem with a minimalist code structure?
Regards,
Brendan.
stand by my original comment in that the use of multiple forms, whilst permissible (when not nested)
tends to cause more problems than it solves. I think it unlikely that PrimeFaces is causing the
problems you're experiencing, although there are some idiosynchracies related to referring to
component ids from within a p:datatable (i.e. you have to use form:compid when you otherwise
wouldn't need to). If you are still experiencing problems perhaps we could try and narrow down the
problem with a minimalist code structure?
Regards,
Brendan.
Greenhorn
posted 8 years agoplease tell me i have two form and cant update the command button whic is disable in form 2.i try alot but cant find a solution my code is below.
<h:form>
<h:panelGrid columns='6' cellpadding='7' cellspacing='2'
columnClasses='a,b,c,d'
rowClasses='plainRow,shadedRow'>
<h:outputLabel value='Marital Status : ' />
<p:selectOneMenu required='true'
value='#{personalInfoBean.maritialStatusPerson}'>
<f:selectItem itemLabel='Select Maritial Status'></f:selectItem>
<f:selectItem itemLabel='Single' itemValue='Single' />
<f:selectItem itemLabel='Married' itemValue='Married' />
<f:selectItem itemLabel='Widower' itemValue='Widower' />
<f:selectItem itemLabel='Divorce' itemValue='Divorce' />
<p:ajax event='blur' update='msg36' />
<p:ajax event='change' update='childaddbtn'
listener='#{personalInfoBean.handleStatusChange}' />
</p:selectOneMenu>
<p:message for='maritalstatus' display='icon' />
<h:outputLabel value=' ' />
<h:outputLabel value=' ' />
<h:outputLabel value=' ' />
<h:outputLabel value='Name next of Kin : ' />
<p:inputText
value='#{personalInfoBean.hrNextOfKin.nameNextOfKin}'
required='true'>
<p:ajax event='blur' update='msg37' />
<f:validateLength minimum='3' maximum='15'></f:validateLength>
</p:inputText>
<p:message for='nok' display='icon' />
<h:commandButton value='Save' action='#personalInfoBean.saveHrNOK}' />
</h:form>
<h:form>
<p:dialog header='Children' widgetVar='dlgchild'>
<h:panelGrid columns='3' cellpadding='5'>
<h:outputLabel value='Name : ' />
<p:inputText value='#{personalInfoBean.nokChild.childrenName}'
required='true'>
<p:ajax event='blur' update='msgchld' />
<f:validateLength minimum='3' maximum='25'></f:validateLength>
</p:inputText>
<p:message for='chlname' display='icon' />
<h:outputLabel value='Gender :' />
<p:selectOneMenu required='true'
value='#{personalInfoBean.nokChild.childrenGender}'>
<f:selectItem itemLabel='Select Gender' itemValue=' />
<f:selectItem itemLabel='Male' itemValue='Male' />
<f:selectItem itemLabel='Female' itemValue='Female' />
<p:ajax event='blur' update='msgchldGnd' />
</p:selectOneMenu>
<p:message for='chldgender' display='icon' />
<h:outputLabel value='Age :' />
<p:inputText value='#{personalInfoBean.nokChild.childrenAge}'
required='true'>
<p:ajax event='blur' update='msgchldage' />
<f:validateLength minimum='1' maximum='3'></f:validateLength>
</p:inputText>
<p:message for='chldage' display='icon' />
<f:facet name='footer'>
<p:commandButton value='Save' update='nokChildList'
oncomplete='handleAddChildrenRequest(xhr, status, args)'
actionListener='#{personalInfoBean.setNOKChild}' />
</f:facet>
</h:panelGrid>
<div>
<p:commandButton disabled='#{personalInfoBean.addButtonChildren}' value='Add Children'/></div>
<h:commandButton value='Save' action='#{personalInfoBean.saveHrNOK}' />
</h:form>
when i change dropdown of from one the button on second form should be enabled by default that button is disabled how i do it.this button is not getting enabled when i change the dropdown
<p:commandButton disabled='#{personalInfoBean.addButtonChildren}' value='Add Children'/>
<h:form>
<h:panelGrid columns='6' cellpadding='7' cellspacing='2'
columnClasses='a,b,c,d'
rowClasses='plainRow,shadedRow'>
<h:outputLabel value='Marital Status : ' />
<p:selectOneMenu required='true'
value='#{personalInfoBean.maritialStatusPerson}'>
<f:selectItem itemLabel='Select Maritial Status'></f:selectItem>
<f:selectItem itemLabel='Single' itemValue='Single' />
<f:selectItem itemLabel='Married' itemValue='Married' />
<f:selectItem itemLabel='Widower' itemValue='Widower' />
<f:selectItem itemLabel='Divorce' itemValue='Divorce' />
<p:ajax event='blur' update='msg36' />
<p:ajax event='change' update='childaddbtn'
listener='#{personalInfoBean.handleStatusChange}' />
</p:selectOneMenu>
<p:message for='maritalstatus' display='icon' />
<h:outputLabel value=' ' />
<h:outputLabel value=' ' />
<h:outputLabel value=' ' />
<h:outputLabel value='Name next of Kin : ' />
<p:inputText
value='#{personalInfoBean.hrNextOfKin.nameNextOfKin}'
required='true'>
<p:ajax event='blur' update='msg37' />
<f:validateLength minimum='3' maximum='15'></f:validateLength>
</p:inputText>
<p:message for='nok' display='icon' />
<h:commandButton value='Save' action='#personalInfoBean.saveHrNOK}' />
</h:form>
<h:form>
<p:dialog header='Children' widgetVar='dlgchild'>
<h:panelGrid columns='3' cellpadding='5'>
<h:outputLabel value='Name : ' />
<p:inputText value='#{personalInfoBean.nokChild.childrenName}'
required='true'>
<p:ajax event='blur' update='msgchld' />
<f:validateLength minimum='3' maximum='25'></f:validateLength>
</p:inputText>
<p:message for='chlname' display='icon' />
<h:outputLabel value='Gender :' />
<p:selectOneMenu required='true'
value='#{personalInfoBean.nokChild.childrenGender}'>
<f:selectItem itemLabel='Select Gender' itemValue=' />
<f:selectItem itemLabel='Male' itemValue='Male' />
<f:selectItem itemLabel='Female' itemValue='Female' />
<p:ajax event='blur' update='msgchldGnd' />
</p:selectOneMenu>
<p:message for='chldgender' display='icon' />
<h:outputLabel value='Age :' />
<p:inputText value='#{personalInfoBean.nokChild.childrenAge}'
required='true'>
<p:ajax event='blur' update='msgchldage' />
<f:validateLength minimum='1' maximum='3'></f:validateLength>
</p:inputText>
<p:message for='chldage' display='icon' />
<f:facet name='footer'>
<p:commandButton value='Save' update='nokChildList'
oncomplete='handleAddChildrenRequest(xhr, status, args)'
actionListener='#{personalInfoBean.setNOKChild}' />
</f:facet>
</h:panelGrid>
<div>
<p:commandButton disabled='#{personalInfoBean.addButtonChildren}' value='Add Children'/></div>
<h:commandButton value='Save' action='#{personalInfoBean.saveHrNOK}' />
</h:form>
when i change dropdown of from one the button on second form should be enabled by default that button is disabled how i do it.this button is not getting enabled when i change the dropdown
<p:commandButton disabled='#{personalInfoBean.addButtonChildren}' value='Add Children'/>
Greenhorn
posted 6 years agoStuff everything in one big form is a bad idea. And also you should avoid using prependId='false'. It is abandoned. Brendan Healey wrote:
About 10 times a week I see someone on here or somewhere else who have multiple forms on a single
page and every time they're in trouble.
Use one form with prependId='false' and everything will start to become a lot simpler. Read up about
naming containers also.
Brendan.
About 10 times a week I see someone on here or somewhere else who have multiple forms on a single
page and every time they're in trouble.
Use one form with prependId='false' and everything will start to become a lot simpler. Read up about
naming containers also.
Brendan.
Saloon Keeper
posted 6 years agoYou don't really 'update' a form, you submit it. The updating can be done to any region up to and including the entire page (which is the default, unless you use AJAX).
Use a form to contain the greatest common denominator of all the control values that you wish to submit (and thus validate) in a single request. Use AJAX if you need to sub-divide the form into partial form requests. There are definitely times when multiple forms on a page are useful, such as cases where the main input source is a data table display and associated controls but you want to have an independent 'search' request that works without the overhead of uploading all the main form control values or being dependent on all of those values being valid (since even one invalid control value will cause the entire request to be rejected).
The AJAX 'render=' attribute is used to indicate what region(s) of the page to re-render after the submit is processed. Regions, as I said, can be anything renderable. Single controls, dataTables, panelGrids, and so forth.
Use a form to contain the greatest common denominator of all the control values that you wish to submit (and thus validate) in a single request. Use AJAX if you need to sub-divide the form into partial form requests. There are definitely times when multiple forms on a page are useful, such as cases where the main input source is a data table display and associated controls but you want to have an independent 'search' request that works without the overhead of uploading all the main form control values or being dependent on all of those values being valid (since even one invalid control value will cause the entire request to be rejected).
The AJAX 'render=' attribute is used to indicate what region(s) of the page to re-render after the submit is processed. Regions, as I said, can be anything renderable. Single controls, dataTables, panelGrids, and so forth.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Greenhorn
posted 6 years agoI agree that we can use AJAX to submit part of a big 'god form'. I am just afraid that if the form is too big, then we are immersed in complicated Ajax process. On the other hand, can we just process sever forms using AJAX, for example, in primefaces use process=':form1 :form2 :form3'? or just @all? Tim Holloway wrote:You don't really 'update' a form, you submit it. The updating can be done to any region up to and including the entire page (which is the default, unless you use AJAX).
Use a form to contain the greatest common denominator of all the control values that you wish to submit (and thus validate) in a single request. Use AJAX if you need to sub-divide the form into partial form requests. There are definitely times when multiple forms on a page are useful, such as cases where the main input source is a data table display and associated controls but you want to have an independent 'search' request that works without the overhead of uploading all the main form control values or being dependent on all of those values being valid (since even one invalid control value will cause the entire request to be rejected).
The AJAX 'render=' attribute is used to indicate what region(s) of the page to re-render after the submit is processed. Regions, as I said, can be anything renderable. Single controls, dataTables, panelGrids, and so forth.
Use a form to contain the greatest common denominator of all the control values that you wish to submit (and thus validate) in a single request. Use AJAX if you need to sub-divide the form into partial form requests. There are definitely times when multiple forms on a page are useful, such as cases where the main input source is a data table display and associated controls but you want to have an independent 'search' request that works without the overhead of uploading all the main form control values or being dependent on all of those values being valid (since even one invalid control value will cause the entire request to be rejected).
The AJAX 'render=' attribute is used to indicate what region(s) of the page to re-render after the submit is processed. Regions, as I said, can be anything renderable. Single controls, dataTables, panelGrids, and so forth.
Saloon Keeper
posted 6 years agoJSF is based on HTML and HTML has a fundamental limitation that exactly one and only one form can be submitted per request.
Don't worry about the form being too big. JSF uses POST, and that means that in effect the form data being uploaded looks like this:
Not much overhead there. Yes, the server can be set up to restrict how many bytes of data are acceptable, but these days, that would be a form so complex that the users would gouge their eyeballs out just trying to read it.
AJAX can be used to restrict the uploaded data from that form to a small subset, which minimizes overhead.
Don't worry about the form being too big. JSF uses POST, and that means that in effect the form data being uploaded looks like this:
Not much overhead there. Yes, the server can be set up to restrict how many bytes of data are acceptable, but these days, that would be a form so complex that the users would gouge their eyeballs out just trying to read it.
AJAX can be used to restrict the uploaded data from that form to a small subset, which minimizes overhead.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Greenhorn
posted 6 years agoI got suggestion from webpage. I know we can only submit one form each time. But what happens if we use process='@all' on a page with several forms? Should it bind all the values for us? Tim Holloway wrote:JSF is based on HTML and HTML has a fundamental limitation that exactly one and only one form can be submitted per request.
Don't worry about the form being too big. JSF uses POST, and that means that in effect the form data being uploaded looks like this:
Not much overhead there. Yes, the server can be set up to restrict how many bytes of data are acceptable, but these days, that would be a form so complex that the users would gouge their eyeballs out just trying to read it.
AJAX can be used to restrict the uploaded data from that form to a small subset, which minimizes overhead.
Don't worry about the form being too big. JSF uses POST, and that means that in effect the form data being uploaded looks like this:
Not much overhead there. Yes, the server can be set up to restrict how many bytes of data are acceptable, but these days, that would be a form so complex that the users would gouge their eyeballs out just trying to read it.
AJAX can be used to restrict the uploaded data from that form to a small subset, which minimizes overhead.
Saloon Keeper
posted 6 years agoUnfortunately, I haven't been able to work with the f:ajax tag. I have a significant investment in RichFaces 3, which doesn't support it and conversion to RichFaces 4 is not trivial :censored:
AJAX basically synthesizes a form dynamically, and if I read the docs correctly, the '@all' option essentially assembles a mega-form containing every control on the page :eek:
In theory, you could also supply the IDs of selected forms and that would work, too - constructing the mega-form from a union of the referenced forms, but there's no explicit illustration of that in the javadocs.
Try it and let us know! :)
AJAX basically synthesizes a form dynamically, and if I read the docs correctly, the '@all' option essentially assembles a mega-form containing every control on the page :eek:
In theory, you could also supply the IDs of selected forms and that would work, too - constructing the mega-form from a union of the referenced forms, but there's no explicit illustration of that in the javadocs.
Try it and let us know! :)
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.