waffel’s Weblog

Oktober 7, 2008

fun with h:dataTable and a4j:form

Filed under: JSF — Thomas Wabner @ 11:41 am
Tags: , , ,

I have some facelet components and want to use them in a h:dataTable. My components containing some form elements like h:inputText, command buttons and so on. To avoid scrolling, I have placed them into a a4j:form.

Now in my h:dataTable loop I call these facelet components and want to have a list of inputText components for example. But every time, I typed in something, only the last input field called correct my setValue() method. All other input components dosn’t call the setter.

Here a very small example to imagine the problem:

The datatable


<h:dataTable value="myBackingBean.list" var="currentItem">
  <h:column>
    <waffel:input item="#{currentItem}"/>
  </h:column>
</h:dataTable>

The facelet component:

  ...
  <a4j:form>
    <h:inputText size="30" value="#{item.value}"/>
    <a4j:commandButton value="ok" action="#{item.applyValue}"/>
  </a4j:form>
  ...

To get this to work you have to place a a4j:region around the a4j:form!

  ...
  <a4j:region>
    <a4j:form>
      <h:inputText size="30" value="#{item.value}"/>
      <a4j:commandButton value="ok" action="#{item.applyValue}"/>
    </a4j:form>
  </a4j:region>
  ...

Now it works fine.

Werbung

Juni 25, 2008

Reuse facelets xhtml files and taglibs from jar archives

Filed under: JSF,software,Uncategorized — Thomas Wabner @ 4:47 pm
Tags: ,

I have asked myself, if it is possible to use facelets xhtml files and taglibs from a jar file instead from the whole web application.

The short anwser: Yes, it is possible 😉

The facelets documentation gives a hint how to use the tag lib from a jar file. But you cannot found in the documentation, if it is possible also to use a xhtml file (referenced from the taglib for example). Of course facelets uses the same approach to load xhtml files from a jar file as for the tag library.

Example:
The follow tag lib definition is placed in my JAR project under /META-INF/myProject.taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<facelet-taglib>

    <namespace>https://thomaswabner.wordpress.com/waffel</namespace>

    <tag>
        <tag-name>select</tag-name>
        <source>components/select.xhtml</source>
    </tag>

</facelet-taglib>

The select.xhtml file is placed in the same project under /META-INF/components/select.xhml and contains some facelets definitions (ui component with a selectbox fo example). The point is, that facelets searches the jar archive under the /META-INF directory for the xhtml file.

Now you can simple use the tag in you web application. You only need to include the jar file with the tag library and xhtml file in you web application classpath.

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:waffel="https://thomaswabner.wordpress.com/waffel"
          version="2.0">
  <ui:component>
     <waffel:select/>
  </ui:component>
</jsp:root>

Update: See comments. I have created a small example.

Erstelle kostenlos eine Website oder ein Blog auf WordPress.com.