在向下钻取SelectOneMenus(Parent-Child)中显示值 [英] Display values in drill-down SelectOneMenus (Parent-Child)
问题描述
当我填充两个 selectOneMenu
的深入选择时,我有恼人的问题。第一个菜单是扇区,它控制另一个 Categorty 。我根据扇区加载了类别的选择,所有这些工作正常。
I have irritating problem when I populate a drill-down selection of two selectOneMenu
. The first menu is Sector which controls the other one Categorty. I load the selection for the Category depending on Sector and all of this is working fine.
但是当我编辑一个具有类别(有一个)扇区的业务对象时它。首次加载 edit.xhtml 页面时,不会显示类别。我知道 SessionScoped
支持bean中的值是正确的。如果我选择另一个扇区类别然后返回到初始扇区,那么类别得到正确设置就会保留在第一个位置。
But when I edit a business object that has a Category (has one) Sector attached to it. The Category doesn't get display when first loading the edit.xhtml page. I know the value is correct in the SessionScoped
backing bean. If I select another Sector-Category and then go back to the initial Sector, the Category get properly set at it was persisted in the first place.
POJO类(扇区) -Category)具有 hashCode()
和 equals(对象对象)
函数。
The POJO classes (Sector-Category) has the hashCode()
and equals(Object object)
functions.
我为POJO对象生成了CRUD生成的JSF转换器,但我不认为这会导致问题。我认为第二个 selectOneMenu
由于某种原因不会显示其值。如果我将父(Sector)翻转到其他东西并返回初始状态,则显示来自manged bean的正确值。
I have CRUD generated JSF converters for the POJO object, but I don't think this is causing the problem. I think the second selectOneMenu
don't display its value as it should for some reason. If I flip the parent (Sector) to something else and the back to the initial state, the correct value from the manged bean get displayed.
我可以制作类别 selectOneMenu
组件显示托管bean中的值?
Ho can I make the Category selectOneMenu
component display the value in the managed bean?
问候Chris
面临错误消息
FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(ERROR 2), summary=(No activity selected), detail=(No activity selected)]
Edit.xhtml
Edit.xhtml
...
<h:outputLabel value="Sector:" />
<h:selectOneMenu id="sectorSelector" value="#{activityController.selectedSector}" title="#{bundle.CreateSectorLabel_sectorName}" required="false" requiredMessage="#{bundle.CreateSectorRequiredMessage_sectorName}"
valueChangeListener="#{activityController.changeSectorMenu}"
disabled="#{activityController.activityStatusOngoing or activityController.activityStatusComplete}">
<f:ajax event="change" execute="@this" render="categoryMenu"/>
<f:selectItems value="#{sectorController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="Category:" />
<h:selectOneMenu id="categoryMenu" value="#{activityController.selectedCategory}" title="#{bundle.CreateSectorLabel_sectorName}"
required="true" requiredMessage="#{bundle.CreateCategoryRequiredMessage_sector}"
disabled="#{activityController.activityStatusOngoing}" rendered="true">
<f:selectItems value="#{activityController.categorySelection}"/>
</h:selectOneMenu>
...
类别的控制器bean
Controller bean for Category
@ManagedBean(name = "categoryController")
@SessionScoped
public class CategoryController implements Serializable{
....
@FacesConverter(forClass = Category.class)
public static class CategoryControllerConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
CategoryController controller = (CategoryController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "categoryController");
return controller.ejbFacade.find(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuffer sb = new StringBuffer();
sb.append(value);
return sb.toString();
}
@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Category) {
Category o = (Category) object;
return getStringKey(o.getIdCategory());
}
else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + CategoryController.class.getName());
}
}
}
POJO对象的一部分
Part of POJO object
...
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idCategory")
private Integer idCategory;
...
推荐答案
这不是我首先想到的是转换器。这是两个 selectOneMenu
的渲染。这是我对xhml文件所做的更改。感谢您的时间和精力,问候Chris。
It was not the Converters as I first thought. It was the rendering of the two selectOneMenu
. This is the changes I did to the xhml file. Thank you for your time and effort, greetings Chris.
Edit.xhml
Edit.xhml
<h:outputLabel value="Sector:" />
<h:selectOneMenu id="sectorSelector" value="#{activityController.selectedSector}" title="#{bundle.CreateSectorLabel_sectorName}" required="false" requiredMessage="#{bundle.CreateSectorRequiredMessage_sectorName}"
valueChangeListener="#{activityController.changeSectorMenu}" immediate="true"
disabled="#{activityController.activityStatusOngoing or activityController.activityStatusComplete}">
<a4j:ajax event="change" execute="@this categoryMenu" render="categoryMenu"/>
<f:selectItems value="#{sectorController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="Category:" />
<h:selectOneMenu id="categoryMenu" value="#{activityController.selectedCategory}" title="#{bundle.CreateSectorLabel_sectorName}"
binding="#{activityController.categoryMenu}"
required="true" requiredMessage="#{bundle.CreateCategoryRequiredMessage_sector}"
disabled="#{activityController.activityStatusOngoing}">
<f:selectItems value="#{activityController.categorySelection}"/>
</h:selectOneMenu>
这篇关于在向下钻取SelectOneMenus(Parent-Child)中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!