3 Replies Latest reply: Jun 6, 2012 1:04 AM by Jose Alvarez de Lara RSS

JSF comparision operators don't work

Jose Alvarez de Lara Novice

Hi,

 

I am trying in a xhtml file the following,

 

<c:choose>
   <c:when test="#{_mensaje.respuesta.length() gt 10}">
     <h:link id="viewRespuesta" value="#{_mensaje.respuesta.substring(0, 9)}..." outcome="respuesta" style="white-space: nowrap;">
       <f:param name="id" value="#{_mensaje.id}"/>
    </h:link>
  </c:when>
  <c:otherwise>
     #{_mensaje.respuesta}
  </c:otherwise>
</c:choose>

 

What I pretend is if  the string length > 10 resume in a link, otherwise show the string.

The problem is that  be what be the length of the string it always show the complete string

And I do not know where the error is.

 

Regards,

Jose

  • 1. Re: JSF comparision operators don't work
    Jose Alvarez de Lara Novice

    Regarding my issue I have two questions,

     

    1) The dependency I added is the one as follows,

     

    <dependency>

       <groupId>javax.servlet</groupId>

       <artifactId>jstl</artifactId>

       <version>1.1.2</version>

    </dependency>

     

    Is that correct?

     

    2) I have been googling and I have not could put light about the namespace,

     

    Is it xmlns:c="http://java.sun.com/jsp/jstl/core" or without /jsp/ as follows xmlns:c="http://java.sun.com/jstl/core"?

     

    Kind regards,

    Jose

  • 2. Re: JSF comparision operators don't work
    Jose Alvarez de Lara Novice

    I have taken some information just googling.

     

    I mean,

     

    https://community.jboss.org/message/640301

    https://issues.jboss.org/browse/RF-7261

     

    So I have changed my code leaving as follows,

     

     

    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:s="http://jboss.org/seam/faces"
                    xmlns:c="http://java.sun.com/jstl/core"
                    template="/WEB-INF/layout/template.xhtml">
                    
        <ui:define name="header">
            Table mensaje
        </ui:define>
    
        <ui:define name="main">
    
            <div class="section">
    
             <span class="errors">
                <h:messages id="messages" globalOnly="true"/>
             </span>
             
            </div>
    
            <h:panelGroup id="displaySessions">
                <div class="section">
                <fieldset>
                    <h:outputText id="noMensajeMsg" value="No Mensajes Found" rendered="#{empty mensajeList}"/>
                    <h:form id="mensajeSelectionForm">
                        <h:dataTable id="mensajeList" value="#{mensajeList}" var="_mensaje" rendered="#{not empty mensajeList}"
                                     columnClasses=",,,,action">
                            <h:column id="asuntoCol">
                                <f:facet id="asuntoFct" name="header">Asunto</f:facet>
                                #{_mensaje.asunto}
                            </h:column>
                            <h:column id="emailCol">
                                <f:facet id="emailFct" name="header">Email</f:facet>
                                #{_mensaje.email}
                            </h:column>
                            <h:column id="fechaEntradaCol">
                                <f:facet id="fechaEntradaFct" name="header">Fecha Entrada</f:facet>
                                #{_mensaje.fechaEntrada}
                            </h:column>
                            <h:column id="contenidoCol">
                                <f:facet id="contenidoFct" name="header">Contenido</f:facet>
                                <c:choose>
                                    <c:when test="#{_mensaje.contenido.length lt 10}">
                                        #{_mensaje.contenido}
                                    </c:when>
                                    <c:otherwise>
                                        <h:link id="viewContenido" value="#{_mensaje.contenido.substring(0, 9)}..." outcome="contenido" style="white-space: nowrap;">
                                            <f:param name="id" value="#{_mensaje.id}"/>
                                        </h:link>
                                    </c:otherwise>
                                </c:choose>
                            </h:column>
                            <h:column id="fechaSalidaCol">
                                <f:facet id="fechaSalidaFct" name="header">Fecha Salida</f:facet>
                                #{_mensaje.fechaSalida}
                            </h:column>
                            <h:column id="respuestaCol">
                                <f:facet id="respuestaFct" name="header">Respuesta</f:facet>
                                <c:choose>
                                    <c:when test="#{_mensaje.respuesta.length lt 10}">
                                        #{_mensaje.respuesta}
                                    </c:when>
                                    <c:otherwise>
                                        <h:link id="viewRespuesta" value="#{_mensaje.respuesta.substring(0, 9)}..." outcome="respuesta" style="white-space: nowrap;">
                                            <f:param name="id" value="#{_mensaje.id}"/>
                                        </h:link>
                                    </c:otherwise>
                                </c:choose>
                            </h:column>
                            <h:column id="actCol">
                                <f:facet id="actFct" name="header">Action</f:facet>
                                <h:commandButton action="#{mensajeAgent.deleteMensaje}" value="Delete">
                                    <f:setPropertyActionListener target="#{mensajeAgent.id}" value="#{_mensaje.id}"/>
                                </h:commandButton>
                            </h:column>
                        </h:dataTable>
                    </h:form>
                </fieldset>
                </div>
            </h:panelGroup>
            
            <h:panelGroup id="cancelSessionList">
                <div class="section">
                <fieldset>
                    <h:form id="cancelMensajeListForm">
                        <h:commandButton action="#{mensajeAgent.cancel}" value="Cancel" />
                    </h:form>
                </fieldset>
                </div>
            </h:panelGroup>
    
        </ui:define>
    
    </ui:composition>
    

     

    but still does not work. It always selects the <c:otherwise> option and I am thinking

    if maybe I am wrong about the logic of the code.

     

    In the database the refereed field is type of varchar(255).

     

    Regards,

    Jose

  • 3. Re: JSF comparision operators don't work
    Jose Alvarez de Lara Novice

    It is a Seam 3 project and I would like to know if JSTL is compatible with the framework.

    I have been googling and the only one question is about the namespace but I did not find to

    anyone saying that I can not use it.

     

    So I can not understand why it does not work.

     

    Regards,

    jose

     

    El mensaje fue editado por: Jose Alvarez de Lara