Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF - passing <f:param> from JSF to Backing Bean

 
Zahoor Haque
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,
I m new to JSF and 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.
and also the value that is been checked in the checkbox should pass to the bean. and in bean in doing Map.get(value from jsf)
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>

Do i have to uncomment the <managed-property> faces-config.xml
Thanks.
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, check out this excellent resource here: http://balusc.blogspot.com/2006/06/communication-in-jsf.html,
and good luck with it.

Brendan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic