I have the following managed bean which has a selectedElement
property and some components in a primefaces view binded to it inside an auto update outputpanel
, i have a commandButton
and f:setPropertyActionListener
to set the selectedElement
then update the panel, i get Target Unreachable, 'null' returned null: javax.el.PropertyNotFoundException:
i think the update proess fires before setting the property , i have another view in different page do the same procedure without errors !
the managed bean code is:
package boddooo.service;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.UserTransaction;
import boddooo.entity.Element;
@ManagedBean(name="ob")
@SessionScoped
public class objectsbuilder {
UserTransaction ut=null;
@PersistenceContext(unitName="game")
private EntityManager em;
Context icontext=null;
public objectsbuilder() throws NamingException{
icontext=new InitialContext();
ut=(UserTransaction)icontext.lookup("java:comp/UserTransaction");
}
private List<Element> elements;
private Element selectedElement;
public Element getSelectedElement() {
return selectedElement;
}
public void setSelectedElement(Element selectedElement) {
this.selectedElement = selectedElement;
}
@SuppressWarnings("unchecked")
public void loadElements(){
Query q=em.createNamedQuery("Element.findAll");
elements=(List<Element>)q.getResultList();
}
public List<Element> getElements(){
return elements;
}
}
and the view is :
<p:layout fullPage="true">
<p:layoutUnit position="west" header="Elements">
<p:dataGrid value="#{ob.elements}" var="element" style="padding:0px;text-align:center" columns="5">
<p:column>
<p:commandButton value="" style="margin:0px;padding:0px;width:40px;height:40px;background-image: url('resources/images/objects/#{element.name}.png');background-size: 40px 40px;">
<f:setPropertyActionListener value="#{element}" target="#{ob.selectedElement}"></f:setPropertyActionListener>
</p:commandButton>
</p:column>
</p:dataGrid>
</p:layoutUnit>
<p:layoutUnit position="center">
<p:outputPanel autoUpdate="true">
<p:panelGrid columns="2">
<p:outputLabel value="Name"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.name}"></p:inputText>
<p:outputLabel value="Type"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.type}"></p:inputText>
<p:outputLabel value="Class"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.class_}"></p:inputText>
<p:outputLabel value="Upgradable"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.upgradable}"></p:inputText>
<p:outputLabel value="Duplicated"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.duplicated}"></p:inputText>
<p:outputLabel value="Period"></p:outputLabel>
<p:inputText value="#{ob.selectedElement.period}"></p:inputText>
</p:panelGrid>
</p:outputPanel>
</p:layoutUnit>
</p:layout>