javax.el.PropertyNotFoundException

UI Components for JSF
Post Reply
andys
Posts: 1
Joined: 18 May 2015, 09:08

18 May 2015, 09:13

If I add stackElemen first time it's ok, the output is:
list size = 1
But after adding second element I get error:
Error Rendering View[/tab.xhtml]: javax.el.PropertyNotFoundException: /tab.xhtml @65,50 value="#{stackElement.name}": The class 'java.lang.String' does not have the property 'name'. ...

Caused by: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'name'.

ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /Play/tab.xhtml: java.lang.IllegalStateException: CDATA tags may not nest ...
Why does it happens?

Page

Code: Select all

<h:form>

        <p:commandButton update="stack" value="Use in expression" action="#{bean.tab}">
            <f:param name="i" value="13" />
        </p:commandButton>

        <p:orderList  id="stack" value="#{expression.list}" var="stackElement" 
            itemLabel="#{stackElement}" itemValue="#{stackElement}" controlsLocation="none" >
            <!-- <p:ajax event="reorder" listener="#{expression.onReorder}" /> -->
            <p:column>
                <h:outputText value="#{stackElement.name}" />
            </p:column>
        </p:orderList>

    </h:form>
//bean

Code: Select all

@ManagedBean @RequestScoped 
public class Bean implements Serializable {
@ManagedProperty(value="#{expression}")
    private Expression ex;
public void tab() { 
        ex.addStackElement( new StackElement((int) System.currentTimeMillis(), "tab") );
    }
    // getters-setters
//bean

Code: Select all

@ManagedBean @SessionScoped
public class Expression implements Serializable {
    private List<StackElement> list = new ArrayList<StackElement>();
    public void addStackElement(StackElement stackElement) {
        list.add(stackElement);
        System.out.println("list size = " + list.size()); 
    }
    // getters-setters
model

Code: Select all

public class StackElement {
    private int id;
    private String name;
    public StackElement(int id, String name) {
        this.id = id;
        this.name = name;
    }
    // getters-setters

pL4Gu33
Posts: 9
Joined: 01 Oct 2013, 18:51

18 May 2015, 19:14

You need a converter for the pojo "StackElement" else the "first" entry converts to his "toString" in the list on second click. (type erasure)

For example ! and only for example ;):

Code: Select all

@FacesConverter(value="stackElementConverter")
public class StackElementConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
		String[] splittedString = value.split("\\+");
		StackElement element = new StackElement(Integer.parseInt(splittedString[0]), splittedString[1]);
		return element;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		if(value instanceof StackElement){
			StackElement element = (StackElement) value;
			String elementAsString = element.getId()+"+"+element.getName();
			return elementAsString;
		}
		return null;
	}

}

Code: Select all

public class StackElement implements Serializable{
    private int id;
    private String name;
    public StackElement(int id, String name) {
        this.setId(id);
        this.setName(name);
    }
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		StackElement other = (StackElement) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	
}

Code: Select all

<p:orderList  id="stack" value="#{expression.list}" var="stackElement" converter="stackElementConverter"
            itemLabel="#{stackElement}" itemValue="#{stackElement}" controlsLocation="none" >
            <p:column>
                <h:outputText value="#{stackElement.name}" />
            </p:column>
        </p:orderList>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 28 guests