Question

I am aware that nesting is a problem with form tags. However, my page does not have nested forms. I have one form (id="menuForm") to enclose the p:menu. Next, I have a form (id="locationForm") lower in the page. I have checked the html source that is output, and there is no nesting happening.

I have one p:commandButton that I want to use to submit the form. It works occasionally, but not all of the time. Sometimes, the method fires and other times it doesn't. Can anyone poing out what I'm doing wrong?

Also--If I comment out the menu form completely it works as intended.

Thanks.

Action Method:

    public String insertLocationAction(){
    System.out.println("******* Method Fired.");
    DatabaseManager.insertLocation(newLocation);
    return "locations";
    }

XHTML Page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:view>
    <ui:debug rendered="#{facesContext.application.projectStage eq 'Development'}"/>
    <h:head />
    <p:messages />
    <p:layout fullPage="true">
        <p:layoutUnit position="west" size="260" header="Menu" resizable="false" closable="false">
        <h:form id="menuForm">
            <p:menu style="width: 240px;" >
                <p:submenu label="Locations" style="width: 240px;">
                    <p:menuitem value="All Locations" outcome="/pages/locations.xhtml" style="width: 240px;" />
                    <p:menuitem value="Create New" action="#{locationBackingBean.addLocationAction}" style="width: 240px;"  />
                </p:submenu>
                <p:submenu label="Queries" style="width: 240px;">
                    <p:menuitem value="Product Group Sales" outcome="/pages/productGroupSales.xhtml" style="width: 240px;" />
                    <p:menuitem value="Product Line Sales" outcome="/pages/productLineSales.xhtml" style="width: 240px;" />
                </p:submenu>
            </p:menu>
        </h:form>
    </p:layoutUnit>
    <p:layoutUnit position="center">
         <h:form id="locationform" enctype="multipart/form-data">
            <p:growl id="growl" showDetail="true" />
            <p:panelGrid columns="2">
                <f:facet name="header">Enter New Location Details</f:facet>
                        <h:outputLabel for="locationName" value="Location Name:" />           <p:inputText id="locationName" value="#{locationBackingBean.newLocation.locationName}" size="100" />
                        <h:outputLabel for="street1" value="Street Address1:" />    <p:inputText id="street1" value="#{locationBackingBean.newLocation.street1}" size="100"/>
                        <h:outputLabel for="street2" value="Street Address2:" /><p:inputText id="street2" value="#{locationBackingBean.newLocation.street2}" size="100"/>
                        <h:outputLabel for="city" value="City:" /><p:inputText id="city" value="#{locationBackingBean.newLocation.city}" size="40" />
                        <h:outputLabel for="state" value="State:" /><p:inputText id="state" value="#{locationBackingBean.newLocation.state}" size="2" />
                        <h:outputLabel for="country" value="Country:" /><p:inputText id="country" value="#{locationBackingBean.newLocation.country}" size="20" />
                        <h:outputLabel for="phone" value="Phone:" /><p:inputText id="phone" value="#{locationBackingBean.newLocation.phone}" size="15" />
                        <h:outputLabel for="locationType" value="Type:" /><p:inputText id="locationType" value="#{locationBackingBean.newLocation.locationType}" />
                </p:panelGrid>
                <p:commandButton action="#{locationBackingBean.insertLocationAction}"  ajax="false" value="Save" />
            </h:form>
        </p:layoutUnit>
    </p:layout>
</f:view>
</html>
Was it helpful?

Solution

Refer to: http://www.primefaces.org/docs/vdl/4.0/primefaces-p/commandButton.html

By default the p:commandButton processes the whole 'view'.

Add process=":locationform" to the commandButton might just need "locationform" (depends on your selector working and nested jsf components etc..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top