aspose file tools*
The moose likes JSF and the fly likes JSF - SelectManyListBox doesnt populate on valeChangeevent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF - SelectManyListBox doesnt populate on valeChangeevent" Watch "JSF - SelectManyListBox doesnt populate on valeChangeevent" New topic
Author

JSF - SelectManyListBox doesnt populate on valeChangeevent

Zahoor Haque
Greenhorn

Joined: Mar 16, 2011
Posts: 4
Hi Experts,

I am trying to fire an event on a selectBooleanCheckBox and also trying to pass the param from this check box to the backing bean. and there im trying to get the values from the map using this param.

I am not getting this right. Any help is Appreciated !!

Here is my code Snippets

JSP :

<tr:column width="16%">
<f:facet name="header">
<hutputText value="Prompt Name" styleClass="tableHeader_txt"/>
</f:facet>
<h:selectBooleanCheckbox id ="chkbox2" valueChangeListener="#{preferenceBean.setNewListValues }">
<tr:forEach var="nameList" items="#{preferenceBean.newListNames}">
<f:param name="keyFromJSF" value="#{nameList} " />
<!--<f:setPropertyActionListener target="#{preferenceBean.key}" value="#{nameList}" />-->
</tr:forEach>
</h:selectBooleanCheckbox>

</tr:column>
<tr:column>
<f:facet name="header">
<trutputText value="Prompt Value" styleClass="tableHeader_txt" />
</f:facet>

<h:selectManyListbox value="#{preferenceBean.selectedPromptValues}">
<tr:forEach var="valueList" items="#{preferenceBean.newListValues}">
<f:selectItem itemLabel="#{valueList}" itemValue="#{valueList}" />
</tr:forEach>
</h:selectManyListbox>


Backing Bean :

public void setNewListValues(javax.faces.event.ValueChangeEvent event) {
checkBoxSelect = (Boolean) event.getNewValue();
if(isCheckBoxSelect()!= false)
{
FacesContext context = FacesContext.getCurrentInstance();
keyFromJSF = (String) context.getExternalContext().getRequestParameterMap().get("keyFromJSF");
setKeyFromJSF(keyFromJSF);
newListValues = new ArrayList<String>(StoreMap.get(keyFromJSF));
//newListValues.addAll(StoreMap.get(keyFromJSF));
System.out.println(" After Passing Param : " + newListValues);
}
}

faces-config.xml :

<!-- <managed-property>
<property-name>keyFromJSF</property-name>
<value>#{param.keyFromJSF}</value>
</managed-property> -->


I am trying to pass the parameter from jsp to the bean. Is this the right way to do it.
Thanks.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Zahoor

The valueChangeListener setNewListValues is not fired becuase you don't post the page to the server, you need to make a post with a commandButton or the most practical submit the form when the user select the checkbox whith the function submit(), so your listener will be fired.

I hope this help you with your problem
Regards
Cesar

When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Zahoor Haque
Greenhorn

Joined: Mar 16, 2011
Posts: 4
Thanks Cesar for your help. much appreciated!

but I would like to know that the parameter that iam passing from JSF <f:param> tag. and retieving the same within a bean using facesContex.getRequestParameterMap().get("paramName")

is the right method to do it.

please take a look on the code.

JSF:

<tr:column width="16%">
<f:facet name="header">
<hutputText value="Prompt Name" styleClass="tableHeader_txt"/>
</f:facet>
<h:selectBooleanCheckbox id ="chkbox2" valueChangeListener="#{preferenceBean.setNewListValues}" onchange="this.form.submit()">
<tr:forEach var="pName" items="#{preferenceBean.newListNames}">
<f:selectItem itemLabel="#{pName}" itemValue="#{pName}" />
<f:param name="keyFromJSF" value="#{pName}" />
<!--<f:setPropertyActionListener target="#{preferenceBean.keyFromJSF}" value="#{pName}" />-->
</tr:forEach>
</h:selectBooleanCheckbox>

</tr:column>
<tr:column width="16%">
<f:facet name="header">
<trutputText value="Prompt Value" styleClass="tableHeader_txt" />
</f:facet>
<h:selectManyListbox value="#{preferenceBean.selectedPromptValues}">
<tr:forEach var="pValue" items="#{preferenceBean.newListValues}">
<f:selectItem itemLabel="#{pValue}" itemValue="#{pValue}" />
</tr:forEach>
</h:selectManyListbox>
</tr:column>

The parameter that iam passing from checkbox based on that iam trying to getvalues from the map. and display new values in the selectManyListBox for every checkBox selection.

Bean:

public void setNewListValues(javax.faces.event.ValueChangeEvent event) {

setCheckBoxSelect((Boolean) event.getNewValue());

if(isCheckBoxSelect()!= false)
{
FacesContext context = FacesContext.getCurrentInstance();
keyFromJSF = context.getExternalContext().getRequestParameterMap().get("keyFromJSF");
setKeyFromJSF(keyFromJSF);
newListValues = new ArrayList<String>(StoreMap.get(keyFromJSF));
System.out.println(" After Passing Param (SETTER): " + newListValues);
}
else{
newListValues = new ArrayList<String>();
}
}


Do i have to set the property in the faces-config.xml ?
like

<managed-bean>
<managed-bean-name>preferenceBean</managed-bean-name>
<managed-bean-class>PreferenceBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<!--<managed-property>
<property-name>keyFromJSF</property-name>
<value>#{param.keyFromJSF}</value>
</managed-property>-->

</managed-bean>

Thanks.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Zahoor
Yes you can use the f:param but I think this doesn't work, I suggest you to use the f:attribute like this:

And you can get this value in this way:

You don't need to set this value with the managed property.
I hope this help you
Regards
Cesar
Zahoor Haque
Greenhorn

Joined: Mar 16, 2011
Posts: 4
Cesar Loachamin wrote:Hi Zahoor
Yes you can use the f:param but I think this doesn't work, I suggest you to use the f:attribute like this:

And you can get this value in this way:

You don't need to set this value with the managed property.
I hope this help you
Regards
Cesar[/quote


Thank you Cesar. It got resolved.
 
 
subject: JSF - SelectManyListBox doesnt populate on valeChangeevent