This question already has an answer here:
javax.el.PropertyNotWritableException: /index.xhtml #29,118 value="": Illegal Syntax for Set Operation
(1 answer)
Closed 5 years ago.
I have this form:
<h:form>
<h:outputLabel value="Entrez un id du compte a supprimer" for="id"/>
<h:inputText id="id" value=""/>
<h:commandButton id="supprimer" value="Supprimer" action="#{compteBancaireMBean.supprimer}"/>
</h:form>
And this action method:
public String supprimer() {
gestionnaireDeCompteBancaire.supprimer(comptebancaire.getId());
return "CompteList";
}
When I submit the form, I get the following exception:
javax.el.PropertyNotWritableException: /Supprimer.xhtml #14,44 value="": Illegal Syntax for Set Operation
How is this caused and how can I solve it?
value="" does not mean anything to the JSF el parser, it can't make sense of that. You need to actually provide a static value there, as in value="Some Text" or bind it to a variable in your backing bean as in value="#{compteBancaireMBean.myVariable}" where myVariable corresponds to an actual variable in your compteBancaireMBean backing bean. This variable must follow the javabean conventions i.e. you must have
private Integer myVariable; //I use Integer here just as an example, you can use any core java type
public void setMyVariable(Integer myVariable){
this.myVariable = myVariable
}
public Integer getMyVariable(){
return this.myVariable
}
Related
This question already has answers here:
How do I process GET query string URL parameters in backing bean on page load?
(4 answers)
When to use f:viewAction / preRenderView versus PostConstruct?
(2 answers)
ViewParam vs #ManagedProperty(value = "#{param.id}")
(2 answers)
Closed 2 years ago.
Can you tell me what is the order of events on page load in JSF?
I have a problem with passing parameter with f:param
I am using Eclipse, postgresql, Wildfly17 and primefaces 7.0.
I have two databases, connected with OneToMany relation. In first are pests with their properties. In second database are names of every pest in different languages (index of English is 1, German is 4, ...)
On first page is searching in first database (side One) for specific pests. Results are displayed in datatable under it. In last column of datatable is Edit button. By clicking on it you go on second page with data from both databases of specific pest.
Entity SmPests is:
Integer idPest;
String latinName;
String code:
#OneToMany(fetch = FetchType.LAZY, mappedBy = "smPests", cascade = CascadeTyoe.ALL, orphanRemoval = true)
List<SmPestsNames> smPestsNames = new ArrayList<SmPestsName>();
...
Entity SmPestsNames is:
Integer idPest;
int idLanguage;
String name;
In SmPestList.xhtml i have:
<p:button outcome="SmPestsEditable"update="pestsListEdit" value="Edit" style="fontsize:3em" title="edit">
<f:param name="id" value="#{zuzek.idPest}" />
<f:param name="code" value="#{zuzek.code}" />
<f:param name="lname" value="#{zuzek.latinName}" />
In SmPestsEdit.xhtml I have:
<f:viewParam name="id" value="#{smPestsEditable.idPest}" />
<f:viewParam name="code" value="#{smPestsEditable.code}" />
<f:viewParam name="lname" value="#{smPestsEditable.latinName}" />
My problem is that I when second page loads, idPest (passed by f:param) is not yet detected by backing bean and if I want to display names from second database I get
java.lang.NullPointerException
If i set static idPest it works but it doesn't display names of current element.
I want to se idPest before page loads.
Thank you in advance.
AFTER the page loads program does find correct children, but I want it happen BEFORE page loads.
I tried with ManagedBean but it says it is deprecated.
I also tried with viewAction
<f:viewParam name="id" value="#{smPestsEditable.idPest}" />
<f:viewParam name="code" value="#{smPestsEditable.code}" />
<f:viewParam name="lname" value="#{smPestsEditable.latinName}" />
<f:viewAction action="#{smPestsEditable.onload}" />
public void onload() {
idPest = id; // to avoid NullPointerException I use static idPest and try to change it to current before page loads
}
UPDATE: Problem is that parameter "id" is identifier for OneToMany relation. I want to load this OneToMany relation BEFORE the page loads. In the backing bean of the second page I have this:
private int idPest = 55; // This one is set so there is something set
#ManagedProperty(value="{param.id}")
private Long Id;
#ManagedProperty(value="{param.id}")
private int id;
public void onload() {
System.out.println(" ONLOAD: id: "+id);
System.out.println(" idpest: "+idPest);
System.out.println(" Id: "+Id);
}
I tried to get parameter using #ManagedBean using variables both int and Long type but what I get is:
ONLOAD: id: 0
idpest: 55
Id: null
Right now it seems to me I can't get (integer) value of parameter "id" in onload
This question already has answers here:
javax.el.PropertyNotFoundException: The class 'xxx' does not have a readable property 'yyy'
(2 answers)
Closed 7 years ago.
(intro: I have generated Entity Clases from DB with one tabe lets say Beans, so it generated me Beans.java, BeansFacade.java, BeansController.java and AbstracFacade.java than I added JSF pages from entity classes, and just want to add something to list.xhtml)
In my BeansFacade.java I have
public String simple(){
return "output";
}
In BeansController.java I hava
public String printSimple(){
return ejbFacade.simple();
}
And than whem I try to print that
<h:outputText value="#{beansController.printSimple}"> </h:outputText>
I get an error
javax.el.PropertyNotFoundException:
The class 'fct.entity.EventsController' does not have the property 'printSimple'.
You are not able to call the method in h:outputText.
h:outputText tries to search the given variable related getter/setter
private String printSimple;
public String getPrintSimple()
{
return ejbFacade.simple();;
}
/**
* #return the simple
*/
public String getSimple()
{
return simple;
}
And than whem you can use the simple variable to get the value.
<h:outputText value="#{beansController.printSimple}"> </h:outputText>
before that call the printSimple method.
I am having a hard-coded value that needs to be set to the jsf backing bean on form submit.
Can any one tell this please.
<h:inputHidden value="#{leaveBean.fApproverEmail}"></h:inputHidden>
but i want to send a hard coded value inplace of "#{leaveBean.fApproverEmail}" and set it to a property of backing bean..
Option 1.
Have your property initialized to your hardcoded value. JSF will auto-update this property on form submit. So, in case it has changed you will end up with a renewed property value in your action method.
String fApproverEmail = "default";
<h:inputHidden id="app" value="#{leaveBean.fApproverEmail}" />
Option 2.
Have a plain HTML <input type="hidden"> or valueless <h:inputHidden>. This way the submitted value is available in request parameter map. So you'll be able to grab it from ExternalContext#getRequestParameterMap() with its name as the key. But beware that in case your object's not a string you'll have to do conversion/validation on your own and action method is a wrong place to put that logic.
String fApproverEmail;
public void action() {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String s1 = ec.getRequestParameterMap().get("plain");
String s2 = ec.getRequestParameterMap().get("form:jsf");
fApproverEmail = ...;//and-or other logic
}
<h:form id="form">
<h:inputHidden id="jsf" />
<input type="hidden" id="plain" name="plain" value="#{backingBean.fApproverEmail}"/>
...
</h:form>
You can just call the bean method directly from your h:inputHidden tag, this way you can use another bean method to get the value you need.
<h:inputHidden value="#{leaveBean.fApproverEmail(otherBean.methodOrProperty)}"/>
In my JSF 2.1 facelets environment, I would like to set a bean property of int type:
facelets template:
<c:set target="#{mybean}" property="size" value="3"/>
java setter:
public void setSize(int size){
this.size = size;
}
But it throws an exception:
javax.el.ELException: Can't set property 'size' on class 'MyBean' to value '3'.
at javax.el.BeanELResolver.setValue(BeanELResolver.java:398)
...
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Looking into the code of BeanELResolver, I have noticed that the value "3" is unfortunately simply passed to the setter method without any coercion, which obviously does not work. It is a pity that BeanELResolver does not make use of the type knowledge it has there.
Is there a way to coerce the value to an int somehow? I already tried value="#{3}" but this yields a Long. Next thing that comes to my mind is value="#{f:toInt(3)}" using a custom function.
I tried to reproduce the problem you're having. I created a simple RequestScoped bean with a single property.
public class IndexBean {
private int value;
public void setValue(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Then When I used a defered expression (the one that starts with a #) within the target attribute...
<c:set target="#{indexBean}" property="value" value="5"/>
<h:outputText value="#{indexBean.value}"/>
...I received a JSP exception, saying
Its illegal to specify deferred expression for dynamic attribute.
...which lead me to change the expression to be immediate evaluated.
<c:set target="${indexBean}" property="value" value="5"/>
<h:outputText value="#{indexBean.value}"/>
...and the value was correctly shown on the screen.
How about using fmt:formatNumber?
<fmt:formatNumber var="i" type="number" value="3" />
<c:set target="#{mybean}" property="size" value="${i}"/>
I have read a lot of posts at Stackoverflow but I didn't succeed in implementing the belowmentioned problem from my side.
the problem is: I need to type some text in <p:inputTextarea> and when clicking on button I need to get this value in the bean method.
I.e.:
<p:inputTextarea binding="#{input}"/>
<p:commandButton action="#{pessoaMB.adicionarContato(input.value)}" immediate="true"/>
with the bean method:
public void adicionarContato(String value) {
System.out.println(value);
}
The code I'm using gives me a null value.
I'm using #ViewScoped and cannot change this.
First of all, a side note: it is a bad practice to work with JSF components, you should work with model instead. I.e. don't use binding="#{input}", but stick to value="#{bean.text}".
Second, I doubt that immediate="true" is used appropriately in your setup. When used in a UICommand component like <h:commandButton> it will cause to skip JSF lifecycle for components with immediate="false" (or omitted, as it's the default), thus their value won't be set at all. Still, JSF will still preset submittedValue behind the scenes before the action method is executed.
Also, I strongly recommend to read BalusC's blog post Debug JSF lifecycle, as it is more than enlightening on the topic.
As to the solution, I'd suggest to deal with value binding with the bean, as presented in the first comment. With this approach you won't need action method parameter at all. Moreover, rethink your use of immediate attribute. If you think it's correct then you've got two choices: (1) use immediate="true" on <p:inputTextarea> or (2) switch to action="#{bean.action(input.submittedValue)}".
I would've done this :
<h:form>
<p:inputText value="#{pessoaMB.input}"/>
<p:commandButton value="add" action="#{pessoaMB.adicionarContato}" />
</h:form>
input would be here a pessoaMB property with a getter and setter (an IDE can autogenerate it).
private String input;
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
As for the adicionarContato method, it would be like this :
public void adicionarContato() {
System.out.println(input);
}
You should create a new class, i.e:
public class MyFields(){
String input1;
String input2; //and so on...
//getters and setters
}
Then, in pessoaMB create a property:
private MyFields inputFields; //getter and setter
Finally, in your xhtml file:
<h:form>
<p:inputText value="#{pessoaMB.inputFields.input1}"/>
<p:inputText value="#{pessoaMB.inputFields.input2}"/>
<!-- add more inputText components... -->
<p:commandButton value="add" action="#{pessoaMB.adicionarContato}" />
</h:form>