aspose file tools*
The moose likes JSF and the fly likes Updating a form in primefaces when a selection is made in the datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Updating a form in primefaces when a selection is made in the datatable" Watch "Updating a form in primefaces when a selection is made in the datatable" New topic
Author

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

Derrick Albers
Greenhorn

Joined: Nov 01, 2010
Posts: 20
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:
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

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.
David Norris
Greenhorn

Joined: May 04, 2009
Posts: 3
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

Joined: May 12, 2009
Posts: 218
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.
sardar waqas ahmed
Greenhorn

Joined: Oct 19, 2011
Posts: 16
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">

<hutputLabel 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" />
<hutputLabel value=" " class="field-title" />
<hutputLabel value=" " class="field-title" />
<hutputLabel value=" " class="field-title" />

<hutputLabel 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">
<hutputLabel 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" />

<hutputLabel 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" />

<hutputLabel 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()"/>
Ruz Li
Greenhorn

Joined: Nov 29, 2007
Posts: 10
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.


SCJP, SCWCD
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16070
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ruz Li
Greenhorn

Joined: Nov 29, 2007
Posts: 10
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

Joined: Jun 25, 2001
Posts: 16070
    
  21

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

Joined: Nov 29, 2007
Posts: 10
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

Joined: Jun 25, 2001
Posts: 16070
    
  21

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! :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating a form in primefaces when a selection is made in the datatable