我有一个问题,我需要你的帮助!我想要得到的p值选择:selectOneListbox当我点击一棵树,但价值总是空的,即使我点击号码:selectOneListbox第一。这是我的XHTML code:
I have a problem and I need your helps!!! I want to get selected value of p:selectOneListbox when I click on a tree, but the value is always null, even though I clicked on p:selectOneListbox first. Here is my xhtml code:
<h:form>
<p:selectOneListbox id="selectRole"
value="#{grandUseAuthoritiesBean.selectedRoleId}"
filter="true" filterMatchMode="contains">
<f:selectItems value="#{grandUseAuthoritiesBean.roleList}"
var="role" itemLabel="#{role.code}" itemValue="#{role.roleId}" />
</p:selectOneListbox>
<p:tree value="#{grandUseAuthoritiesBean.root}"
selectionMode="single" var="node"
style="font-size:13px; width:100%;border-width:0">
<p:treeNode icon="ui-icon-calculator">
<h:outputText value="#{node}" />
</p:treeNode>
<p:ajax event="select" update="@([id$=privilegeChecbox])"
listener="#{grandUseAuthoritiesBean.onNodeSelect()}">
</p:ajax>
</p:tree>
</h:form>
和这里是我的管理bean的code:
and here is my manage bean's code:
public String selectedRoleId;
public String getSelectedRoleId() {
return selectedRoleId;
}
public void setSelectedRoleId(String selectedRoleId) {
this.selectedRoleId = selectedRoleId;
}
public void onNodeSelect(NodeSelectEvent event) {
if (selectedRoleId!=null)
System.out.println("selected Role Id: "+ this.selectedRoleId);
}
我不能打印变量selectedRoleId怎么把它为空,但如果我用一个button'method来调用这个变量,我可以得到它的价值。我该怎么办?感谢您阅读我的问题!
I can't print the variable "selectedRoleId" coz it is null but if I use a button'method to call this variable, I can get its value. What should I do? Thanks for reading my question!
当你选择一些从列表框中,直到您发送的形式或做部分发这么因此空值,它不支持bean里面看到的东西是。加入部分处理为&LT;电话号码:selectOneListbox&GT;
,并再次检查:
The thing is when you choose something from listbox it is not visible inside backing bean until you send a form or do a partial sending so hence null value. Add partial processing to <p:selectOneListbox>
and check again:
&LT;电话号码:AJAX程序=@这个partialSubmit =真/&GT;
<p:ajax process="@this" partialSubmit="true" />
还有类似的话题: http://stackoverflow.com/a/14988129/3803447