I have Postgresql 8.4 table
CREATE TABLE users
(
username character varying(50) NOT NULL,
"password" character varying(50) NOT NULL,
enabled boolean NOT NULL,
type_of_signature boolean NOT NULL,
companyusers2_id integer NOT NULL,
numberorganizac character(8) NOT NULL,
);
In that table i have just one row: ""admin";"admin";TRUE;TRUE;1;"12345678"
I have JPA
@Entity
@Table(name="users")
public class Users implements Serializable {
...
private boolean typeOfSignature;
...
@Column(name="type_of_signature")
public boolean getTypeOfSignature() {
return this.typeOfSignature;
}
public void setTypeOfSignature(boolean typeOfSignature) {
this.typeOfSignature = typeOfSignature;
}
...
}
I have JSF
<h:outputText value="Type of signature is NULL" rendered="#{curUser.typeOfSignature == null}"/>
<h:outputText value="Type of Signature is TRUE" rendered="#{curUser.typeOfSignature}"/>
<h:outputText value="Type of Signature is FALSE" rendered="#{!curUser.typeOfSignature}"/>
I always get "Type of signature is NULLType of Signature is FALSE" at result page.
But I also have method in my bean
if(getCurUser().getTypeOfSignature())
{
jpaBean.pushSignature(dataItem, 1);
}
else
{
jpaBean.pushSignature(dataItem, 2);
}
And it works right depending on type of user's signature.
Why I always get NULL in JSF? Or I'm a newby and have done something wrong?
I ran into this same issue before when trying to use Boolean type with JPA and JSF, you can try to create a Custom BooleanConverter and map your JPA Entity with a Boolean instead of the raw type boolean.
Even though you might run into portability issues as you run this with different DBs, JSF and JPA implementations. I strongly suggest you change your approach to map Booleans as Strings in JPA:
CREATE TABLE users
(
username character varying(50) NOT NULL,
"password" character varying(50) NOT NULL,
enabled haracter(1) NULL,
type_of_signature char(1) NOT NULL,
companyusers2_id integer NOT NULL,
numberorganizac character(8) NOT NULL,
);
and your mapping would turn to be:
@Entity
@Table(name="users")
public class Users implements Serializable {
...
private String typeOfSignature;
...
@Column(name="type_of_signature")
public String getTypeOfSignature() {
return this.typeOfSignature;
}
public void setTypeOfSignature(String typeOfSignature) {
this.typeOfSignature = typeOfSignature;
}
...
}
populate your record with one row: ""admin";"admin";'T';'T';1;"12345678" then in JSF you shall have a different result:
<h:outputText value="Type of signature is NULL" rendered="#{empty curUser.typeOfSignature}"/>
<h:outputText value="Type of Signature is TRUE" rendered="#{curUser.typeOfSignature eq 'T'}"/>
<h:outputText value="Type of Signature is FALSE" rendered="#{!curUser.typeOfSignature eq 'T'}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With