0

I have to select one menus. In the first select one menu i load all warehouse values.

In the second one menu i want to load all products, which depends to the warehouse. So if i do a value Change of the first select one menu i am going to render the second one menu.

I have a ProductDataAction Bean. In this bean i have following method.

public List<Product> getAllProductsForProjectAndWarehouse() {
            Warehouseinput w = warehouseinputDataAction.getActualWarehouseInput();
            return w.getWarehouse().getProduct();
    }

My Problem is, that the value w.getWarehouse() is null in my ProductDataActionBean.

My Expectation is, that it is not null, because in my xthml page i set the warehouseinputSaveActions.actualWarehouseInput.warehouse in the value of the first select one menu.

<div class="form-group form-md-line-input">
    <label class="col-md-2 control-label">#{texts['warehouseinput.warehouse']}</label>
        <h:selectOneMenu value="#{warehouseinputSaveActions.actualWarehouseInput.warehouse}">
            <f:converter converterId="ccWarehouseConverter"/>
            <f:selectItems value="#{warehouseDataActions.getAllWarehousesForProject
                    (warehouseinputDataActions.actualWarehouseInput.project)}" var="warehouse" 
                    itemLabel="#{warehouse.warehouseName}" itemValue="#{warehouse}"/>
            <f:ajax event="change" execute="@form" render="products"/>
        </h:selectOneMenu>

</div>

<div class="form-group form-md-line-input">
    <label class="col-md-2 control-label">#{texts['warehouseinput.product']}</label>
        <h:selectOneMenu id="products" value="#{warehouseinputSaveActions.actualWarehouseInput.product}">
            <f:converter converterId="ccConverter"/>
            <f:selectItems value="#{productDataActions.getAllProductsForProjectAndWarehouse()}"
                            var="product"itemLabel="#{product.productName}" itemValue="#{product}"/>
        </h:selectOneMenu>
</div>  
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
java java
  • 405
  • 1
  • 11
  • 25
  • when you get all the wharehouse, you also get the products? usually, this behaviour is used when you don't want all the data from DB for performance reason, so it may be correct that product are in warehouse are null... – Dan M Oct 06 '15 at 14:21
  • the w.getwarehouse is alreday null.... – java java Oct 06 '15 at 14:49
  • the warehouseinputDataAction instance you have in the getAllProductsForProjectAndWarehouse method, is the right one (and the same as the one where the set is done)? – Dan M Oct 06 '15 at 16:00
  • I have inject the warehouseinputDataAction in the productDataAction. But i don't know if its the same instance. Do i have a Change to know if its the same instance ? – java java Oct 06 '15 at 16:27
  • is the scope of the beans correct? have you tried to move the getAllProductsForProjectAndWarehouse method into the warehouseinputDataAction ? To avoid this kind of pitfall, I prefer to have one controller bean for each page, instead of one bean for each "control" in page. – Dan M Oct 06 '15 at 16:30
  • In the warehouseinput.xhtml i set first select one menu the value warehouseinputSavaAction.actualwarehouseInput.warehouse , and then in the second one menu i want to Access to the warehouse which is set in the first select one menu. Is this a valid procedure ? – java java Oct 06 '15 at 16:31
  • the scope is requestScope. and i also tried ViewScoped – java java Oct 06 '15 at 16:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91511/discussion-between-dan-m-and-java-java). – Dan M Oct 06 '15 at 16:32
  • Code is fishy. Business logic in getter == no just no. Is this acceptable as dupe? http://stackoverflow.com/a/11505860 – BalusC Oct 06 '15 at 17:58
  • why is the code fishy ? in the getter is no Business logic ! – java java Oct 07 '15 at 07:01
  • @dan: Can we continue analyzing in the Chat ? – java java Oct 07 '15 at 07:05
  • I recognized that the setter method of warehouse is not called if the page is loading. At which time the setter have to called for the select one menu () ? After submit ? or by loading the site ? – java java Oct 07 '15 at 07:24

0 Answers0