I have a scenario where I need to apply default selection on one radio button item where radio button list is being populated from a data binding(of static data) and the data control is from a bean class.
<af:selectOneRadio value="#{bindings.si_DmndType.inputValue}"
required="#{bindings.si_DmndType.hints.mandatory}"
shortDesc="#{bindings.si_DmndType.hints.tooltip}" id="sor1"
layout="horizontal" >
<f:selectItems value="#{bindings.si_DmndType.items}" id="si1"/>
<f:validator binding="#{bindings.si_DmndType.validator}"/>
</af:selectOneRadio>
You can set a default value for si_DmndType attribute - in your view object.
For a bean data control, when I have static values for it I need to go at pageDef.xml file -> selecting the variable and updating the DefaultValue attribute of the variable. Basically for a static data source(for bean data control) I need to manually insert DefaultValue which is typically not required when you choose from a Value Object i.e. VO.
Related
I have a local Web Application developed with JDK 8, JSF 2.2 (implementation provided by JBoss), Spring 4.2 and Primefaces 6.2
In the application, I have one XHTML page for edit some fields of an object that is instance of a class named SiepRoEncabezado. One of those fields is an instance of SiepRpaPescador.
Until yesterday, I had one <p:selectOneMenu> contained in a form that is contained in a modal dialog in order to select one SiepRpaPescador object. The modal itself has 2 submit <p:commandButton> (one for save the changes and one for clean the form) and some aditional input fields.
The modal is developed in such manner that it closes automatiquely when the data is successfully edited after I push the save button.
The modal with the <p:selectOneMenu> worked fine, but due to the fact that there are too many select items to be handled in terms of memory usage, I was forced to replace the <p:selectOneMenu> by the following component:
<p:autoComplete dropdown="true"
id="rpaAutoComplete"
value="#{correccionROBean.tmpPescador}"
var="itemRpa"
itemLabel="#{itemRpa.nmPescador.concat(' ').concat(itemRpa.nmPaterno).concat(' ').concat(itemRpa.nmMaterno)}"
itemValue="#{itemRpa}"
completeMethod="#{correccionROBean.filtrarRpa}"
minQueryLength="4"
maxResults="10"
forceSelection="true" />
There, tmpPescador is a bean in the Managed Bean CorreccionROBean.
The complete method there works fine and the selection items are displayed as desired.
However, after I select one item in the <p:autoComplete> component and push the button to save the changes, it does nothing at all. Also, it does not display an error message and it does not throw any exception. What is worst, if I try to debug the action listener method in the button to save changes, it does nothing, it's like the action listener method is not called at all.
I put an <p:ajax> tag hoping to solve the problem with no avail:
<p:autoComplete dropdown="true"
id="rpaAutoComplete"
value="#{correccionROBean.tmpPescador}"
var="itemRpa"
itemLabel="#{itemRpa.nmPescador.concat(' ').concat(itemRpa.nmPaterno).concat(' ').concat(itemRpa.nmMaterno)}"
itemValue="#{itemRpa}"
completeMethod="#{correccionROBean.filtrarRpa}"
minQueryLength="4"
maxResults="10"
forceSelection="true">
<p:ajax event="itemSelect" listener="#{correccionROBean.onRpaSelect}" update="rpaAutoComplete"/>
</p:autoComplete>
Here, when I select one item, the listener method is not triggered. When I try to debug the method, it's like the method is not called at all.
Finally, when I push the save button without selecting an item in the <p:autoComplete>, then and only then, the action listener method in the save <p:commandButton> is triggered.
What may cause this behaviour?
Thanks in advance.
EDIT
I added the field immediate="true" to the autocomplete component and that triggered the ajax submit method, but still cannot execute the save button action listener method
SOLVED.
Refeer to Melloware's answer and my reply to that answer for more details.
For those that are unfamiliar with Converters:
The interface Converter, defined in JSF's API, allows to convert the data inputted and outputted to a Auto Complete component (and some other JSF UI components as well and their sub-classes). This interface has two methods:
public Object getAsObject(FacesContext context, UIComponent component, String value): This method must return an Object that is instance of the same class as the value defined in the value field of the Auto Complete component (in my case, it returns a SiepRpaPescador object). You must handle exceptions in this method as it is called automatiquely in two situations:
When you input characters in the Auto Complete text field and the number of inputted characters are equal or greater than the value defined in the minQueryLength field of the Auto Complete component or it's default value if not specified (in my case, when I input 4 characters or more). In this case, the value parameter in this method will be the String you inputted. Notice that if you enabled dropdown (dropdown="true")as in my case and you push the dropdown button, this method is NOT called.
When you submit the form. In this case, the value will be the value of the labelValue field in the Auto Complete component (in my case, #{itemRpa.nrFolio}) converted to String using the toString method defined in the class that value is instance of (#{itemRpa.nrFolio} is an Integer, so the value will be converted using the Integer class' own implementation of toString()) or in the Object class if no implementation of toString() is defined.
public String getAsString(FacesContext context, UIComponent component, Object value): This method must return a String representation of the label value of each item to be displayed in the Auto Complete component. The parameter value is an instance of the same class as the value defined in the labelValue field of the Auto Complete component. This method is called automatiquely when the items are displayed (it doesn't matter if you inputted characters in the Auto Complete's text field or pressed the dropdown button if present) and it's called as many times as defined in the field maxResults (in my case, 10) in the Auto Complete, using the objects obtained from the returned list of the completeMethod (in my case, from each object in the list obtained from #{correccionROBean.filtrarRpa}, this method obtains it's nrFolio, as I stablished in the labelValue field of the AutoComplete).
I hope this helps to you all
View looks like this:
form (can have only one checkbox selected)
----------------------------------------
checkbox_1 (on value change clears checkbox_1 and checkbox_2 values in the backing bean and updates form**. new checkbox_1value is set after all checkbox values are cleared)row_checkbox_1(rendered only ifcheckbox_1` is checked)
checkbox_2 (on value change clears checkbox_1 and checkbox_2 values in the backing bean and updates form**. new checkbox_2value is set after all checkbox values are cleared)row_checkbox_2(rendered only ifcheckbox_2` is checked)
saveButton (on click updates formand a separate messages component)
---------------------------------
Lets state checkbox_1 is selected meaning that row_checkbox_1 components is also visible. Also there are errors in row_checkbox_1 fields.
After saveButtonis pressed the errors are displayed.
Problem: pressing/checking checkbox_2 updates backing bean - checkbox_1 value field in the backing bean gets set to false (debugged and verified by looking at getter) and checkbox_2 value field is set to true. However view does not update correctly since checkbox_1 is rendered as checked while row_checkbox_1 is not rendered at all. Remember row_checkbox_1 is rendered only if checkbox_1 is true. checkbox_2 is rendered and checked as it should be and row_checkbox_2 fields are visible as it should be.
I'm doing all this in PrimeFaces 6.0
ajax attribute restValues="true" helped. Maybe someone could do an explanation why this situation occurs? Would gladly give answer point to them!
jsf adf....
My code in adf jsf.
this code creates a choice list form the model....and I want that if user selects the perticular customer id from the select list the related address will be displayed in the next line. any idea and solution how to add or bind data control(for address attribute) for such that when the select item vales from the select list generated from the binded model(id attribute only) is selected then the related adrress will get displayed.
<af:selectOneChoice label="#{bindings.InvView1.label}" id="soc1"
binding="#{backingBeanScope.backing_inv.soc1}"
value="#{bindings.InvView1.inputValue}"
required="#{bindings.InvView1.hints.mandatory}">
<f:selectItems value="#{bindings.InvView1.items}" id="si2"
binding="#{backingBeanScope.backing_inv.si2}" />
</af:selectOneChoice>
</af:selectOneChoice>
You can use a bean with a setter (customer ID) that gets activated upton customer selection.
You can use a navigation list.
Like this:
https://blogs.oracle.com/shay/entry/the_navigation_list_select_som
I have a Facelets page with a h:dataTable. In each row of the h:dataTable, i am displaying some enabled and disabled services of a user.Here is the model object
public class ServiceList {
private long userId;
private long serviceGroupId;
private String serviceGroupName;
private long serviceId;
private String serviceName;
private String serviceUrl;
private String serviceState;
public UserServiceList() {
}
//getters and setters....
}
These are the details i am displaying in a single row of a dataTable.
serviceState in the above model object is either 'Y' or 'N'.
my problem is the application user should be able to update the servicestate of all rows of a dataTable at once and update them in the backend database.
1)what additional JSF component do i need to use inside dataTable to achive this? I am thinking of adding one more column with h:selectOneradio
2)How do i get which rows are selected and what status they have set?
I am kind of newbee to JSF.Please help.
Update:At present what i am having is two buttons namely 'Disable Service' and 'Enable Service' in the footer section of the table.
Onclick of Disable Service i am navigating to another page where i show the application user the list of enabled services to disable
And vice-versa for Enabled service button click.
So, let's say you in your Managed Bean you have a list of services you would like the user to edit:
List<Service> serviceList;
You take this List to be displayed in the data table.
<h:dataTable value="#{yourManagedBean.serviceList}" ... >
Then you can implement a commandButton that has either an action or an actionListener which points to a certain method of your managed bean, like this:
<h:commandButton action="#{yourManagedBean.saveAllAction}" ... >
And the corresponding method to save 'em all is quite straight-forward. You iterate over the managed bean field serviceList and persist every single entry (however you persist them, like calling the EntityManager when using Hibernate or any DAO class in between, you name it.)
Concerning the service status: I'd preferably use a selectBooleanCheckbox for toggling the status, since it's probably a boolean value.
Edit after comment 1:
You have the serviceStatus in your Service class. Currently it's a string, but I suppose it should be boolean to toggle active/inactive. If this property is displayed by the selectBooleanCheckbox it is automatically changed in your corresponding Java class. So calling getServiceStatus() returns true or false, depending on what is selected in the frontend. If you persist the whole Service object then, you don't have to do anything because any modifications made in the frontend HTML elements are automatically projected to the Java object behind it.
We are using Oracle ADF/JSF 1.1 to show search results in a table starting with a radio button. Our requirement is to show search result with one of the <af:tableSelectOne> radio buttons preselected depending on the database value match. However, I am unable to preselect a radio button.
Here is the code snippet:
<f:facet name="selection">
<af:tableSelectOne text="Select" autoSubmit="true" id="radiobtn" />
</f:facet>
How can I preselect it?
I believe that you should change your selection strategy :)
As far as know you can't configure selection property of af:tableSelectOne. It is nested in facet of af:table component, component which drives af:tableSelectOne behaviour. So, in order to select certain row, you should check for property "selectionState" on af:table (I suppose you're using ADF 10.x version)
<af:table value="#{bindings.DemoView1.collectionModel}"
var="row" rows="#{DemoView1.DemoView1.rangeSize}"
first="#{bindings.FilterView1.rangeStart}"
emptyText="#{bindings.DemoView1.viewable ? \'No rows yet.\' : \'Access Denied.\'}"
selectionState="#{bindings.DemoView1.collectionModel.selectedRow}"
selectionListener="#{bindings.DemoView1.collectionModel.makeCurrent}"
id="table1"
I'm sure you'll find it. To get an idea, just drag'n'drop some table object to your jsf page from data control (i.e. view object if you are using ADF Business Components based Data Controls ) and choose table as wanted component, and last step , on that table choose selection option (you should get popup window after drag'n'drop).When you configure your af:table component that way, you can control selection by changing your view object's current row . (View object to which af:table is attached)
Regards