I have a Webapp with the Technologies: Wildfly, JSF, Primefaces
I have to select One Menus. The first Select One Menu loads all Warehouses and the second Select One Menu loads all Products which depends to the selected Warehouse.
I want to implemente the posibility, that i don't have necessarily choose a warehouse. I want to have the possibility that i dont select a warehouse, and logically if i dont choose a warehouse, the product Select one menu has to be disabled.
If i submit the form without a warehouse, it should be written in the database null for warehouse and also null for product.
My first attempt was to do the following entry in the select one menu of warehouse.
<f:selectItem itemLabel="---" itemValue="#{null}" value="#{null}"/>
Now, i don't know how to set the value of the warehouse select one menu to null, if i haven't choose a warehouse.
value="#{warehouseDataActions.actualWarehouse}" --> how to set to null
The second Problem is, that in the Ajax of the first select one menu i have to add the Attribute immediate = true. This Attribute is only neccassary for me if i add the following line. I don't know why ?
<f:selectItem itemLabel="---" itemValue="#{null}" value="#{null}"/>
So i have three questions:
1-How to set the actualWarehouse and .actualWriteservice.warehouseProduct to null ?
How to disable the product select one menu if i have already doesn not choose a warehouse (---) above ?
Why does my Ajax request in the warehouse select one menu does not function, if i add the item
<p:selectOneMenu style="width:151px"
value="#{warehouseDataActions.actualWarehouse}">
<f:converter converterId="ccWarehouseConverter" />
<f:selectItem itemLabel="---" itemValue="#{null}" value="#{null}"/>
<f:selectItems
value="#{warehouseDataActions.allWarehousesForProject}"
var="warehouse"
itemLabel="#{warehouse.warehouseName}"
itemValue="#{warehouse}" />
<p:ajax listener="#{warehouseProductDataActions.warehouseProductsForWarehouse}"
update="products" />
<p:panelGrid>
<p:outputLabel for="products">#{texts['writeservice.product']}</p:outputLabel>
<p:selectOneMenu id="products" style="width:151px"
value="#{writeserviceDataActions.actualWriteservice.warehouseProduct}">
<f:converter converterId="ccWarehouseProductConverter" />
<f:selectItems
value="#{warehouseProductDataActions.warehouseProductsResult}"
var="warehouseProduct" itemLabel="#{warehouseProduct.product.productName}"
itemValue="#{warehouseProduct}" />
</p:selectOneMenu>
</p:panelGrid>
You need to handle the --- case in your converter
(ccWarehouseConverter).
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || value.length() == 0 || value.equalsIgnoreCase("---")) {
return null;
}
return databaseService.getWarehouseByName(value);
}
To disable the selectOne
<p:panelGrid>
<p:outputLabel for="products">#{texts['writeservice.product']}</p:outputLabel>
<p:selectOneMenu id="products" style="width:151px" disabled="#{empty warehouseDataActions.actualWarehouse}"
value="#{writeserviceDataActions.actualWriteservice.warehouseProduct}">
<f:converter converterId="ccWarehouseProductConverter" />
<f:selectItems
value="#{warehouseProductDataActions.warehouseProductsResult}"
var="warehouseProduct" itemLabel="#{warehouseProduct.product.productName}"
itemValue="#{warehouseProduct}" />
</p:selectOneMenu>
</p:panelGrid>
In order to have your ajax update working, you must encapsulate both warehouse and products in a mother panel, and you update the mother:
<h:panelGroup id="motherPanel" layout="block">
<p:selectOneMenu style="width:151px" value="#{warehouseDataActions.actualWarehouse}">
<f:converter converterId="ccWarehouseConverter" />
<f:selectItem itemLabel="---" itemValue="#{null}" value="#{null}"/>
<f:selectItems
value="#{warehouseDataActions.allWarehousesForProject}"
var="warehouse"
itemLabel="#{warehouse.warehouseName}"
itemValue="#{warehouse}" />
<p:ajax listener="#{warehouseProductDataActions.warehouseProductsForWarehouse}"
update="motherPanel" />
</p:selectOneMenu>
<p:panelGrid>
<p:outputLabel for="products">#{texts['writeservice.product']}</p:outputLabel>
<p:selectOneMenu id="products" style="width:151px" disabled="#{empty warehouseDataActions.actualWarehouse}"
value="#{writeserviceDataActions.actualWriteservice.warehouseProduct}">
<f:converter converterId="ccWarehouseProductConverter" />
<f:selectItems
value="#{warehouseProductDataActions.warehouseProductsResult}"
var="warehouseProduct" itemLabel="#{warehouseProduct.product.productName}"
itemValue="#{warehouseProduct}" />
</p:selectOneMenu>
</p:panelGrid>
</h:panelGroup>
Related
I have a required select and my problem is that when the user selects an empty option (null) the validation jumps in and the listener call of the select is being skipped. Some components on my view are depending on this value so in case of null being selected the bean won't get actualized and the components don't change.
Example:
<h:form id="createForm">
<p:selectOneMenu id="produktCreateTypSelect"
converter="omnifaces.SelectItemsIndexConverter"
value="#{productController.selectedProduct.typ}" required="true">
<f:selectItem itemValue="#{null}" itemLabel="-- Select --" />
<f:selectItems var="productType" value="#{productController.findAllProducts()}"
itemLabel="#{productType.name}" itemValue="#{productType}" />
<p:ajax process="#this " event="valueChange" update="createForm"
listener="#{productController.printHelloWorld}" />
</p:selectOneMenu>
<h:panelGroup id="dummy1" rendered="#{productController.selectedProduct.type != null}" />
</h:form>
The question is what the best way is to update that panelGroup
'dummy1'
Thanks for any help.
I'm using primefaces and have a datatable that has 2 columns. One column is outputtext another one is selectOneMenu. I made editable selectOneMenu. Actually it's work but not properly. Default value of selectItem is shown null but ı want it to show first value as default value. How can I make it?
<p:dataTable id="cellEditingTable" var="message"
value="#{messageTableController.menuList}" paginator="true"
paginatorPosition="bottom" editable="true" editMode="cell">
<p:column>
<p:selectOneMenu id="menu" value="#{messageTableController.selected}"
style="width:96%" effect="fold" editable="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
</p:column>
</p:dataTable>
I change selectOneMenu's value to first ItemValue. So when run the program, first ItemValue picked selected item as a default.
<p:selectOneMenu id="menu" value="#{message.assign}"
style="width:97%" editable="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
Add noSelectionOption to the first selectItem
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" noSelectionOption="true" />
May be late to answer this.
If you use editable="true" then while rendering in the browse, it will render as textbox.
Remove the editable="true" then the default value will be selected.
If you want to provide the filter option in the selectOneMenu, use filter="true"
<p:selectOneMenu id="menu" value="#{message.assign}"
style="width:97%" filter="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
Based on the editable property, it will render in browser as below.
I have the following component on the xhtml:
<p:outputLabel for="concept" value="Concept" />
<p:selectOneMenu id="concept" value="#{dIGRCController.digrc.qconce}"
requiredMessage="Debe de seleccionar un concepto."
required="#{request.getParameter('validate')}">
<f:selectItem itemLabel="Concept" itemValue="" />
<f:selectItems value="#{cCRX1Controller.ccrx1.concepts.entrySet()}"
var="concepts" itemValue="#{concepts.key}"
itemLabel="#{concepts.value}" />
<p:ajax event="change" execute="#this" listener="#{dIGRCController.testing()}" />
</p:selectOneMenu>
The values are coming correctly from the cCRX1Controller class. However, when I select an option, I am trying to display the value. the #{dIGRCController.testing()} looks like this:
public void testing()
{
System.out.println("sdfsd");
}
What am I doing wrong? I checked this question but could't figure out what the problem is.
Try with this
<p:ajax process="#this" listener="#{dIGRCController.testing()}" />
I think the default of ajax event of Primefaces select one menu is valueChange event. So, try with using also
<p:ajax event="valueChange" process="#this" listener="#{dIGRCController.testing()}" />
I have a big complex form with validation on most of the fields. Somewhere I have <h:selectOneMenu> where if I select a certain value, I want another <h:selectOneMenu> to appear under it. The second list is initially invisible (I set it with rerender property to false and I make it true with clickListener() function and render it an ajax call).
<o:form>
<h:panelGroup id="group" >
<label>Status</label>
<h:selectOneMenu id="status" immediate="true" label="Status" value="#{candidateBean.statusVO}" converter="omnifaces.SelectItemsConverter" required="true" requiredMessage="The field is empty">
<f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
<f:selectItems value="#{settingsBean.settings.statusListVO.statusVO}" var="status" itemValue="#{status}" itemLabel="#{status.name}"/>
<f:ajax event="valueChange" listener="#{candidateBean.clickListener}" execute="form" render="group" />
</h:selectOneMenu>
<h:messages for="status" style="color:red" />
<label>Invalidation Reason</label>
<h:selectOneMenu id="invalidationReason" rendered="#{candidateBean.falseTest}" label="Invalidation Reason" value="#{candidateBean.invalidationReasonVO}" converter="omnifaces.SelectItemsConverter" requiredMessage="The field is empty">
<f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
<f:selectItems value="#{settingsBean.settings.invalidationReasonListVO.invalidationReasonVO}" var="invalidation" itemValue="#{invalidation}" itemLabel="#{invalidation.name}"/>
</h:selectOneMenu>
</h:panelGroup>
</o:form>
I used <o:form> instead of <h:form> because somewhere in the form I used <o:ignoreValidationFailed> because I needed to update a dataTable with values from a <h:selectOneMenu> and force update on my model.
Everything works except when I select a value from the list, the elements inside the panelGroup are rendered without any style at all and I can't figure out why. If I refresh the page the CSS is loaded on the elements but this is not an option.
My bean is #SessionScoped.
I have a drop down list with several values and I want to show a panel only if a value has been selected
Here is the code simplified
<p:selectOneMenu id="" value="#{myBean.myElement}" >
<f:selectItem itemLabel="Choose an element itemValue="" />
<f:selectItems value="#{myBean.myElementList}" />
<p:ajax update="myPanel" listener="#{myBean.handleChange}"/>
</p:selectOneMenu>
<p:panel id="myPanel" header="My Header" style="margin-bottom:10px;" rendered="#{myBean.myElement != null}">
But this does not seem to work (it works only if I refresh manually the page).
How could you fix this ?
Since myPanel is not rendered, the component won't be in the component tree, so it cannot be updated later in the view. Use another UIContainer to wrap it like <h:panelGroup> and update this container:
<p:selectOneMenu id="" value="#{myBean.myElement}" >
<f:selectItem itemLabel="Choose an element itemValue="" />
<f:selectItems value="#{myBean.myElementList}" />
<!-- here update to foo instead of myPanel -->
<p:ajax update="foo" listener="#{myBean.handleChange}"/>
</p:selectOneMenu>
<h:panelGroup id="foo">
<p:panel id="myPanel" header="My Header" style="margin-bottom:10px;"
rendered="#{myBean.myElement != null}">
</h:panelGroup>