I am trying to create a datatable programmatically
Here where i am making a new instance for the dataTable :
public DataTables getDataTableTest() {
if(dataTableTest==null){
String var=getDatatableVar();
dataTableTest=new DataTables(context, app, "datatable1", "width: 50%", var,
"#{programmaticallyComp.roleLists}", "single", true, 5, "", "");
}
return dataTableTest;
}
DataTables
public class DataTables extends DataTable {
private static final long serialVersionUID = 1L;
public DataTables() {
super();
// TODO Auto-generated constructor stub
}
public DataTables(FacesContext context, Application app, String id,String style,String var,String expression,
String selectionMode, boolean paginator, int row,
String rowSelectListener, String rowUnSelectListener) {
super();
// TODO Auto-generated constructor stub
app.createComponent(DataTable.COMPONENT_TYPE);
setStyle(style + " !important;");
setSelectionMode(selectionMode);
setPaginator(paginator);
setRows(row);
setVar(var);
setMethodsExpression(this, context, app, rowSelectListener, rowUnSelectListener);
setComId(this, id);
setValueExpressions(this, context, app, expression);
}
private void setComId(DataTable comp,String id){
comp.setId(id);
}
private void setValueExpressions(DataTable comp ,FacesContext context,Application app,String expression){
ELContext elContext=context.getELContext();
ValueExpression value=app.getExpressionFactory().createValueExpression(elContext,expression ,Object.class);
comp.setValueExpression("value",value);
}
private void setMethodsExpression(DataTable comp, FacesContext context,
Application app, String rowSelectListener,
String rowUnSelectListener) {
ELContext elContext = context.getELContext();
if (JSFUtils.isInputFilled(rowSelectListener)) {
MethodExpression rowSelectListenerMethod=app.getExpressionFactory()
.createMethodExpression(elContext,
rowSelectListener, null,new Class[] {SelectEvent.class});
comp.setRowSelectListener(rowSelectListenerMethod);
}
if (JSFUtils.isInputFilled(rowUnSelectListener)) {
MethodExpression rowUnSelectListenerMethod=app.getExpressionFactory()
.createMethodExpression(elContext,
rowUnSelectListener, null,new Class[] {UnselectEvent.class});
comp.setRowUnselectListener(rowUnSelectListenerMethod);
}
}
}
I am assign the related columns by this way :
getDataTableTest();
for(RoleBean roles : roleLists){
OutputLabel outputLabelId=new OutputLabel(context,app,roles.getRoles().getRoleNum());
OutputLabel outputLabelName=new OutputLabel(context,app,roles.getDescription().getDesc());
getColDataTableIdTest().getChildren().add(outputLabelId);
getColDataTableNameTest().getChildren().add(outputLabelName);
}
getDataTableTest().getChildren().add(getColDataTableIdTest());
getDataTableTest().getChildren().add(getColDataTableNameTest());
getRowDataTable().getChildren().add(getDataTableTest());
container.getChildren().add(getRowDataTable());
OutPutLabel Class
public class OutputLabel extends HtmlOutputLabel {
public OutputLabel() {
super();
// TODO Auto-generated constructor stub
}
public OutputLabel(FacesContext context, Application app, String id,
String value) {
super();
// TODO Auto-generated constructor stub
app.createComponent(HtmlOutputLabel.COMPONENT_TYPE);
compSetId(this, id);
setValue(value);
setStyleClass(JSFUtils.BootstrapClasses.LabelsControl.toString());
}
public OutputLabel(FacesContext context, Application app, Object value) {
super();
// TODO Auto-generated constructor stub
app.createComponent(HtmlOutputLabel.COMPONENT_TYPE);
setValue(value);
}
private void compSetId(UIOutput comp, String id) {
comp.setId(id);
}
getColDataTableIdTest() :
public AceColumn getColDataTableIdTest() {
if(colDataTableIdTest==null){
colDataTableIdTest=new AceColumn(app,"ID");
}
return colDataTableIdTest;
}
getColDataTableNameTest() :
public AceColumn getColDataTableNameTest() {
if(colDataTableNameTest==null){
colDataTableNameTest=new AceColumn(app,"ID");
}
return colDataTableNameTest;
}
AceColumn class :
public class AceColumn extends Column {
private static final long serialVersionUID = 1L;
public AceColumn() {
super();
// TODO Auto-generated constructor stub
}
public AceColumn(Application app,String headerText) {
super();
// TODO Auto-generated constructor stub
app.createComponent(Column.COMPONENT_TYPE);
setHeaderText(headerText);
}
getRowDataTable()
public RowContainer getRowDataTable() {
if(rowDataTable==null){
rowDataTable= new RowContainer(context, app, false,"dataTableRowId");
}
return rowDataTable;
}
RowContainer
public class RowContainer extends HtmlPanelGroup {
public RowContainer() {
super();
// TODO Auto-generated constructor stub
}
public RowContainer(FacesContext context,Application app,boolean required,String id) {
app.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
if(required==true){
setStyleClass(JSFUtils.BootstrapClasses.Rows.toString() + " " +
JSFUtils.BootstrapClasses.Required.toString()
);
}else{
setStyleClass(JSFUtils.BootstrapClasses.Rows.toString());
}
setLayout(JSFUtils.BootstrapClasses.Layout.toString());
setId(id);
}
}
Container is the panel group that holds the component in the page
container=new ContainerFluid(context, app, "SuperPanel");
ContainerFluid
public class ContainerFluid extends HtmlPanelGroup {
public ContainerFluid() {
super();
// TODO Auto-generated constructor stub
}
public ContainerFluid(FacesContext context,Application app,String id) {
app.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
setLayout(JSFUtils.BootstrapClasses.Layout.toString());
setStyleClass(JSFUtils.BootstrapClasses.ContainerFluid.toString());
//compSetId(this, id);
setStyle("padding: 30px;");
//setId(id);
}
}
Inside the xhtml Page there is only :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ace="http://www.icefaces.org/icefaces/components">
<ui:composition template="/resources/template/master.xhtml">
<ui:define name="content">
<h:panelGroup binding="#{programmaticallyComp.container}"/>
</ui:define>
</ui:composition>
</html>
the problem is in the output of the datatable :
wrong output
and the right output is like this without the expiry date:
right output
we must assign the 'datatable' var to the output label
setDatatableVar("role");
then we must send a value expression to the output label and we must delete the for loop
OutputLabel label1= new OutputLabel(context, app,"#{role.roleNum}");
and we must assign a value expression the OutPutLabel class
private void compSetValue(UIOutput comp, FacesContext context,
Application app, String expression) {
ELContext elContext = context.getELContext();
ValueExpression valueExpression = app.getExpressionFactory()
.createValueExpression(elContext, expression, Object.class);
comp.setValueExpression("value", valueExpression);
}
and the code must be like this
setDatatableVar("role");
OutputLabel label1= new OutputLabel(context, app,"#{role.roleNum}");
OutputLabel label2= new OutputLabel(context, app,"#{role.roleName}");
getColDataTableIdTest().getChildren().add(label1);
getColDataTableNameTest().getChildren().add(label2);
getColDataTableIdTest().getChildren().add(getColDataTableIdTest());
getDataTableTest().getChildren().add(getColDataTableNameTest());
getRowDataTable().getChildren().add(getDataTableTest());
container.getChildren().add(getRowDataTable());
the out put well be like this :
Related
When I dispatch an ajax event from the Composite Component by using <cc:clientBehavior name="chartUpdated" event="change" targets="chartdata"/> I catch it in Facelet page by using <f:ajax event="chartUpdated" listener="#{bean.updateListener}">. And In backing bean I capture event of type AjaxBehaviorEvent.
public void updateListener(AjaxBehaviorEvent event){
...
}
I undertand that I can extend AjaxBehaviorEvent and pass within it object which has been changed. For example, Primefaces's Scheduler uses this approach:
<p:ajax event="eventMove" listener="#{scheduleView.onEventMove}" update="messages" />
And backing bean:
public void onEventMove(ScheduleEntryMoveEvent event) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event moved", "Day delta:" + event.getDayDelta() + ", Minute delta:" + event.getMinuteDelta());
addMessage(message);
}
Is it possible to achieve the same functionality by using Composite Component together with the #FacesComponent ?
Thank you in advance!
Nice to meet you, again :)
continuing from your previous question:
Override queueEvent() to filter interesting events (changes from specific components) and postpone their enqueue to validation phase to be able to fetch converted & validated values:
#FacesComponent("rangeComponent")
public class RangeComponent extends UIInput implements NamingContainer
{
private final List<AjaxBehaviorEvent> customEvents = new ArrayList<>();
...
#Override
public void queueEvent(FacesEvent event)
{
FacesContext context = getFacesContext();
if(event instanceof AjaxBehaviorEvent)
{
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get("javax.faces.behavior.event");
Object eventSource = event.getSource();
if("change".equals(eventName) && (from.equals(eventSource) || to.equals(eventSource)))
{
customEvents.add((AjaxBehaviorEvent) event);
return;
}
}
super.queueEvent(event);
}
#Override
public void validate(FacesContext context)
{
super.validate(context);
if(from.isValid() && to.isValid())
{
for(AjaxBehaviorEvent event : customEvents)
{
SelectEvent selectEvent = new SelectEvent(this, event.getBehavior(), this.getValue());
if(event.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES))
{
selectEvent.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
}
else
{
selectEvent.setPhaseId(PhaseId.INVOKE_APPLICATION);
}
super.queueEvent(selectEvent);
}
}
}
...
}
then add the specific event listener to your managed bean:
#ManagedBean
#ViewScoped
public class RangeBean implements Serializable
{
private static final long serialVersionUID = 1L;
private String range = "01/01/2015-31/12/2015";
public void onSelect(SelectEvent event)
{
Messages.addGlobalInfo("[{0}] selected: [{1}]", event.getComponent().getId(), event.getObject());
}
public String getRange()
{
return range;
}
public void setRange(String range)
{
this.range = range;
}
}
I try to use JSF in combination with Bean Validation. Basically, everything works well, the validation works as expected, I get the correct message, but there is an exception on my Glassfish console:
Warnung: EJB5184:A system exception occurred during an invocation on EJB MyEntityFacade, method: public void com.mycompany.testbv.AbstractFacade.create(java.lang.Object)
Warnung: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
....
....
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.
This exception occurs if I use custom constraints as well as predefined constraints.
Here is my sample code.
Sample Entity:
#Entity
#ValidEntity
public class MyEntity implements Serializable {
private static final long serialVersionUID = 3104398374500914142L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#Size(min = 2)
private String name;
public MyEntity(String name) {
this.name = name;
}
public MyEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Custom constraint:
#Constraint(validatedBy = MyValidator.class)
#Target({FIELD, METHOD, TYPE})
#Retention(RUNTIME)
public #interface ValidEntity {
String message() default "fail";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Custom validator:
public class MyValidator implements ConstraintValidator<ValidEntity, MyEntity>{
#Override
public void initialize(ValidEntity a) {
}
#Override
public boolean isValid(MyEntity t, ConstraintValidatorContext cvc) {
return false;
}
}
Sample Controller:
#Named
#SessionScoped
public class MyController implements Serializable {
private static final long serialVersionUID = -6739023629679382999L;
#Inject
MyEntityFacade myEntityFacade;
String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void saveNewEntity() {
try {
myEntityFacade.create(new MyEntity(text));
} catch (Exception e) {
Throwable t = e;
while (t != null) {
if (t instanceof ConstraintViolationException) {
FacesContext context = FacesContext.getCurrentInstance();
Set<ConstraintViolation<?>> constraintViolations = ((ConstraintViolationException) t).getConstraintViolations();
for (ConstraintViolation<?> constraintViolation : constraintViolations) {
FacesMessage facesMessage = new FacesMessage(constraintViolation.getMessage());
facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(null, facesMessage);
}
}
t = t.getCause();
}
}
}
}
Sample jsf page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head></h:head>
<h:body>
<h:form>
<h:messages id="messages" />
<h:inputText value="#{myController.text}" />
<h:commandButton value="Save" action="#{myController.saveNewEntity()}" />
</h:form>
</h:body>
</html>
The MyEntityFacade only calls persist from entity manager.
As mentioned before, the application is running fine and the correct messages are shwon, but I want to avoid this exception in the Glassfish console.
Setting the validation mode in persistence.xml to NONE as discussed here is no option, because I want a validation.
I use JSF in version 2.2, the implementation is Mojarra. The version of Bean Validation is 1.1, the implementation is Hibernate Validator.
Application Server is Glassfish 4.0.
Class-level constraints do not work with JSF. Take a look at this answer. When you press the 'Save' button JSF checks only if name has at least 2 chars and does not take into account the ValidEntity constraint. JPA, on the other hand, complains that the bean is not valid and throws an exception.
UPDATE
1) the #Size constraint is on MyEntity.name property while in the facelet you have MyController.text property. In the JSF perspective there is nothing to validate. It has no knowledge of the MyEntity at all.
2) ValidEntity is always invalid, so JPA will always throw the exception (unless you disable validation) even if you properly set the MyEntity.name in the facelet.
Im trying to create a JSF page that lets the user select X amount of ingredients, and then saves those selected ingredients to a list.
Ingredient is an object with two values, String IngredientName and int ingredientPrice.
What I want to do is to create 1 selectItem per Ingredient in an IngredientList (dynamically sized), and then save the selected items to another list of ingredients.
I've tried doing this multiple different ways but either I get classcast exceptions or the checkboxes don't appear at all.
My Bean:
#ManagedBean
#SessionScoped
public class ManagedIngredientsBean {
#EJB
IngredientBean iBean;
private List<Ingredient> ingredientList;
private List<Ingredient> checkedOptions;
private List<SelectItem> selectList;
public ManagedIngredientsBean() {
}
public String createNew(){
ingredientList = iBean.getAllIngredients();
selectList = new ArrayList<SelectItem>(ingredientList.size());
for(Ingredient i : ingredientList){
selectList.add(new SelectItem(i.getIngredientName()));
}
return "createnew.xhtml";
}
public List<SelectItem> getSelectList() {
return selectList;
}
public void setSelectList(List<SelectItem> selectList) {
this.selectList = selectList;
}
public List<Ingredient> getCheckedOptions() {
return checkedOptions;
}
public void setCheckedOptions(List<Ingredient> checkedOptions) {
this.checkedOptions = checkedOptions;
}
public List<Ingredient> getIngredientList() {
return ingredientList;
}
public void setIngredientList(List<Ingredient> ingredientList) {
this.ingredientList = ingredientList;
}
#FacesConverter(value="userConverter")
public static class UserConverter implements Converter {
public Object getAsObject(FacesContext facesContext,
UIComponent component, String value) {
return value;
}
public String getAsString(FacesContext facesContext,
UIComponent component, Object o) {
Ingredient i = (Ingredient) o;
return i.getIngredientName();
}
}
}
IngredientBean used to get the Ingredient items from the persistence database and returning them as a list:
#Stateless(name = "IngredientEJB")
public class IngredientBean {
EntityManagerFactory entFactory;
EntityManager em;
public IngredientBean() {
entFactory = Persistence.createEntityManagerFactory("NewPersistenceUnit");
em = entFactory.createEntityManager();
}
public List<Ingredient> getAllIngredients(){
TypedQuery<Ingredient> ingQuery = em.createQuery("SELECT i FROM Ingredient i", Ingredient.class);
List<Ingredient> iList = ingQuery.getResultList();
return iList;
}
}
My JSF Page:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Create New Order</title>
</h:head>
<h:body>
<h:form>
<h:selectManyCheckbox value = "#{managedIngredientsBean.checkedOptions}">
<f:converter converterId="userConverter"/>
<f:selectItem value = "#{managedIngredientsBean.selectList}" var = "item" itemLabel = "#{item.getIngredientName()}" itemValue = "#{item}"/>
</h:selectManyCheckbox>
</h:form>
</h:body>
</html>
I'm probably missing something obvious or simply misunderstanding how to use the selectManyCheckbox element but I'm completely stuck on how to fix this. Appreciate any answers on how I should be implementing this. :)
Edit: Forgot to mention, the createNew() method in the managed bean is called in the previous JSF page and redirects to this one.
your converter is broken.
first, it have to be a bean so must not be a static class.
second, it "should" be symmetric:
x.equals(c.getAsObject(ctx, comp, c.getAsString(ctx, component, x))); "should" be true.
#FacesConverter(value="userConverter")
public class UserConverter implements Converter
{
public Object getAsObject(FacesContext facesContext, UIComponent component, String value)
{
return database.loadIngredientByUniqueValue(value);
}
public String getAsString(FacesContext facesContext,UIComponent component, Object o)
{
Ingredient i = (Ingredient) o;
return i.getSomeUniqueValue();
}
}
I'm trying to create a custom component for displaying an Entity with a certain form. So I've created my #FacesComponent and he's working but only when he is not inside a loop like <ui:repeat>. When I'm using the following code, my component is displaying null values for price and photo but not for name. Do you have an explaination ?
XHTML code :
<ui:define name="content">
<f:view>
<h:form>
<ui:repeat value="#{dataManagedBean.listNewestCocktails}" var="item" varStatus="status">
<h:outputText value="#{item.price}"/> <!--working very well-->
<t:cocktailVignette idPrefix="newCocktails" name="foo" price="#{item.price}" urlPhoto="#{item.photoURI}"/> <!-- not working the getPrice here -->
</ui:repeat>
<!--<t:cocktailVignette idPrefix="allCocktails" name="OSEF" price="20" urlPhoto="osefdelurl" ></t:cocktailVignette> -->
</h:form>
</f:view>
My component code :
package component;
import java.io.IOException;
import javax.faces.context.FacesContext;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.ResponseWriter;
#FacesComponent(value = "CocktailVignette")
public class CocktailVignette extends UIComponentBase {
private String idPrefix;
private String name;
private String price;
private String urlPhoto;
public String getIdPrefix() {
return idPrefix;
}
public void setIdPrefix(String idPrefix) {
this.idPrefix = idPrefix;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getUrlPhoto() {
return urlPhoto;
}
public void setUrlPhoto(String urlPhoto) {
this.urlPhoto = urlPhoto;
}
#Override
public String getFamily() {
return "CocktailVignette";
}
#Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.write("<div id=\""+idPrefix+name+"\" class=\"cocktail-vignette\">");
writer.write("<h2>"+name+"</h2>");
writer.write("<h3>"+price+"</h3>");
writer.write("</div>");
}
}
Thanks a lot :) I'm trying but nothing is working ...
All of component's attributes which are sensitive to changes in state (e.g. the value being dependent on <ui:repeat var>, at least those which is not known during view build time but during view render time only), must delegate the storage of attribute value to the state helper as available by inherited getStateHelper() method.
Kickoff example:
public String getPrice() {
return (String) getStateHelper().eval("price");
}
public void setPrice(String price) {
getStateHelper().put("price", price);
}
Apply the same for all other attributes and get rid of the instance variable declarations. Important note is that the state helper key ("price" in above example) must be exactly the same as attribute name.
See also:
How to save state when extending UIComponentBase
I've created a picklist via PrimeFaces. Now i want to handle the selected items which are listed in the target list when i click the commandButton.
I want to pass the data through the controller and store them in my database. But everytime i call the function duallist.getTarget() it's empty.
I've crated a foreach-Loop where i want to select all items in the target list:
Controller (Bean):
private List<DTOAktivitaet> source = new ArrayList<DTOAktivitaet>();
private List<DTOAktivitaet> target = new ArrayList<DTOAktivitaet>();
private List<DTOAktivitaet> zwischen = new ArrayList<DTOAktivitaet>();
public void speicherAktiZug() {
DTOAktivitaet aktivitaet_vorgaenger = null;
for (DTOAktivitaet item : controller.getAktivitaeten()) {
if (item.toString().equals(selected)) {
aktivitaet_vorgaenger = item;
}
}
for (DTOAktivitaet aktivitaet : zwischen) {
try {
dao.aktiZugAkt(aktivitaet_vorgaenger, aktivitaet);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
public AktiListController() {
for (DTOAktivitaet ak : controller.getAktivitaeten()) {
source.add(ak);
}
aktis = new DualListModel<DTOAktivitaet>(source, target);
zwischen = aktis.getTarget();
}
JSF:
<h:form id="form" name="formular">
<h:outputText id="aktivitaet"
value="#{aktiListController.selected}" />
<p:pickList id="pickList" value="#{aktiListController.aktis}"
var="aktivitaet" itemValue="#{aktivitaet}"
itemLabel="#{aktivitaet}" converter="aktivitaetsConverter"
showSourceControls="true" showTargetControls="true" />
<h:commandButton
action="#{aktiListController.speicherAktiZug}"
value="Aktivität-Abhängigkeit anlegen" class="commandButton">
</h:commandButton>
</h:form>
Converter:
#EJB
public class AktiListConverter implements Converter {
private InitialisierungController controller = InitialisierungController
.getInstance();
DTOAktivitaet aktivitaet = new DTOAktivitaet();
String name = "";
#Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
for (DTOAktivitaet item : controller.getAktivitaeten()) {
if (item.toString().equalsIgnoreCase(arg2)) {
this.aktivitaet = item;
System.out.println(aktivitaet);
return aktivitaet;
}
}
return null;
}
#Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
this.aktivitaet = (DTOAktivitaet) arg2;
return this.name = aktivitaet.getTeambezeichnung();
}
}
My Problem: The target-List is empty before i want to store the items in my database.
I don't fully understand your code as it is not written in English but as far as I can see your Converter is written badly. As far as I can see you do a toString() and a fromString() basically. This is quite error prone and the way you did it, heavy in performance. It is a better idea to use unique ID's (business or database).
Example:
#FacesConverter(value = "aktiListConverter")
public class AktiListConverter implements Converter
{
private InitialisierungController controller = InitialisierungController.getInstance();
#Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
{
//Get object by it's unique ID
return controller.getById(Long.parseLong(arg2));
}
#Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
{
//Return object's unique ID
return ((DTOAktivitaet) arg2).getId();
}
}
In stead of using the object as itemLabel (which performs a toString()) use something that generates a nice label like getName() for a person.
itemLabel="#{aktivitaet.nameOrSomething}"
The speicherAktiZug() method doesn't really make sense to me so I came this far:
public class AktiListController
{
private List<DTOAktivitaet> source;
private List<DTOAktivitaet> target = new ArrayList<DTOAktivitaet>();
private DualListModel<DTOAktivitaet> aktis;
public AktiListController()
{
source = controller.getAktivitaeten();
aktis = new DualListModel<DTOAktivitaet>(source, target);
}
//Getters and setters
public void speicherAktiZug()
{
target = aktis.getTarget();
//target should contain the picked items here.
}
}
I see you are also using aktiListController.selected but I cannot see what it's used for.
Names of Conterter between (XHTML) and (Class Converter) is not equal.
converter="aktivitaetsConverter"
public class AktiListConverter implements Converter {...}