Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:27:31+00:00 2026-06-10T02:27:31+00:00

I’ve created a picklist via PrimeFaces. Now i want to handle the selected items

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:27:32+00:00Added an answer on June 10, 2026 at 2:27 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.