I have a button in JSF page which when clicked calls a method in the bean and return me all the rows present in the table. But when I am clicking the button the table is not getting refreshed. I am using a return listener in the button and binded the table with it.
<f:facet name="additionalToolbarButtons">
<af:toolbar>
<af:commandToolbarButton text="ShowAll"
actionListener="#{backingBeanScope.Bean.showAllRows}"
returnListener="#{backingBeanScope.Bean.refreshTable}"/>
</af:toolbar>
</f:facet>
Table binding -
binding="#{backingBeanScope.Bean.refreshTable}">
Java Code -
public void refreshTable(ReturnEvent returnEvent) {
// Add event code here...
AdfFacesContext ctx = AdfFacesContext.getCurrentInstance();
ctx.addPartialTarget(getRefreshTable());
}
public RichTable getRefreshTable() {
return refreshTable;
}
When I am manually refreshing the page then I can see all the rows in table. I have recently started working in ADF. Can someone please guide me
Which exact version of JDev you are using?
Try to ppr the parent of the table.
Related
I have a prime faces wizard and a dataTable, my page successfully go to the next wizard tab if I selected an item from the dataTable, but my problem is when inserting a new data to the dataTable I want the wizard to go to the next tab if the insert was successful, any suggestions please?
You can use the client side API from backing bean, after the insert was successful.
Add a widgetVar to your wizard
<p:wizard widgetVar="wiz" ...>
...
<p/wizard>
Add the client execute, after the data is successfully inserted.
public void insertData() {
// Insert data
if (successfully) {
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('wiz').next()");
}
}
This question already has answers here:
Creating master-detail pages for entities, how to link them and which bean scope to choose
(2 answers)
Closed 7 years ago.
I have two pages:
listMedicalJourneys.xhtml
listAffectedEmployees.xhtml
From the first page:
<h:form>
<h:commandLink action="#{MedicalJourneyController.listAffectedEmployees()}" value="Manage">
<f:setPropertyActionListener value="#{element.id}" target="#{MedicalJourneyController.medicalJourneyId}" />
</h:commandLink>
</h:form>
The #RequestScoped bean #{MedicalJourneyController} has this method:
public String listAffectedEmployees() {
MedicalJourney m = medicalJourneyBean.getMedicalJourneyById(medicalJourneyId);
setMesList(new ArrayList<MedicalJourneyEmployeeService>(m.getMedicalJourneyEmployeeServices()));
setSelectedMedicalJourney(m);
return "listAffectedEmployees.faces?faces-redirect=true";
}
When I use the redirect to change URL, the next page doesn't show the selected value.
if i understand you right, you want to select an item inside one view, and display its SubItems in the next View. if this is the Case then, there are seviral ways to acheave this, here i will show you a way based on your Concept/Code above, so lets assume the following:
listMedicalJourneys.xhtml the View where you select an Item
listAffectedEmployees.xhtml the view Where you display SubItems of the preselected Item
and i assume that you have for each View its own Controller/ManagedBean,
so lets call the first one medicalJourneysManager and for the second view affectedEmployeesManager, both are requestScoped Beans
in the medicalJourneysManager your "selection Methode" action event should only get the selected ItemId, and pass this selected id to the next Page. Next Page Controller should then load the List of SubItems. Because a requestScoped Bean is only available during this single request, and as soon as you navigate anywhere, your bean will be reinitialized, that means the loaded data is lost at this moment.
so in your medicalJourneysManager define some ActionMethode like this:
//JSF 2.+
public String selectMedicalJourny(int medicalJourneyId) {
// do what ever you want before redirect, i.e. any validations, ...etc if required
return "listAffectedEmployees.faces?faces-redirect=true&medicalJourneyId="+medicalJourneyId;
}
this will redirect you to the next View where you display a list of AffectedEmployees
this new View needs its Controller "affectedEmployeesManager" to load the list of affectedEmployees.
so in the this managed Bean do something like this:
#PostConstruct
private void init(){
try{
String medicalJourneyId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("medicalJourneyId");
// now do whatever you want with it, load its subNodes/affectedEmployeesList, ...etc
MedicalJourney m = medicalJourneyBean.getMedicalJourneyById(medicalJourneyId);
setMesList(new ArrayList<MedicalJourneyEmployeeService>(m.getMedicalJourneyEmployeeServices()));
setSelectedMedicalJourney(m);
}catch(Exception e){
e.printStackTrace();
}
}
a simpler alternative to commandLink is using a direct link with that param without any action commands.
here is a helpfull link.
I have dataTable for editing users.
I have commandLink in each row for opening modal dialog with selected user data for editing.
On that dialog I have commandButton for saving user.
I have a problem refreshing dataTable and displaying new edited values for user.
<p:commandButton value="Save" action="#{usersBean.updateUser()}" onclick="PF('editUserDlg').hide();" update=":adminForm:adminTabView:usersDataTable" styleClass="ui-priority-primary" style="float: right;" />
I followed BalusC answer on subject finding out id of component and have no errors in server log.
When I click on Save button I call backing bean method:
public void updateUser() {
int userId = selectedUserView.getId();
User user = adminSessionBean.getMe(userId);
try {
updateUser(user);
LOG.info("User seccessfully updated.");
} catch (Exception exc) {
String message = "Error updating user: " + exc.getMessage();
LOG.error(message);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, message, null));
}
}
and edited user is saved correctly (I've checked in database). Problem is that I don't see new edited user values in dataTable after modal dialog is closed.
When I refresh page I see new values for user.
When I add call #PostConstruct init() method after updateUser(user); I see the changed values in dataTable, but I am not sure if this is the correct approach.
Thanks Kukeltje,
I'll go with calling init() after updateUser() method.
I wouldn't call the init method, this method should only be called after the bean is constructed as the annotation states.
Try calling a remoteCommand instead of closing your dialog directly which refreshes the dataTable. After that you could close the dialog from that command. Something like this.
<p:remoteCommand name="updateContent" update="table"
oncomplete="PF('dialog').hide();" />
Didn't tried this solution directly, but I think that should work. I used this approach for a similar problem.
EDIT: As Kukeltje states, you also have to refresh your dataModel so that the dataTable receives the new data. You could add an actionListener to the remoteCommand to do that.
We are using primefaces 5.1 in the project, in a p:calender after I select a date in the pop up calendar window, the text field will lose focus. The issue caused by this is you can not use tab to focus on next field in the form, it will go to the first element in the form instead. Even the primefaces showcase has this issue:
http://www.primefaces.org/showcase/ui/input/calendar.xhtml
Any suggestion on how to solve it ?
After some search and local testing while waiting for the answer. I comes out a way to fix this.
It is actually a JQuery UI bug (or may be not as it been there since the first version and still got no official fix!). We need to override the jQueryUI datepicker used by primefaces. Make sure to put the import for that custom script in the last facet so it will be pick up as a resource in the last order.
<f:facet name="last">
<h:outputScript name="default/js/customDatePicker.js" />
</f:facet>
Inside the JavaScript code I do the following to merge the _selectDate into datepicker(the change is in the last else) which will over ride the orginal _selectDate without changing the others. It will do the trick for me on Chrome and IE11.
$(document).ready(function () {
$.extend(jQuery.datepicker, {
_selectDate: function (id, dateStr) {
var onSelect,
target = $(id),
inst = this._getInst(target[0]);
dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
if (inst.input) {
inst.input.val(dateStr);
}
this._updateAlternate(inst);
onSelect = this._get(inst, "onSelect");
if (onSelect) {
onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
} else if (inst.input) {
inst.input.trigger("change"); // fire the change event
}
if (inst.inline) {
this._updateDatepicker(inst);
} else {
this._hideDatepicker();
inst.input.focus();
}
}
});
});
I have 2 screens in my JSF 2.0 application. Screen 1 searches for students and lists students in a table. The student name in the results table is a link to the student details page (screen 2).
My managed bean:
#SessionScoped
public class TestController {
private Student studentOnUI; // Student being viewed on the UI
// synchronized public getters and setters
public String viewStudentAction(String studentId) {
this.studentOnUI = getStudentFromDB( studentId );
return "studentDetailedPage";
}
public synchronized String clearSearchAction() {
this.studentOnUI = null;
return "studentSearchPage";
}
screen 1 xhtml snippet
<!-- search fields -->
<h:commandButton
value="Clear Search"
action="#{testController.clearSearchAction()}"/>
<!-- Search button -->
<!-- search results table -->
Screen 2 xhtml snippet
<h:outputText value="#{testController.studentOnUI.name}" />
<h:dataTable
value="#{testController.studentOnUI.subjects}"
var="subject">
<h:outputText value="#{subject.score}"/>
</h:dataTable>
I face the following issue:
After running search, user clicks on
a student name (to move into screen
2)
When the render response phase of
screen 2 is in progress (which has
EL references to
testController.studentOnUI), He
clicks on clear button (without waiting for the first request to complete). Now the
thread handling the clear request
sets testController.studentOnUI to null and
the first thread that is in render
response phase throws
NullPointerException when it
evaluates
{testController.studentOnUI.*}.
Although the managed bean handles synchronization (correctly?) it does not solve the concurrency issue here because, the following could happen
Thread 1 (handling request to navigate to screen 2) - evaluates #{testController.studentOnUI.name} and happily renders the value. And then exits the testController.getStudentOnUI() synchronized method. So thread 1 no longer has the lock on the controller instance (in session scope). context switch happens.
Thread 2 (handling request to clear
search results) - does
testController.studentOnUI = null in
clearSearchAction(). context switch
happens.
Thread 1 - evaluates the next EL in the page (#{testController.studentOnUI.subjects}) and throws a NullPointerException (as testController.studentOnUI is now null).
Appreciate any pointers on what I am doing wrong with this approach or if a different approach needs to be adopted here.
this is really strange behaviour but then i would rather disable the link on the first page with JavaScript to make it "unclickable".
try with jQuery:
1 button: $('#button').attr("disabled", true);
2 link: $('a.something').click(function(e) {
e.preventDefault();
});
I'm not sure about the synchronization in the backing bean since the JSF Controller has to put the lock on your Student object, not the clear method. Am I wrong?