anon
anon

Reputation:

JSF difficulty with EL expression

I am facing a problem while using the property "required" JSF 2 + Prime Faces 3.5.

The code below works perfectly:

    <!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<ui:decorate template="/templates/main_template.xhtml">
    <ui:define name="centro">
        <h:head>
        </h:head>
        <h:body>
            <f:view>
                <h:form id="form">

                    <h3>TITLE</h3>



                    <h:panelGrid id="panel1" columns="3">

                        <h:outputLabel for="input1" value="Input1" />
                        <p:inputText id="input1" value="#{controller.myObject.input1}" label="input1" required="#{empty param['form:input3']}"/>
                        <p:message for="input1" />

                        <h:outputLabel for="input2" value="Input2" />
                        <p:inputText id="input2" value="#{controller.myObject.input2}" label="input2" required="#{empty param['form:input3']}"/>
                        <p:message for="input2" />

                        <h:outputLabel for="input3" value="Input3" />
                        <p:inputText id="input3" value="#{controller.myObject.input3}" label="input3" required="#{empty param['form:input1']}"/>
                        <p:message for="input3" />

                    </h:panelGrid>


                    <p:commandButton id="btn" value="Save" update="form" actionListener="#{controller.save}" />

                </h:form>
            </f:view>
        </h:body>
</ui:define>
</ui:decorate>
</html>

If I add to my code a TAB VIEW, required field validation does not work anymore, as follows:

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<ui:decorate template="/templates/main_template.xhtml">
    <ui:define name="centro">
        <h:head>
        </h:head>
        <h:body>
            <f:view>
                <h:form id="form">

                    <h3>#{msgs.clienteCadastroTitulo}</h3>

                    <p:tabView id="tabView">

                    <p:tab id="tab1" title="TAB 1">


                    <h:panelGrid id="panel1" columns="3">

                        <h:outputLabel for="input1" value="Input1" />
                        <p:inputText id="input1" value="#{controller.myObject.input1}" label="input1" required="#{empty param['form:input3']}"/>
                        <p:message for="input1" />

                        <h:outputLabel for="input2" value="Input2" />
                        <p:inputText id="input2" value="#{controller.myObject.input2}" label="input2" required="#{empty param['form:input3']}"/>
                        <p:message for="input2" />

                        <h:outputLabel for="input3" value="Input3" />
                        <p:inputText id="input3" value="#{controller.myObject.input3}" label="input3" required="#{empty param['form:input1']}"/>
                        <p:message for="input3" />
                    </h:panelGrid>

                    </p:tab>

                    </p:tabView>

                    <p:commandButton id="btn" value="Save" update="form" actionListener="#{controller.save}" />

                </h:form>
            </f:view>
        </h:body>
    </ui:define>
</ui:decorate>
</html>

I will not post here everything I've tried, but they can be sure that I've tried using various methods outlined by tutorials, questions from other users, etc..

Still I could not understand where I am going wrong and what you would like to give me some tips so I can perform my validation correctly.

Basically, my required property should be dynamic according to the fill or not the fields in my form.

Thank you all in advance.

Upvotes: 1

Views: 271

Answers (2)

Ravi Kadaboina
Ravi Kadaboina

Reputation: 8574

If you look at the API docs http://www.primefaces.org/docs/api/3.5/org/primefaces/component/tabview/TabView.html

tabview is implementing javax.faces.component.NamingContainer so you need to include its id also like this with naming container separator ":"

form:tabView:input3

Upvotes: 1

klimpond
klimpond

Reputation: 766

Probably by adding <p:tabView> and <p:tab> you changed the path for param['form:inputX'], try changing it to param['form:tab1:inputX'] or param['form:tabView:tab1:inputX']. Not sure with exact combination, but really hope that this is the reason of the bug.

Upvotes: 0

Related Questions