0

I fill a carousel with datas from an array. And I'd like to change the datas of the array with the datas which are set in the carousel.

<h:form id="newConditionPanelForm">
    <p:panelGrid id="newConditionPanelGrid">
        <p:row>
            <p:column colspan="2"><h2>Define conditions</h2></p:column>
        </p:row>
        <p:row>
            <p:column>
                <p:outputLabel value="Condition Name:" />
            </p:column>
            <p:column>
                <h:outputText value="#{priceManagementMB.conditions.name}"></h:outputText>
            </p:column>
        </p:row>
        <p:row>
            <p:column colspan="2" style="text-align:center; width:100%">
                <p:carousel id="priceCarousel"
                                        value="#{priceManagementMB.prices}" headerText="Price per hour" 
                                        var="priceEdit"
                                        numVisible="1" 
                                        style="width:100%"
                                        circular="true"
                                        binding="#{carousel}"
                                        responsive="true">
                    <h:panelGrid columns="1">
                        <p:row>
                            <p:column colspan="2">
                                <h:outputText value="#{carousel.rowIndex + 1}h00" />
                            </p:column>
                        </p:row>
                        <p:row>
                            <p:column>
                                <h:outputText value="Price during given Hour: " />
                            </p:column>
                            <p:column>
                                <p:inplace id="inplacePrice" emptyLabel="click here to edit">
                                    <p:inputText id="priceEdit" value="#{priceEdit}">
                                    </p:inputText>
                                </p:inplace>
                            </p:column>
                        </p:row>
                    </h:panelGrid>
                </p:carousel>
            </p:column>
        </p:row>
    </p:panelGrid>
    <h:commandButton value="Submit conditions" update="newConditionPanelGrid" 
                    validateClient="true" action="#{priceManagementMB.updateCondition}">
    </h:commandButton>
</h:form>

The elements in the inputtext that are in the carousel aren't submitted to the backing bean and I can't use them. What do I do wrong ? How could I get the datas without transmitting them an actionPropertyListner in a link or button? An event like blur would work too but I don't know how to put it in use, I need the Index and the new Value. The array has a lenght of 24, one for each hour of the day.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Leahparr
  • 1
  • 3

1 Answers1

0

JSF after submit try to call proper setter. You don't provide details about prices type but I'm guessing that you use some class from java.lang (Float, Double).

So then when you use value="#{priceEdit}" JSF try to use setPriceEdit on Double, Float. In details it is explained here How does EL #{bean.id} call managed bean method bean.getId()

The solution is to used your class with setter (take a look at What is the best data type to use for money in java app?). If this class has no setter you always can write your own class (wrapper) with proper setter.

Simple example:

class MoneyWrapper {
     private YourMoneyType value;

     public setValue(YourMoneyType value){
         this.value = value;
     }

     public YourMoneyType getValue(){
         return this.value;
     }

}

Than in your bean you can use array contains elements of MoneyWrapper. And finally use it in view like this value="#{priceEdit.value}"

Community
  • 1
  • 1
rkarczmarczyk
  • 327
  • 5
  • 13