问题
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 {
回答1:
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 {
}
}
}
来源:https://stackoverflow.com/questions/60049846/unable-to-set-true-false-value-to-a-boolean-variable