• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Updating a form in primefaces when a selection is made in the datatable

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I 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:
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right 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.
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi 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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please 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 id="FamilyInfo">


<h:panelGrid columns="6" cellpadding="7" cellspacing="2"
id="grid3" columnClasses="a,b,c,d"
rowClasses="plainRow,shadedRow">

<h:outputLabel value="Marital Status : " class="field-title" />
<p:selectOneMenu required="true" id="maritalstatus"
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" id="msg36" display="icon" />
<h:outputLabel value=" " class="field-title" />
<h:outputLabel value=" " class="field-title" />
<h:outputLabel value=" " class="field-title" />

<h:outputLabel value="Name next of Kin : " class="field-title" />
<p:inputText
value="#{personalInfoBean.hrNextOfKin.nameNextOfKin}"
required="true" id="nok">
<p:ajax event="blur" update="msg37" />
<f:validateLength minimum="3" maximum="15"></f:validateLength>
</p:inputText>
<p:message for="nok" id="msg37" display="icon" />
<h:commandButton value="Save" action="#personalInfoBean.saveHrNOK}" class="defaultButton" />

</h:form>

<h:form id="nokChildForm">

<p:dialog header="Children" widgetVar="dlgchild" id="childDlg">


<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel value="Name : " />
<p:inputText value="#{personalInfoBean.nokChild.childrenName}"
required="true" id="chlname">
<p:ajax event="blur" update="msgchld" />
<f:validateLength minimum="3" maximum="25"></f:validateLength>
</p:inputText>
<p:message for="chlname" id="msgchld" display="icon" />

<h:outputLabel value="Gender :" />
<p:selectOneMenu id="chldgender" 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" id="msgchldGnd" display="icon" />

<h:outputLabel value="Age :" />
<p:inputText value="#{personalInfoBean.nokChild.childrenAge}"
required="true" id="chldage">
<p:ajax event="blur" update="msgchldage" />
<f:validateLength minimum="1" maximum="3"></f:validateLength>
</p:inputText>
<p:message for="chldage" id="msgchldage" 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 style="padding-left: 950px; padding-top: 28px">

<p:commandButton disabled="#{personalInfoBean.addButtonChildren}" value="Add Children" id="childaddbtn" onclick="dlgchild.show()"/></div>


<h:commandButton value="Save" action="#{personalInfoBean.saveHrNOK}" class="defaultButton" />


</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" id="childaddbtn" onclick="dlgchild.show()"/>
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stuff 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.

 
Saloon Keeper
Posts: 27489
195
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ruz Li
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I 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.

 
Tim Holloway
Saloon Keeper
Posts: 27489
195
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ruz Li
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I 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.

 
Tim Holloway
Saloon Keeper
Posts: 27489
195
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, 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! :)
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic