hahagal
hahagal

Reputation: 41

<p:inputText> auto set value when page refreshes

I am facing this problem where when I leave everything blank for inputText, click on the Save button, one of the inputText field will be auto set with 0.000000. I have been looking at this for sometime but I still couldn't figure out what is wrong with it. By right, it should remain blank.

<tr>
<td><p:commandButton type="button"
     value="#{msg.cr1002_command_save}" onclick="confirmation.show()"
     id="cr1002_command_save" styleClass="commandButton">
  </p:commandButton> <p:confirmDialog id="confirmDialog"
     message="#{msg.cr1002_prompt_confirm_save}" severity="alert"
     widgetVar="confirmation">
     <p:commandButton id="confirm" value="OK"
    oncomplete="confirmation.hide()"
    action="#{pc_Cr1002.doCr1002_command_saveAction}" ajax="false"
    styleClass="commandButton" />
     <p:commandButton id="decline" value="Cancel"
    onclick="confirmation.hide()" type="button"
    styleClass="commandButton" />
  </p:confirmDialog>
</td>
</tr>

<tr>
   <td><h:outputText styleClass="outputText"
     id="cr1002_output_sample_value"
     value="#{msg.cr1002_output_sample_value}"></h:outputText>
   </td>
   <td></td>
   <td><p:inputText styleClass="inputTextRefresh"
     id="cr1002_input_sample_value" onchange="this.form.submit()"
     valueChangeListener="#{pc_Cr1002.handleCr1002_input_sample_valueValueChange}"
     style="text-align: right"
     value="#{pc_Cr1002.w_currency.sample_value}">
     <f:convertNumber pattern="##0.000000" />
  </p:inputText>
   </td>
   <td></td>
   <td><p:message styleClass="message_200px"
     id="cr1002_error_sample_value" for="cr1002_input_sample_value"
     display="text"></p:message>
   </td>
   <td></td>
</tr>

Upvotes: 0

Views: 505

Answers (1)

Niks
Niks

Reputation: 4842

#{pc_Cr1002.w_currency.sample_value}

I suppose your field sample_value is a primitive (float may be) and not a wrapper class (Float)

The default value for primitives on instance level is 0 or 0.0 whereas that of wrapper classes is null. So, if these assumptions are correct, and changing the data type does not harm you, this might solve your issue.

Upvotes: 1

Related Questions