0

I have a simple input form that accepts data from the user and stores the data in DB upon a click action for a p:commandButton

the form looks like this

form.xhtml :

<div align="center" style="width: 80%">
            <p:panelGrid columns="1">
                <p:accordionPanel>

                    <p:tab title="#{msg['truck.tab.general']}">
                        <h:form><h:panelGrid columns="3">
                                <p:outputLabel value="*#{msg['truck.form.code']}"></p:outputLabel>
                                <p:inputText id="inputTruckCode" required="true"
                                    requiredMessage="Must exist"
                                    value="#{trucksBean.currentTruck.code}"></p:inputText>
                                <p:message for="inputTruckCode" showSummary="true"></p:message>
<!-- rest of the form -->
</h:form>
</p:tab>
</p:accordionPanel>
<p:commandButton action="#{trucksBean.insertTruck}"
                        value="Insert Truck"></p:commandButton>
                </p:panelGrid>
            </div>

the backing bean code:

@ManagedBean
@ViewScoped
public class TrucksBean {
private TruckFullInformation currentTruck;
public String insertTruck() {
        //the values inside currentTruck member variable are NULLs

        return null;
}

what's wrong with the code? why clicking on the commandButton doesn't affect/update the values of the "currentTruck" variable?

thanks in advance;

  • 2
    Seems to me the commandButton must be inside the form – Jaqen H'ghar Sep 27 '15 at 16:28
  • @ Jaqen H'ghar : I tried to put the p:commandButton inside the h:form tag, yet, the action method was NOT triggered upon commandButton's click !!! I don't know why! – user3660267 Sep 27 '15 at 16:31
  • Do you initialize currentTruck anywhere? For example in a @PostConstruct method. Also do you have getter/setter for it? – Jaqen H'ghar Sep 27 '15 at 16:32
  • yes, the currentTruck member variable was initialized in a @PostConstruct method, and it has getter and setter – user3660267 Sep 27 '15 at 16:37
  • And nothing in the server or browser log? Still, the button must be inside the form – Jaqen H'ghar Sep 27 '15 at 16:39
  • Jaqen H'ghar is correct, all elements you need to process on server side have to be inside of `h:form`. Anyway, I would suggest to change the method `insertTruck` to return `void` as having method with `String` as a return type suggests that you wish to perform navigation. More detailed explanation here: http://stackoverflow.com/a/3909382/5280532 – Sva.Mu Sep 27 '15 at 17:44
  • 1
    post the whole bean and the truck entity. is the method even triggered when you put the button inside the form? – Ced Sep 27 '15 at 20:12

0 Answers0