refreshing a datatable - jsf

dudes, does any of you know how to do this?
i have a page that has a datatable on it. it has a button to delete a row. the button works as expected, when you click it, it will delete the selected row/s. i also have another button that opens a popup window where you search for items and them add them to the said datatable. i am having a hard time figuring out how to refresh the datatable once you click the "select" button on the popup window.
my solution is having a hidden button that will refresh the datatable. it works when i litterally click it. but when i trigger the click event on the popup window using javascript, it doesnt always work. sometime it refreshes, sometimes it doesnt.
what's actually the best way to refresh a datatable?

If you use JSF2.0, there is an option to update part of your application with
<h:form>
...
...(here you have the binding data)
<h:commandButton action="#{yourbean.updateRows}" >
<f:ajax render="tableName" />
</h:commandButton>
</h:form>
EDITED
If you want to invoke it from JAVASCRIPT use:
document.getElementById('elementName').click();

How are you accessing your DataTable in the popup window ? by keeping it in some session variable and in you parent page are you displaying the datatable through some UI Component like GridView ? In that case you can reload your parent window from where you opned the popu windo through javascript. E.g. window.opener.location.reload();

I can think of .. Datatable.AcceptChanges(); But that's for C#..

Related

p:commandButton show other button after this button clicked

Hi I have a JSF "Register.xhtml" inside I have two Primefaces Command Buttons:
<p:commandButton id="registerButton"
action="#{registerController.register()}" rendered="#{!registerController.IsUserRegistered()}" />
<p:commandButton id="unregisterButton"
action="#{registerController.unregister()}" rendered="#{registerController.IsUserRegistered()}"/>
It works if I manually refresh the page.
I want a method to show the unregisterButtonand hiding the registerButton after I call the
registerController.register() function by clicking on the register Button.
You need to refresh the part of the page where the second button is after the click on the first button.
With Primefaces you can use PartialSubmit, http://www.primefaces.org/showcase/ui/ajax/partialSubmit.xhtml

Disable dynamically created button from managed bean

I have a problem with dynamicaly created CommandButton in Primefaces.
I want to disable button after user click (submit). I've tried in two ways:
By adding widgetWar (commandButton.setWidgetVar("pony");) property to my commandButton and setting onclick behaviour (commandButton.setOnclick("PF('pony').disable();");). WidgetVar property is unique among all elements on page. This approach doesn't work - my button after click turns into disable and then immediately goes back to enable.
From managedBean by calling setDisabled method on button UiComponent ((CommandButton) component).setDisabled(true);. This also doesn't work.
Is there any other way to disable CommandButton from Java code or am I missing something?
I'm generating my page dynamically so I cannot use disabled property in xhtml.
I also set my commandButton update property to update parent p:outputPanel.
Thanks in advance.
my button after click turns into disable and then immediately goes back to enable.
That will happen if the ajax update covers the button itself. Just exclude the button from it and specify only the parts which really need to be updated.
you can a declare field in your bean
boolean disable = false;
after click on button in your listener:
disable = true;
in your button use this code:
<p:commandButton id="x" disabled="#{bean.disable}" update="#form:x" />

How to upgrade select one of my other xhtml page?

I have a jsf form of registration that usually works on a select one menu is displayed a list of vehicles, in case the user needs to register a new vehicle for the issuance of the note he clicks one side of the select menu and opens a dialog to register .
Until then everything is working but when I close the dialog the registered vehicle only appears after typing F5. How can I do to update the select one menu. It is important to point out that the registration of the notes and open dialog xthmml are different pages, so do not know how.
Try putting styleClass="vehicles" to <p:selectOneMenu>, and update="#(.vehicles)" on <p:commandButton> in the dialog (the button in the dialog that adds the new vehicle). If everything is wired up correctly in the managed bean (the list that select one menu displays is updated), you should see the new car in the list.
<p:selectOneMenu styleClass="vehicles" ...>
<p:commandButton update="#(.vehicles)" ...>

rich:popupPanel form remembering old values

I have a JSF page powered by a session-based backing bean. The page also includes a rich:popupPanel modal window which contains a form with couple of cascading elements and a couple of text boxes. The first time I input values into the form and press the Cancel button, the popup disappears. But when I click on the commandButton which displays the popup again, the drop-downs and input text boxes show the previously input values, even though I reset the underlying properties in the backing bean. It is as though the JSF UI elements' state is being cached, because for debugging purposes I print the underlying property values at the bottom of the popup and those are null (or empty).
Why is this happening and is there an effective way to reset the form UI elements' state?
Showing and hiding is just flipping between visible and invisible state. You need to rerender the popup every time you open it if you want it to use the current values.
Edit: Sample code
<a4j:commandButton render="popupPanelId" execute="#this"
oncomplete="#{rich:component('popupPanelId'}.show()" value="Click me" />

how to refresh the whole tabpanel in jsf

I am using richfaces and jsf.
I am using <rich:tabpanel> to create the tabs.
I have taken 4 tabs.
In 1st tab , one refresh button is available. If I click that button, the whole tabpanel is refreshed. whatever the data is kept in tab2, tab3 and tab4 will be clear.
use <a4j:support reRender="tabPanelComponentId"> inside your button, or use <a4j:commandButton reRender="tabPanelComponentId" />

Resources