Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<b:selectOneMenu> and <f:selectItems> #942

Closed
dguna opened this issue May 17, 2018 · 12 comments
Closed

<b:selectOneMenu> and <f:selectItems> #942

dguna opened this issue May 17, 2018 · 12 comments
Assignees
Milestone

Comments

@dguna
Copy link

dguna commented May 17, 2018

Hello,

I just started working with Bootsfaces. I ran into problem with <b:selectOneMenu> with <f:selectITems>.
The behavior is much different than <h:selectOneMenu>, the converter class is not at all called. I don't see the converter option as well.

Here is my simplified code:

<h:outputLabel value="#{bundle.Category}" for="idCategoryProduct" />
                    <b:selectOneMenu id="idCategoryProduct" value="#{productController.selected.idCategoryProduct}" required="true" >
                        <f:selectItems value="#{categoryProductController.itemsAvailableSelectOne}"/>
                    </b:selectOneMenu>

The bean code is as follows

@FacesConverter(forClass = CategoryProduct.class)
    public static class CategoryProductControllerConverter implements Converter {

Please help me to solve this issue.

Thanks in advance

@chongma
Copy link
Collaborator

chongma commented May 17, 2018

which version are you using? converters should be working in 1.2.0+
try defining converter in <b:selectOneMenu id="idCategoryProduct" value="#{productController.selected.idCategoryProduct}" required="true" converter="categoryProductControllerConverter"> as i am not sure if forClass is supported.
also there is a label attribute of b:selectOneMenu

@dguna
Copy link
Author

dguna commented May 17, 2018

I am using 1.2.0. converter attribute is not recognised. I am trying to migrate an already existing code. This will be lot of work. It is better to give support to native <h:selectOneMenu> and add features as PF. Thanks.

@stephanrauh
Copy link
Collaborator

Oops - it might have something to do with the annotation @FacesConverter(for="entityClass"). Until five minutes ago, I simply didn't know this annotation exists. So most likely I haven't implemented it properly.

As a workaround, you can use the converter attribute of b:selectOneMenu, as described at https://showcase.bootsfaces.net/forms/converters.jsf.

@chongma
Copy link
Collaborator

chongma commented May 22, 2018

might be related to this issue...i have just noticed that if the bean has a List of SelectItem e.g.

List<SelectItem> myObjectList = new ArrayList<>();
for (MyObject myObject : myObjectDao.selectObjects()) {
	myObjectList.add(new SelectItem(myObject, myObject.getName()));
}

with an example object like:

public class MyObject {
private Long id;
private String name;

...getters setters

@Override
public String toString() {
	return "MyObject [id=" + id + "]";
}
}

then h:selectOneMenu would produce html like

<select name="j_id_9w:j_id_a7" size="1">
<option value="MyObject [id=35]">Name35</option>
<option value="MyObject [id=39]" selected="selected">Name39</option>
</select>

whereas b:selectOneMenu seems to produce something like

<select name="j_id_9w:j_id_a7" size="1">
<option value="1">Name35</option>
<option value="2" selected="selected">Name39</option>
</select>

for additional context i am trying to use converter="omnifaces.SelectItemsConverter"

@stephanrauh
Copy link
Collaborator

@dguna I'd like to hear from you. Did our clues help you? In particular, did you add the converter attribute to your <b:selectOneMenu>?

@dguna
Copy link
Author

dguna commented May 30, 2018

Sorry for the late reply. Converter is working but when I use <f:selectitem readOnlyOption="true">, then nothing happens, even the list is not displayed. It is laborious to migrate a project in this way.

@chongma
Copy link
Collaborator

chongma commented May 30, 2018

i can't see a readOnlyOption at https://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/selectItem.html. shouldn't it be itemDisabled?

@dguna
Copy link
Author

dguna commented May 30, 2018

<f:selectItem noSelectionOption="true" /> sorry, I made the mistake.

@chongma
Copy link
Collaborator

chongma commented May 30, 2018

could be related to #939 ? does the noSelectionOption usually result in a null itemValue?

stephanrauh added a commit that referenced this issue Jun 8, 2018
…notation like @FacesConverter(forClass=Some.class)
stephanrauh added a commit to TheCoder4eu/BootsFacesWeb that referenced this issue Jun 8, 2018
…nverters defined with an annotation like @FacesConverter(forClass=Some.class)
@stephanrauh stephanrauh added this to the v1.5.0 milestone Jun 8, 2018
@stephanrauh
Copy link
Collaborator

@dguna Your annotation-based converter now works. I've uploaded a developer snapshot containing the bugfix to Maven Central. See #369 how to get it. Would you mind to run a test?

Thanks in advance (and thanks for your patience)
Stephan

@dguna
Copy link
Author

dguna commented Jun 11, 2018

Hi Srephan,
It seems to work fine. This is good. Thanks.

@dguna
Copy link
Author

dguna commented Jun 12, 2018

Hi Stephan,
Sorry to bother you all. Now I ran into problem with <b:selectMultiMenu>

I am getting the following error:
javax.faces.FacesException: SelectMultiMenu only works with Strings!
<b:selectMultiMenu id="userGroupsList" value="#{userDetailsController.userGroupsList}" > <f:selectItems value="#{userDetailsController.groupsList}" var="c" itemValue="#{c}" itemLabel="#{c}"/> </b:selectMultiMenu>

both userGroupsList and groupsList are String list.

Thanks in advance

@stephanrauh stephanrauh modified the milestones: v1.5.0, v1.3.0 Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants