Topic
No replies
SystemAdmin
SystemAdmin
6420 Posts
ACCEPTED ANSWER

Pinned topic JSF 2.0 - Ajax issue when using parameter with action methods

‏2012-09-20T08:15:52Z |
I created a little portlet and use JSF 2 with it. I try to create two UI elements with each containing a list where I can choose one element from the source list and add it to the result list by hit the "Add" button and remove one element I select in the result list by using the button "Remove". I tested this with the following code and MyFaces 2.1.7 on a tomcat and everything works fine. When I use the same code with the WebSphere Portal Server inside a Portlet I have the issue that not always the focused elements will be added or removed. Sometimes you need to click twice to get the expected result. I guess the "JSF variable" I implicitly declared

==================
POJO: SimpleObject
==================




class SimpleObject 
{ 

private String id; 

public String getId()
{ 

return this.id; 
} 

public 

void setId(String id)
{ this.id=id; 
} 
}


=====================
BEAN: SimpleBean.java
=====================


...   List<SimpleObject> sourceList; List<SimpleObject> resultList;   ...   

public 

void addObj(String sourceId) 
{ 

for (SimpleObject obj : sourceList) 
{ 

if (obj.getId().equals(sourceId)) 
{ resultList.add(obj); 

break; 
} 
} 
}   

public 

void removeObj(String removeId) 
{ 

if (!resultListe.isEmpty()) 
{ SimpleObject toremove = 

null; 

for (SimpleObject obj : resultListe) 
{ 

if (obj.getId().equals(removeId)) 
{ toremove = obj; 

break; 
} 
} 

if (toremove != 

null) 
{ resultListe.remove(toremove); 
} 
} 
}   ...


===============
JSF: page.xhtml
===============


...   <h:panelGrid columns=
"4"> <h:selectOneListbox value=
"#{sourceId}" id=
"sourcelistui"> <f:selectItems  value=
"#{simpleBean.sourceList}" var=
"entry" itemValue=
"#{entry.id}" itemLabel=
"#{entry.id}" /> </h:selectOneListbox> <h:panelGroup> <h:commandButton value=
"Add" action=
"#{simpleBean.add(sourceId)}"> <f:ajax event=
"click" execute=
"@form" render=
"resultlistui" /> </h:commandButton> <br/> <h:commandButton value=
"Remove" action=
"#{simpleBean.remove(removeId)}"> <f:ajax event=
"click" execute=
"@form" render=
"resultlistui" /> </h:commandButton> </h:panelGroup> <h:selectOneListbox value=
"#{removeId}" id=
"resultlistui"> <f:selectItems value=
"#{simpleBean.resultList}" var=
"entry" itemValue=
"#{entry.id}" itemLabel=
"#{entry.id}" /> </h:selectOneListbox> </h:panelGrid>   ...


I am using MyFaces 2.0 with WebSphere Portal 8 and latest updates for WAS and WPS.