-
1. Re: select elements in s:selectManyListBox
pmuir Mar 31, 2008 12:41 PM (in response to haefti)Make sure the #{pictureManager.selectedPicture.pictureRightList} contains the values that should already be selected (this is no different to a <h:inputText /> for example
-
2. Re: select elements in s:selectManyListBox
haefti Mar 31, 2008 7:19 PM (in response to haefti)Hi!
Hm, it does not work.
I try to paste only the relevant parts of the code:
@Stateless @Name("pictureManager") public class PictureManager implements PictureManagerLocal { /* Logger and EntityManager injected */ private Picture selectedPicture; @DataModel private List<PictureRight> pictureRightList; @Factory(value = "pictureRightList") public void initPictureRightList() { Query query = em.createQuery("select p from PictureRight p order by name"); pictureRightList = query.getResultList(); log.info("Number of picture rights: " + pictureRightList.size()); } public String editPicture() { if (selectedPicture != null) { log.info("Chosen picture: " + selectedPicture.getPictureId()); if (selectedPicture.getPictureRightList() != null) { log.info("Number of picture rights: " + selectedPicture.getPictureRightList().size()); log.info("First picture right: " + selectedPicture.getPictureRightList().get(0).getName()); return "edit"; } } } public Picture getSelectedPicture() { return selectedPicture; } public void setSelectedPicture(Picture selectedPicture) { this.selectedPicture = selectedPicture; } }
The editPicture() method is called when selecting an option from a select box in a view before.
After invoking the method I can see in the log, that there is a value injected in selectedPicture, the object has a pictureRightList with the size of 1 and the name of the first associated pictureRight is displayed so I think pictureManager.selectedPicture.pictureRightList should contain a value but it is not selected in the select box of available rights in the following view.
<h:selectManyListbox size="10" value="#{pictureManager.selectedPicture.pictureRightList}"> <s:selectItems value="#{pictureRightList}" var="pictureRight" label="#{pictureRight.name}" /> <s:convertEntity /> </h:selectManyListbox>
(I also checked, that the associated value is one of the values of the available rights in pictureRightList.)
Could it be a problem like object identity so that the already associated object(s) do(es) not compare successfully to the items of the list of avaliable items? (Of course they use the same entity bean)
Maybe someone has another idea.
Thanks!
-
3. Re: select elements in s:selectManyListBox
pmuir Mar 31, 2008 10:57 PM (in response to haefti)For a start you can't have fields with mutators on a @Stateless bean. Make it stateful. You probably want to be in a conversation too.
-
4. Re: select elements in s:selectManyListBox
barbacena Mar 31, 2008 11:45 PM (in response to haefti)As Pete said, use a statefull bean or bijection to keep your selectedPicture.
After that, you are going to run into a @Factory update problem. You can solve this by nullifying the pictureRightList variable at the setSelectedPicture.
If none of this solve your problem, plz post your java code as is (or a full example) and facelets page.