Constants in EL 3.0 - Property not found -


i'm trying reference constant el on jsf page (https://java.net/projects/el-spec/pages/staticfield), i'm stuck on exception:

javax.servlet.servletexception: /faces/signup.xhtml @18,85 maxlength="#{signupbean.username_maxlength}": property 'username_maxlength' not found on type com.foo.signupbean 

i'm using tomcat 8.0.0-rc1 , here backing bean , input declaration:

bean:

@managedbean @requestscoped public class signupbean implements serializable {      public static final int username_maxlength = 30;     ...  } 

input field on page:

<input type="text" jsf:id="username" jsf:value="#{signupbean.username}" maxlength="#{signupbean.username_maxlength}" /> 

update:

with maxlength="#{(com.foo.signupbean).username_maxlength}" i'm getting java.lang.nullpointerexception: argument error: parameter value null

first, off, see balusc's updated answer how use constants in el 3.0 expressions.

now, said, if want code working right released version of glassfish 4.0, can modify backing bean in following way. backing bean doesn't have getter/setter field. backing beans need have javabeans-style properties getters/setters.

@managedbean @requestscoped public class signupbean implements serializable {      private final int username_maxlength = 30;     private string username;      ...      public int getusername_maxlength() {         return username_maxlength;     }      public void setusername_maxlength(int i) {         // don't set anything, because constant     }       public string getusername() {         return username;     }      public void setusername(string u) {         username = u;     }  } 

then facelets tag:

<input type="text"         jsf:id="username"         jsf:value="#{signupbean.username}"         jsf:maxlength="#{signupbean.username_maxlength}" /> 

that is, don't make field static. recommend switching on correct syntax once jsf updated in ri/glassfish 4.0.

edit: fixed input tag use jsf:maxlength.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -