Showing posts with label jsf. Show all posts
Showing posts with label jsf. Show all posts

Tuesday, March 22, 2011

Passing parameter to included page using jsp:include in JSF 1.2

If you want to pass a parameter to an included page in JSF 1.2, it is not possible to do it like this:

<jsp:include page="header.jsp">
      <jsp:param value="main" name="pageTitle"/>
</jsp:include>

No way you can retrieve the parameter in header.jsp
This is because the JSF cycle already has built up it's view. Parameters you set while rendering, are not yet in the view that jsf created for this request. You could use the c:set tag and retrieve it using a scriptlet, but we want to do it clean and use no scriptlets in jsf, right.

The trick to do it is by binding a UIInput component in the first page to a certain value, and reading that value in the included file.

Say we have a request scoped bean (called pc_Header) HeaderBean.java with variable of type UIInput and name pageTitle. Then you can set the pagetitle in your main page like this:

<h:inputHidden binding="#{pc_Header.pagetitle}" value="My Title"></h:inputHidden>

This value can be used in the included header like this:

<h:outputText value=#{pc_Header.pagetitle.value}" />

Friday, August 28, 2009

Render labels correctly with IBM JSF

If you place a jsf component like this on your page:


<h:selectOneRadio disabledClass="selectOneRadio_Disabled"
enabledClass="selectOneRadio_Enabled"
id="selectType"
required="true"
tabindex="11"
value="#{myBean.type}" layout="pageDirection">
<f:selectItems value="#{myBean.selectTypes}" />
</h:selectOneRadio>


You will notice that the labels for the radio buttons in the final html are not generated like you would want them to - the label tag goes around the text and the radio button.

There is a context parameter you can set in the web.xml, so the generation of the html is as expected.


<context-param>
<description>
Set to true to explicitly associate labels with their input elements for select one radio buttons
and select many check box lists.
</description>
<param-name>com.ibm.ws.jsf.associateLabelWithId</param-name>
<param-value>true</param-value>
</context-param>


source : http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/rweb_jsf_custom_props.html (new window)

Wednesday, August 12, 2009

"Loading" Modal Div using IBM JSF

An easy way to disable the entire screen (prevent user input) while making an ajax call in ibm's jsf implementation : use a hx:panelDialog with your loading message, and use "show" and "hide" in the behaviorAction of the elements that trigger the ajax requests.

example :


<h:selectOneMenu id="selectTopic" styleClass="selectCombobox" value="#{myBean.topic}">
<f:selectItems value="#{myBean.allTopics}" id="selectTopics"/>
</h:selectOneMenu>
<hx:behavior event="onchange"
target="selectTopic"
behaviorAction="show;get;hide"
targetAction="loading_modaldialog;pgLeafTopic;loading_modaldialog"
id="selectTopicBehavior"></hx:behavior>
<h:panelGroup id="pgLeafTopic">
<h:selectOneMenu id="selectLeafTopic" styleClass="selectCombobox" value="#{myBean.leafTopic}">
<f:selectItems value="#{myBean.leafTopics}" id="selectLeafTopics"/>
</h:selectOneMenu>
</h:panelGroup>
<hx:ajaxRefreshRequest
target="pgLeafTopic"
id="ajaxRefreshRequest2"
params="form1:selectTopic"
>
</hx:ajaxRefreshRequest>
<hx:panelDialog id="loading_modaldialog"
for=""
movable="false"
showTitleBar="false"
saveState="false">
<h:outputText id="loadingdialogtext" value="Loading Data" />
</hx:panelDialog>

This will show and hide the modal div while the leafTopic dropdown gets a refresh depending on the selected topic in the first dropdown.