-1

I'm unable to set true false value to a boolean variable I have the following code

Form.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml">
    <h:form>
        <p:panel id="work" styleClass="panelNoBorder">
            <p:fieldset toggleable="true" toggleSpeed="500" legend="Core">
                <h:panelGrid columns="2" styleClass="panelNoBorder"
                             rendered="#{javaMB.formNotComplete and !javaMB.formRejected}">

                    <p:outputLabel value="Form Number"/>
                    <p:row>
                        <p:inputText id="formNumber" value="#{javaMB.formNumber}" maxlength="10">
                        </p:inputText>
                    </p:row>
                    <p:outputLabel value="Result"/>
                    <p:row>
                        <p:inputText id="result" maxlength="10"
                                     value="#{javaMB.result}">
                        </p:inputText>
                    </p:row>
                </h:panelGrid>

            </p:fieldset>
        </p:panel>
    </h:form>
</ui:composition>
public class JavaMB {

    private boolean formRejected = false;
    private boolean formNotComplete = true;

    public boolean isFormRejected() {
        return formRejected;
    }

    public void setFormRejected(boolean formRejected) {
        this.formRejected = formRejected;
    }

    public boolean isFormNotComplete() {
        return formNotComplete;
    }

    public void setFormNotComplete(boolean formNotComplete) {
        this.formNotComplete = formNotComplete;
    }

    public void initializeWorkFlow() {
        logger.debug("Form: " + FormEntity.getFormId());
        if (workflow.getActionType().getActionTypeId() == '5') {
            this.setFormNotComplete(false);
        } else if (workflow.getActionType().getActionTypeId() == '7') {
            this.setFormRejected(true);
        } else {

        }

    }
}

The set values are placed inside an if statement , The if Statements work perfectly fine

The problem is that I can't display correctly boolean value. There are NO errors in the console,

this.setFormNotComplete(false);
this.setFormRejected(true); 

Any ideas how to solve this issue?

the database has the values for Approved and Not approved, So if the record has a 5 or 7 It must hit those values and not display the panel

In database we have a table workflow and the action type IDs

The action type Ids being set to record has a 5 being approved or 7 being Rejected

Upon these values the setFormNotComplete(false 7 if setFormRejected(true must act

<h:panelGrid
rendered="#{javaMB.formNotComplete and !javaMB.formRejected}">

                    if (workflow.getActionType().getActionTypeId() == '5') {
        this.setFormNotComplete(false);
    } else if (workflow.getActionType().getActionTypeId() == '7') {
        this.setFormRejected(true);
    } else {
ansa
  • 1
  • 1
  • 1
    Your `p:commandButtons` have no `update` attribute and thus you won't see any change on click. – Selaron Feb 04 '20 at 07:04
  • Does it work if you remove all but one input and one button from the xhtml? And from the bean all but code that is directly related to the simplified xhtml – Kukeltje Feb 04 '20 at 07:05
  • 1
    And regarding your reset button, read #1 in https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Feb 04 '20 at 07:40
  • @Selaron Even if there is no update on the buttons the database has the values for Approved and Not approved, So if the record has a 5 or 7 It must hit those values and not display the panel – ansa Feb 04 '20 at 14:15
  • It does not work even if I remove all the buttons and place only the h:panelGrid and the inputs, The render function must act as per the db values if 5 then we are setting setFormNotComplete(false 7 if setFormRejected(true – ansa Feb 04 '20 at 14:19
  • Try to remove the type attribute of both of your buttons, and also use update attribute on them, and give your form an id and update it – BugsForBreakfast Feb 04 '20 at 14:29
  • @BugsForBreakfast even if I remove all the buttons and place only the h:panelGrid and the inputs, The render function must act as per the db values if 5 then we are setting setFormNotComplete(false 7 if setFormRejected(true – ansa Feb 04 '20 at 15:12
  • 1
    Why did you remove the command buttons? You now have no action on your page. Please take a step back and find some beginner tutorials. Check the resources section of https://stackoverflow.com/tags/jsf/info – Jasper de Vries Feb 04 '20 at 15:33
  • Nobody said to remove ALL buttons. I said all **but one** (in my first comment), and @BugsForBreakfast said to remove the type attribute (which only is a problem for the reset button like mentioned in the link I posted in my second comment) – Kukeltje Feb 04 '20 at 15:54
  • @Kukeltje true hehe ;) – BugsForBreakfast Feb 04 '20 at 15:59

1 Answers1

0

For boolean fields the getter method name should be is<First letter capitalised field name> but yours is not.

public boolean isformRejected() should be public boolean isFormRejected() and public boolean isformNotComplete() should be public boolean isFormNotComplete()

So your class should be as follows.

public class JavaMB {

    private boolean formRejected = false;
    private boolean formNotComplete = true;

    public boolean isFormRejected() {
        return formRejected;
    }

    public void setFormRejected(boolean formRejected) {
        this.formRejected = formRejected;
    }

    public boolean isFormNotComplete() {
        return formNotComplete;
    }

    public void setFormNotComplete(boolean formNotComplete) {
        this.formNotComplete = formNotComplete;
    }

    public void initializeWorkFlow() {
        logger.debug("Form: " + FormEntity.getFormId());
        if (workflow.getActionType().getActionTypeId() == '5') {
            this.setFormNotComplete(false);
        } else if (workflow.getActionType().getActionTypeId() == '7') {
            this.setFormRejected(true);
        } else {

        }

    }
}
seenukarthi
  • 8,241
  • 10
  • 47
  • 68