Put Hibernate Objects in f:selectItems and retrieve them after submit

Hi,
My question is if there is a convenient way to put a list of hibernate objects in combobox and retrieve the selected one after the user submitted the form.
What I do now is this:
I retrieve a list of Hibernate objects and create a list of selectItems, using their id as the value and their name as the description.
Example:
public List<SelectItem> getCountries() {
          List<SelectItem> re = new ArrayList<SelectItem>();
          for (Country countries : this.dao.getCountries()) {
               Short id = countries.getIsoCountrycode();
               String desc = countries.getName();
               SelectItem item = new SelectItem(id, desc);
               re.add(item);
          return re;
In the save-method i use another dao method to retrieve the country object by using the id (isocountrycode). This seems very inefficient to me, as i retrieve the country object which i already have in memory to feed the combobox in the first place.
Is there a better way?
Thanks in advance.

Looks like I and BalusC interpreted your questions differently.
The way I have implemented this case is to have get and set methods for the selectedProperty in my bean.
I also have the change propertyChanged method that sets the session attribute whenever the user changes the selection.
       public String getSelectedPropertyType() {
            return this.selectedPropertyType;
       public void setSelectedPropertyType(String selectedPropertyType) {
            this.selectedPropertyType = selectedPropertyType;
            HttpServletRequest request = getHttpRequest();
            request.getSession().setAttribute("selectedPropertyType", selectedPropertyType);
       public void propertyTypeSelectionChanged(ValueChangeEvent event) {
            if (event.getNewValue() == null) return;
            String newValue = (String) event.getNewValue();
            setSelectedPropertyType(newValue);
       }Whenever you need the currently selected property, you would just need to get the #(myBean.selectedProperty).
If you find a simpler solution than this, please let me know.

Similar Messages

  • My contacts are not updating from the iCloud. How can I actively go and retrieve them?

    My contacts are not updating from the iCloud even with "push" on. How can i actively go and retrieve them?

    Hello there, Lk354.
    The following Knowledge Base article offers up some great recommendations for troubleshooting issues with using iCloud Contacts:
    Get help using iCloud Contacts
    http://support.apple.com/kb/TS3998
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • How to store images in database and retrieve them back to page?

    Well I don't know how to store an image file to a database (say MSSQL) from the JSP and retrieve it back whenever needed and put it on the JSP page? Please help me.

    I am not sure how to store images in database but what you can do is store the image into particular folder using FileOutputStream and its unique name into the database...and than retrieve it from the folder using that name retrieved from database...
    <%
    response.setContentType("text/html");
    response.setHeader("Cache-control","no-cache");
    String err = "";
    String lastFileName = "";
    String contentType = request.getContentType();
    String boundary = "";
    final int BOUNDARY_WORD_SIZE = "boundary=".length();
    System.out.println("contentType --> "+contentType);
    System.out.println("BOUNDARY_WORD_SIZE --> "+BOUNDARY_WORD_SIZE);
    if(contentType == null || !contentType.startsWith("multipart/form-data"))
    err = "Ilegal ENCTYPE : must be multipart/form-data\n";
    err += "ENCTYPE set = " + contentType;
    else
    boundary = contentType.substring(contentType.indexOf("boundary=") + BOUNDARY_WORD_SIZE);
    System.out.println("boundary --> "+boundary);
    boundary = "--" + boundary;
    try
    ServletInputStream sis = request.getInputStream();
    byte[] b = new byte[1024];
    int x=0;
    int state=0;
    String name=null,fileName=null,contentType2=null;
    java.io.FileOutputStream buffer = null;
    while((x=sis.readLine(b,0,1024))>-1)
         System.out.println("************ x ********** "+x);
         String s = new String(b,0,x);
                   System.out.println("************ s ********** \n"+s);
         if(s.startsWith(boundary))
         state = 0;
         System.out.println("name="+name);
         System.out.println("filename="+fileName);
         name = null;
         contentType2 = null;
         fileName = null;
         else if(s.startsWith("Content-Disposition") && state==0)
              System.out.println("-- 1 --");
              state = 1;
              System.out.println("s.indexOf(filename=) --> "+s.indexOf("filename="));
              if(s.indexOf("filename=") == -1)
                   name = s.substring(s.indexOf("name=") + "name=".length(),s.length()-2);
                   System.out.println("after name substring 1 "+name);
              else
                   name = s.substring(s.indexOf("name=") + "name=".length(),s.lastIndexOf(";"));
                   System.out.println("after name substring 2 "+name);
                   fileName = s.substring(s.indexOf("filename=") + "filename=".length(),s.length()-2);
                   System.out.println("fileName --> "+fileName);
                   //String fileName1 = s.substring(s.indexOf("filename=") + "filename=".length(),s.length());
                   //System.out.println("fileName1 -->"+fileName1);
                   if(fileName.equals("\"\""))
                   fileName = null;
                   else
                        String userAgent = request.getHeader("User-Agent");
                        System.out.println("userAgent --> "+userAgent);
                        String userSeparator="/"; // default
                        if (userAgent.indexOf("Windows")!=-1)
                        System.out.println("test --> "+"\\");
                        userSeparator="\\";
                        if (userAgent.indexOf("Linux")!=-1)
                        userSeparator="/";
                        System.out.println("userSeparator "+userSeparator);
                        System.out.println("fileName before inserting userSeparators "+fileName);
                        fileName = fileName.substring(fileName.lastIndexOf(userSeparator)+1,fileName.length()-1);
                        System.out.println("fileName after userSeparators "+fileName);
                        if(fileName.startsWith( "\""))
                        fileName = fileName.substring( 1);
              name = name.substring(1,name.length()-1);
              System.out.println("name 2 --> "+name);
              System.out.println("final file name "+fileName);
              if (name.equals("file"))
                   if (buffer!=null)
                   buffer.close();
                   lastFileName = fileName;
                   buffer = new java.io.FileOutputStream("/Documents and Settings/sunil/Desktop/images/"+fileName);
         else if(s.startsWith("Content-Type") && state==1)
                             System.out.println("-- 2 --");
              state = 2;
              contentType2 = s.substring(s.indexOf(":")+2,s.length()-2);
              System.out.println("contentType2 --> "+contentType2);
         else if(s.equals("\r\n") && state != 3)
                   System.out.println("-- 3 --");
              state = 3;
         else
              System.out.println("-- 4 --");     
              if (name.equals("file"))
              System.out.println("Final x :: "+x);     
              buffer.write(b,0,x);
    }     // while closing
    sis.close();
    buffer.close();
    }catch(java.io.IOException e)
    err = e.toString();
    boolean ok = err.equals("");
    if(!ok)
    out.println(err);
    else
    %>
              <SCRIPT language="javascript">
              history.back(1);
              alert('Uploaded <%=lastFileName%>');
              window.location.reload(false);
              </SCRIPT>
    <%
         out.println("done");
    %>
    </BODY>
    </HTML>
    I think it will solve ur problem..

  • Storing an array of checkbox booleans into preferences and retrieving them

    Just wondering how to go about storing an array of JCheckBoxes into a preference and retrieving it. There's 32 checkboxes so if they select, say, 6 of these randomly it should store it in a preference file and retrieve it when the application is loaded so that the same 6 checkboxes remain selected. I'm currently getting a stack overflow error, though.
    import java.util.prefs.*;
    public class Prefs {
         Preferences p;
         GUI g = new GUI();
         public Prefs() {
              p = Preferences.userNodeForPackage(getClass());
              g = new GUI();
         public void storePrefs() {
              for (int i = 0; i < g.symptoms.length; i++) {
                   p.putBoolean("symptoms", g.symptoms.isSelected());
         public void retrievePrefs() {
              for (int t = 0; t < g.symptoms.length; t++) {
                   p.getBoolean("symptoms", g.symptoms[t].isSelected());
    symptoms is the array of checkboxes in the GUI class. Not sure where I am going wrong here. I can do it with strings from textfields etc but this is proving to be an annoyance. :(
    Thanks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Actually, I have a better example, see below
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.util.prefs.*;
    public class PreferencesTest {
        private Preferences prefs;
        public static final String PREF_OPTION = "SELECTED_MENU_ITEM";
        public void createGui() {
            prefs = Preferences.userNodeForPackage(this.getClass());
            JMenuItem exitAndCloseMenuItem = new JMenuItem("Exit");
            exitAndCloseMenuItem.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
            JMenu fileMenu = new JMenu("File");
            fileMenu.add(exitAndCloseMenuItem);
            JCheckBoxMenuItem[] preferenceItems = {
                new JCheckBoxMenuItem("pref 1"),
                new JCheckBoxMenuItem("pref 2"),
                new JCheckBoxMenuItem("pref 3"),
                new JCheckBoxMenuItem("pref 4")};
            int selectedMenuItem = prefs.getInt(PREF_OPTION, 0);
            preferenceItems[selectedMenuItem].setSelected(true);
            ButtonGroup preferencesGroup = new ButtonGroup();
            JMenu preferenceMenu = new JMenu("Preferences");
            for(int i = 0;i<preferenceItems.length;i++){
                preferenceItems.setActionCommand(Integer.toString(i));
    preferenceItems[i].addActionListener(new menuItemActionListener());
    preferencesGroup.add(preferenceItems[i]);
    preferenceMenu.add(preferenceItems[i]);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(preferenceMenu);
    JFrame f = new JFrame("Prefernce Test");
    f.setJMenuBar(menuBar);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    public static void main(String[] args){
    new PreferencesTest().createGui();
    class menuItemActionListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    JCheckBoxMenuItem jcbm = (JCheckBoxMenuItem)e.getSource();
    prefs.put(PREF_OPTION, jcbm.getActionCommand());

  • Can I put apps on an external drive and run them from there?

    I want to know can I put apps downloaded from the Mac App store onto an external hard drive and launch them from there? The storage on my mac is full and I want to put apps onto an external drive to create more space on my mac.

    Bad idea.  See this:
    https://discussions.apple.com/thread/3472949?q=run apps on an external drive
    Ciao.

  • Need an app or a script to find a list of files and retrieve them

    A few years ago at an old job I used an application that could search a hard drive for a list of images all in one shot. The names of the images were typed into a txt file. the text file was used as the search list and the application would report back if the images were found and it would retrieve them. Where can I get my hands on something like This or can it be built in Automator?

    'I used an application that could search a hard drive for a list of images all in one shot ... and it would retrieve them.' - desired result is too vague.
    'Where can I get my hands on something like this ... - perform a 'Google' or equivalent search.
    "... or can it be built in Automator?' - possibly yes.
    On your behalf the above request is re-written below.
    Can someone assist me in AppleScript scripting. I am trying to open a '.txt' file which lists on each line a file to search for, and if found - to open its containing folder. Is such a process also possible with 'Automator'? Thank you for any assistance.
    One possible AppleScript solution:
    -- Code starts here --
    set tFile to read (choose file) -- One was to obtain the file, to open.
    set tPars to paragraphs of tFile -- create a list of paragraphs of selected file.
    repeat with i in tPars -- Cycle through the list of paragraphs.
    with timeout of 0 seconds -- Prevent AppleScript timeout error.
    set tItems to paragraphs of (do shell script ("locate " & (quoted form of i))) -- Obtain list of found filename files.
    end timeout
    repeat with j in tItems -- Cycle through the list of found file.
    try
    set {oAStid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"} -- Extract container of file.
    set fPath to text items 1 through -2 of j
    set AppleScript's text item delimiters to "/"
    set fPath to fPath as string
    set AppleScript's text item delimiters to oAStid
    do shell script ("open " & fPath) -- Open container of file.
    end try
    end repeat
    end repeat
    -- Code ends here --
    If the above sample code is not exactly what you seek - then edit the code accordingly; and / or post requests with specific details.
    'Is such an action also possible with 'Automator'?' - please post an properly constructed request to the 'Tiger - Automator'
    forum.

  • If my photos are saved to my I cloud can I delete them of my phone and retrieve them again later

    If my photos are backed up to my I cloud can I delete them of my phone and be able to retrieve them at a later date?

    Read this Discussion...
    https://discussions.apple.com/message/22184833#22184833
    More Info
    See  >  Photo Stream FAQ
    From Here  >  http://www.apple.com/support/icloud/photo-stream/

  • Passing Parameters and Retrieving them

    Hi,
    I am trying to learn the JSC2 IDE.Would like to pass a parameter from all my JSP pages.I will have to retrieve this parameter and use it for further processing.I have two things here.
    1.How to pass parameters from say from a hyperlink.
    2.How to retrieve them and use it fro further processing.
    Hope to hear from you.
    Thanks.
    ramdsp.

    Hi,
    Go through the tutorials "Sharing Data Between Two
    Pages" and "Understanding Scope and Managed Beans".
    These are available at:
    http://developers.sun.com/prodtech/javatools/jscreator
    /learning/tutorials/index.jsp
    These should be of help to you
    Cheers
    GirishI do understand how to share data between two pages!
    I just don�t know (the best way) to keep request variables between multiple requests (without using session variables).
    Question: What would happen if I had one button on the last page of the tutorial "Sharing Data between Two Pages". I mean, that button would make a post on the same page and would try to get data from the request bean (which does not exist anymore).
    Best regards,
    Nuno Ferreira

  • Using Access to store OLE objects like Excel , Word docs and retrieve them

    Hi folks,
    I need a solution for this problem guys.
    The logic is like this : A portable exe file and a database. Database contains files stored ( embedded ) in it like Excel , Word , notepad etc.
    On running the exe file and giving necessary prompts or combo entries, it should display all files related to the selection and On clicking the link the document should open itself.
    Why I use Access : Most of the PC contains MS Office. Otherwise I have to use a lightweight protable database.
    Also it should be able to store files into it. As far as I know , Access can store excel and images etc. Is there any other protable db capable of storing excel and word docs.
    After storing how do I retrieve the file. I have read about displaying images. What about excel files...

    Portable as in the sense every one can cary the file and the MS access database and can access data whenever they want . They can carry it in their flash drive / USB drive. Only the data base would get updated with the data. So in effect , One could access the updated documents by the means of a query.
    This should work in Windows environment

  • UDT's and Retrieving them

    How do we retrieve a specific column within a UDT
    For example we have a table Employees and within that table is a column Address and the address is a UDT with city, country, etc
    How can i retrieve the country only?

    SQL> create type Address as Object (
      2    city varchar2(50),
      3    state varchar2(2)) ;
      4  /
    Type created.
    SQL> create table Addr_Book (Name Varchar2(20), addr Address) ;
    Table created.
    SQL>
    SQL> insert into Addr_Book values ('SAMPLE', Address('Any City', 'AA')) ;
    1 row created.
    SQL>
    SQL> select t.addr.city from addr_book t ;
    ADDR.CITY
    Any City
    1 row selected.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • How to put  jsp/servlets on the oc4j and view them with browser

    I have no experience with it.
    perhaps with: localhost:8888/ ???
    witch xml-files must I configure??
    thank you

    I m new in jboss application server with myeclipse plateform.
    im unable to solve this error.which are occured doring the starting of server in my eclipse.
    How to compile jsp project on the plateform of Myeclipse and jboss
    hi :-) this is not eclipse forum and not that sure about your problem but i'll try to answer :-)
    i'm not sure how you create your war but there something wrong with your web.xml. kindly check it :-)
    by d way, you can deploy your project in my-eclipse by
    - right click on the project then select my-eclipse > Add and Remove Project Deployment's
    - a new window will open and you can now configure how you deploy your project :-)
    other alternative edit your jboss-service.xml then put something like this
    <attribute name="URLs">deploy/, file:/D:/workspace/deploy</attribute>
    (note, change the path according to your needs)
    regards,

  • How to add dynamic name value pair to html link and retrieve them?

    *topic
    Someone, please help me with a code example. A simple example will do.

    And the setClientAttributes() takes Set object, so i added ClientAttributeTag and then set it in HashSet. Is this the way to do it ??
    and how can i set string value in ClientAttributeTag.setValue() ??
    Please help.
    Sudeep

  • Object freezing when clicking and then releasing after moving mouse

    Hi there,
    When I want to select on object, I click on it.
    Then, the object freeze.
    I move my mouse wherever I want, wait 1-2 seconds, and the object comes where I am with my mouse.
    Could someone explain me what is the problem ? Is there an option checked that shouldn't ?
    Thanks a lot
    Running on yosemite 10.10.3 and AI CC14 18.1.1

    Finally, it's seems like it was an app I installed recently, called "rightzoom".
    I uninstalled it, and the problem seems gone. A bit weird, because rightzoom had AI in his exceptions.
    Anyway, here is a post about the problem : https://discussions.apple.com/thread/2796058?tstart=0
    Thanks a lot

  • Where does Firefox store my bookmarks and how can I retrieve them after reinstalling Firefox.I had to restore and reinstall Windows XP(32).

    I have reteieved all my documents and settings and have recovered my E8 "Favorites" , but I can't find my FF bookmarks.

    Bookmarks are stored in the '''places.sqite''' file in your Profile folder. Also, there are bookmark backup files in the \bookmarkbackups\ folder in your Profile folder.
    https://support.mozilla.com/en-US/kb/Profiles#w_how-do-i-find-my-profile
    http://support.mozilla.com/en-US/kb/Recovering+important+data+from+an+old+profile

  • How to Store bollean selection values and retrieve them in runtime?

    I have an array of bolleans representing a channel of a device. Now , when the user turns on the channel the selected channel array are supposed to be stored. Now when the user selects device 2 (using a ring function) the list refreshes t5he channel names and resets the bollean array to their default values and the new selection values are to be stored. Now if the user wants, he should revert back to device 1 and can review what all channels he had selected for Device 1. How can this functionality be achieved?
    Labview Learner
    Attachments:
    1.PNG ‏14 KB
    2.PNG ‏14 KB

    You need to store the boolean array somewhere.  I would likely just use a shift register
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for

  • Problem with JAVA1.3 on HP_UX 11

    I run my application using BC4J (jbo tags) on HP_UX 11 with JAVA1.3 with a lot of memmory >2GB. But sometimes java hangs and nothing is not usefull to refresh application, I must use kill -9 <PID of java> to restart it. Please can you help me, what i

  • Need some expert help on this one

    My PPC 10.4.11 mac is running very very slow with plenty of disk space and when I try to verify permission, repair permissions etc. disk utility freezes up to the point where I have to cold shut off the computer. Issues started yesterday when a page

  • What does this icon mean?

    Hello, My iPhone 4 battery is draining 1% on every 3 minutes. I fully charged iPhone and removed all the apps from multi-tasking expect the Apple pre-built apps. Even I turned off all the location services, notifications. Reduced the brightness and t

  • Cost center material to Stock material

    Dear All, Wishing all a Happy Sankranthi, We procured pc material for cost center (i.e Without material number - PR,PO,GRN and GI for 1 pc done). Later out of 2 pcs 1 pc issued and remaining 1 pc want to consider as stock material against a material

  • IE8 and ADF 11g

    Hi, has anyone tried to run an ADF 11g Application on IE8? Is it working? Kind Regards, Friedrich