Hiding conditional logic using JSF tags

Hi
I'm trying to encapsulate some logic which, dependent on a true / false validation, outputs either one component or another containing a value.
For example...
when the validation is true, output <h:selectOneMenu... containing all available values with selected value highlighted.
when the validation is false, output <h:outputText... containing selected value.
I've tried custom tags but I'm using this to write out very basic tags and I'd prefer to use the JSF HTML tags.
The only option I can see is to write conditional logic in the JSPs to say:
if valid = true
<h:selectOneMenu...
else
<h:outputText...
endif
...but this means the developers must do this for every occurrence and the pages contain lots of conditional logic.
Is there any way to create a custom JSF tag which outputs JSF HTML tags as this seems to be what we want to do?
Thanks D

There is no tag for this, but every HTML component has a 'rendered' attribute which accepts a boolean expression. If it's outcome is true, then the component will be rendered, otherwise it will be hidden.
Here are some basic examples:
<h:someComponent rendered="#{myBean.booleanValue}" />
<h:someComponent rendered="#{myBean.intValue > 10}" />
<h:someComponent rendered="#{myBean.objectValue == null}" />
<h:someComponent rendered="#{myBean.stringValue != 'someValue'}" />
<h:someComponent rendered="#{!empty myBean.collectionValue}" />
<h:someComponent rendered="#{!myBean.booleanValue && myBean.intValue != 0}" />
<h:someComponent rendered="#{myBean.stringValue == 'oneValue' || myBean.stringValue == 'anotherValue'}" />

Similar Messages

  • Can i use JSF tags and HTML tages Together

    i am trying to use html and JSf tages together. i hope it should owrk. but for me html tags are not working.
    can any one help me

    thanks
    its working but i have one more clarification
    can we wuse jsf tags in javascript
    for examp
    this my javascript using html
    newQuotCell1[0].innerHTML='<input type=text class=TextField name="nameofEmployer'+count1+'">';
    if i want to write a jsf tage there . does it allow
    i want to bind the textfield with bean value . Is it possibel.
    please let me know.
    thansk in advance

  • How we can use jsf tags in included jsp enclosed in subview tags

    Hello everybody,
    I am developing web app by using jsf. I am including a jsp page "header.jsp" into another jsp page "main.jsp". The header.jsp page is enclosed in jsf subview tag on main.jsp page. The header.jsp contains some static html code and some jsf tags like "outputText". When i added tag library url in header.jsp then my app was not even not initiating and i was getting following exception
    ERROR [UIComponentTag] Faces context not found. getResponseWriter will fail. Check if the FacesServlet has been initialized at all in your web.xml.
    16:22:16,890 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
    java.lang.NullPointerException
    at javax.faces.webapp.UIComponentTag.setupResponseWriter(UIComponentTag.java:929)
    at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:310)
    ....Now i removed jsf tag library url from included jsp "header.jsp" so now my app is running but only static html data is being displayed but the value in the jsf tag "outputText" is not being printed in the browser
    kindly help me. i would be very thankful....

    Your question has nothing to do with Sun Java System Directory Server.
    Please use the right forum(s).
    Thanks

  • Is it possible use jsf tags in a desktop client?

    How can I use the tags for jsf for example <h:view .../> in a desktop client?

    You probably could if you try hard enough. For starters, use Facelets instead of JSP; that drops the need for a Java compiler and other things. Then you will need to supply the equivalent of the FacesServlet. Any underlying technology usually supplied by the container would need to be supplied by you. You will also need a first rate browser embedded in your application, with JavaScript support.

  • Using JSF and IFRAMEs

    I have a basic JSF app that takes some input, does a request and creates a table on output. What I need to do with it now is to have the query "page" and results "page" in two iframes on the same page. Before the query has been run the second iframe should just be blank (or with some default text). After the query that frame should be populated but the query frame needs to still be there. I've managed to do part of this. The "search" page and the "results" page are in separate iframes:
    <%@ page session="true" %>
    <html>
    <head>
      <title>Frames</title>
    </head>
    <body>
    <table>
      <tr>
        <td width="100%" colspan="2">
          <iframe title="Synonyms Search" src="search.jsf"
              width="800" height="200">
          Alternate search content...
          </iframe>
         </td>
      </tr>
      <tr>
      <td width="100%">
        <iframe src="results.jsp" title="Results"
          width="800" height="800">
          Results....
        </iframe>
      </td>
      </tr>
    </table>
    </body>
    </html>The reason this page is not using jsf tags is that the iframes will need to contain other pages that themselves are not jsf (mostly servlets) and I wasn't sure I could make that work. Currently the problem is that previously the search page had a QueryBean that the results page accessed to create it's table of results. Now in iframes the results.jsp frame just has a jsp processing exception and running the query does nothing. I'm new to JSF so I'm sure there's parts I'm missing, these do work if I pull them outside the frames and write navigation rules in the faces-context.xml file.
    Thanks,
    Sarah

    nigeldeakin wrote:
    The first thing to ask is whether you are sure that
         @Resource(name = "jms/QueueConnectionFactory",mappedName = "queueConnectionFactory")
         private ConnectionFactory connectionFactory;is valid. Does it work when you use it in other places?No it is not working still giving me NullPointerException for it. I'm using JBoss AS and having hard times deploying a jms queue on it i used an xml file to configure the queue and here is the file
    <?xml version="1.0" encoding="UTF-8"?>
    <server>
         <mbean code="org.jboss.jms.server.destination.QueueService"
              name="jboss.messaging.destination:service=Queue,name=StockHistoryQueue"
              xmbean-dd="xmdesc/Queue-xmbean.xml">
              <depends optional-attribute-name="ServerPeer">
                   jboss.messaging:service=ServerPeer
             </depends>
              <depends>jboss.messaging:service=PostOffice</depends>
         </mbean>
    </server>i think it's not working because i have this null exception for queue factory.

  • Programatic Value/MethodBindings with JSF tags

    I read thread http://forum.java.sun.com/thread.jsp?forum=427&thread=526026 "Using JSP scriplets in the JSF tags". The following was suggested but not recomended in order to use JSF Tag EL with a programatically set value.
    <%
    String myString="MyLabel";
    request.setAttribute("myString", myString);
    %>
    <h:view>
    <h:outputText id="myID" value="#{myString}" />
    </h:view>
    Is it possible to set up ValueBinding's and MethodBindings in a similar way or would it be better to dump the JSF tags and use JSF altogether programatically. Below is an example that seems like it should work but the result is the ValueBinding.toString() ends up being the value.
    thanks in advance;
    <%
    FacesContext context = FacesContext.getCurrentInstance();
    Application app = context.getApplication();
    ValueBinding vb= app.createValueBinding("#{MyBean.member}");
    request.setAttribute("vb", vb);
    %>
    <h:inputText id="myid" value="#{vb}"/>

    --right ValueBinding.getValue() takes a FacesContext, which you definately would not want to pass as and arg in El, even if you could I would think. 
    To answer your question, we are generating several software layers based on an MDA approach. We reverse engineer the database schema into XML then use that "Platform Independent Model" to generate a JDO model and set of persistence-capable Java classes, and now a Faces Bean model and Bean classes. We also have a set of constants files which have all the entity and property names to be used in the web layer.
    Since the database model is huge, and changes alot (government project), hard-coding EL expressions in a thousand places is a very bad idea given the code-generation/reverse-engineering approach.
    We want 100% compile-time checking for all persistent-access properties and the Faces programatic approach to Value/Method bindings gets us there, if it will somehow work.
    --any other ideas would be greatly appreciated.
    --cheers; Scott

  • Using JSP scriplets in the JSF tags

    Hi,
    I haven't done that much JSP development using various tag libraries prior to looking at JSF, hence this very basic question:
    I am declaring and manipulating Java variables in my JSP. Is there a way to access those in my JSF tags? It seems that something like:
    <%
    String myString="MyLabel";
    %>
    <h:view>
    <h:outputText id="myID" value="<%=myString%>" />
    </h:view>
    blows up in the JSF processor.
    I am porting some stuff to JSF and hence do not use backing beans in all cases.
    Any suggestions/ideas/pointers are greatly appreciated.
    Thanks in advance,
    Vadim.

    JSF action element attributes take JSF EL expressions, not Java expressions. A JSF EL expression has access to objects in one of request, session or application scope only, not to scripting variables. One way to get your example to work is by putting the String in one of these scopes within the scriptlet, e.g.:
    <%
      String myString="MyLabel";
      request.setAttribute("myString", myString);
    %>
    <h:view>
      <h:outputText id="myID" value="#{myString}" />
    </h:view>But, if you're porting a JSP-based application to JSF, I strongly recommend that you move all scriptlet code into beans; otherwise it's kind of pointless to migrate to JSF. The strength of JSF is its separation of UI layout and application logic.
    Even though JSP happens to be one way to wire up a JSF view with JSF components, JSF has very little to do with JSP. You need to understand the basic JSF component model, event-driven development, and use JavaBeans to really gain any benefits. Don't be fooled into believing that JSF is "just a new JSP tag library" by the support for JSP as the default presentation layer; it's far more than that, and I personally believe that using JSP as the presentation layer makes using JSF a lot harder than it should be. In fact, most of the issues posted in this forum are issues with the JSP layer, not with the core JSF components or the infrastructure classes.
    Hans Bergsten (EG member)

  • Issues in using JSF UI:Tree tag

    Hi,
    I am trying to work with Tree Structure using JSF UI tags. In Studio Creator i just created a JSP page and designed a Tree with two nodes under it. This is what i have in the body of my jsp.
    <ui:body binding="#{Page1.body1}" id="body1" style="-rave-layout: grid">
    <ui:form binding="#{Page1.form1}" id="form1">
    <ui:tree binding="#{Page1.tree1}" id="tree1" style="left: 48px; top: 48px; position: absolute" text="L3">
    <ui:treeNode binding="#{Page1.treeNode1}" expanded="true" id="treeNode1" style="width: 408px" text="Tree Node 1">
    <f:facet name="image">
    <ui:image binding="#{Page1.image1}" icon="TREE_DOCUMENT" id="image1"/>
    </f:facet>
    </ui:treeNode>
    <ui:treeNode binding="#{Page1.treeNode2}" expanded="true" id="treeNode2" text="Tree Node 2">
    <f:facet name="image">
    <ui:image binding="#{Page1.image2}" icon="TREE_DOCUMENT" id="image2"/>
    </f:facet>
    </ui:treeNode>
    </ui:tree>
    </ui:form>
    </ui:body>
    But when i am trying to launch the jsp page from browser i am getting the below exception.
    com.sun.rave.web.ui.appbase.ApplicationException
    Caused by: java.lang.NullPointerException at java.io.File.(File.java:194) at com.sun.rave.web.ui.renderer.template.xml.XMLLayoutDefinitionManager.getLayoutDefinition(XMLLayoutDefinitionManager.java:142) at com.sun.rave.web.ui.component.TemplateComponentBase.getLayoutDefinition(TemplateComponentBase.java:150) at com.sun.rave.web.ui.renderer.template.TemplateRenderer.encodeBegin(TemplateRenderer.java:73) at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:683)
    Any suggestion to solve this issue would be greatly helpful.

    Now with Unified EL - JSTL and JSF tags are supposed to work on one page.
    If you want to use Unified EL you need
    1) A container that is built on Servlet 2.5 / JSP 2.1 , and example of such a container is Tomcat 6.x
    2) Probably need to upgrade to JSTL 1.2 , and JSF 1.2
    3) If you're upgrading the container to Servlet 2.5 then web.xml should conform to Servlet 2.5 version.
    4) Use correct taglib URIs for JSTL 1.2 and JSF 1.2
    Read here: Summary of new features in JSP 2.1
    http://java.sun.com/developer/technicalArticles/J2EE/jsp_21/index.html
    JSP 2.1 Technology and JSF 1.2 Technology
    http://java.sun.com/developer/community/chat/JavaLive/2004/jl1207.html
    http://java.sun.com/products/jsp/index.jsp
    Message was edited by:
    appy77

  • How to use HTML tags inside JSF pages

    I am creating a Menu using dataTable and outputLink in a JSF page.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
    <h:column>
    <li>
    <h:outputLink id="crumbID" value="#{bread.menuLink}">
    <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
    </h:outputLink>
    <li>
    </h:column>
    </h:dataTable>
    </ol>
    </div>
    </div>
    I want to use <li> HTML tag as shown in code above before and after every <tr> tag formed, but when i run it and see view source, this is how it shows:
    NOTE: you can see it has thrown out of <table> tag itself.
    <div class="bodyarea">
    <div id="location">
    <ol>
    <li>
    </li>
    <table>
    <tbody>
    <tr>
    <td><a id="_id0:0:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=-1"><span id="_id0:0:crumpName" style="width: 165px;">Home</span></a></td>
    </tr>
    <tr>
    <td><a id="_id0:1:crumbID" href="/eApps/admin/loginPage.jsp?MenuItem=3~-1"><span id="_id0:1:crumpName" style="width: 165px;">HIM Admin</span></a></td>
    </tr>
    </tbody>
    </table>
    </ol>
    </div>
    </div>
    Can some one help me, how do i use HTML tags inside <h:dataTable>.
    Or is their any other way i should form my Menus, to fully utilize to HTML tags.
    Thanks
    Ravi

    Hello,
    You can embed the verbatim elements in your datatable, ie,
    <h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
      <h:column>
        <f:verbatim><li></f:verbatim>
        <h:outputLink id="crumbID" value="#{bread.menuLink}">
          <h:outputText id="crumpName" value="#{bread.menuLabel}" style="width: 165px;"/>
        </h:outputLink>
        <f:verbatim></li></f:verbatim>
      </h:column>
    </h:dataTable>

  • Advanced Search using conditional & logical operators+ sharepoint 2010

    Hi Team,
    We have an requirement something like this. we have to search values from Custom SharePoint List using Conditional & Logical Operators in SharePoint 2010. how can i achieve this ? if some one has worked on something like this, can you please share the
    details to my email id ([email protected]
    Thanks in Advance.
    Cheers, San

    Hi Santhosh,
    If you have only one list, then you can use CAML query to perform search in that list. You can write code to generate dynamic CAML based on selection in the filter.
    If have to perform the search function on multiple list then you can use Search object model and create dynamic query and execute it using Search OM.
    http://msdn.microsoft.com/en-us/library/office/dn423226(v=office.15).aspx
    Best Regards,
    Brij K

  • Use jstl tags in jsf page

    I have h:dataTable in each row of which i'd like to output row data as text, inputfield or link depending on row data type
                        <h:dataTable id="pnlHistory" value="#{UserOrdersBean.orderLineWrappers}" var="wrapper" rendered="#{UserOrdersBean.isBasicUser}"
                                     columnClasses="history_col1, history_col2, history_col3, history_col4, history_col5" width="100%" cellpadding="5" >
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink action="doRefresh" actionListener="#{UserOrdersBean.doSort}">
                                        <h:outputText value="#{msg.userorders_itemName}">
                                            <f:param value="orderLineWrappers"/>
                                            <f:param value="itemName"/>
                                        </h:outputText>
                                    </h:commandLink>
                                </f:facet>
                                <h:outputText value="#{wrapper.itemName}" styleClass="itemdescription"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:commandLink action="doRefresh" actionListener="#{UserOrdersBean.doSort}">
                                        <h:outputText value="#{msg.userorders_data}">
                                            <f:param value="orderLineWrappers"/>
                                            <f:param value="data"/>
                                        </h:outputText>
                                    </h:commandLink>
                                </f:facet>
                                <c_rt:choose>
                                    <c_rt:when test="#{wrapper.type==0}">
                                        <h:outputText value="#{wrapper.data}" styleClass="basic_thin"/>
                                    </c_rt:when>
                                    <c_rt:when test="#{wrapper.type==1}">
                                        <h:inputText value="#{wrapper.data}" styleClass="basic_thin" style="width:160px"/>
                                    </c_rt:when>
                                    <c_rt:when test="#{wrapper.type==2}">
                                        <h:outputLink value="#{wrapper.data}">
                                            <h:outputText value="#{msg.userorders_link}" styleClass="basic_thin"/>
                                        </h:outputLink>
                                    </c_rt:when>
                                </c_rt:choose>
                            </h:column>
                         </h:dataTable>trying to use jstl tags but unsuccessfull. Is it ever possible user jstl tags in jsf tags like listed above

    Replace the c:choose block by<h:outputText value="#{wrapper.data}" styleClass="basic_thin" rendered="#{wrapper.type == 0}" />
    <h:inputText value="#{wrapper.data}" styleClass="basic_thin" style="width:160px" rendered="#{wrapper.type == 1}" />
    <h:outputLink value="#{wrapper.data}" rendered="#{wrapper.type == 2}">
        <h:outputText value="#{msg.userorders_link}" styleClass="basic_thin"/>
    </h:outputLink>

  • Using TAG Attributes within JSF Tags

    I'm using some .tag files for templating purposes. I'm using two tag attributes via <@% attribute %> directive. How can i access this attribute to do something like follows.
    <%@ tag display-name="Area de Trabajo" language="java" %>
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>
    <%@ attribute name="title" required="true"%>
    <%@ attribute name="location" %>
    <t:div styleClass="zonaArea#{(not empty location) ? location : 'Global'}">
      <h:panelGrid columns="1">
        <h:outputText value="#{title}" />
      </h:panelGrid>
      <jsp:doBody />
    </t:div>

    Hola Alberto.
    Any luck? Did you worked that around?
    I'm just trying to do the same thing...
    Tried to do something like:
    <%@attribute name="enabled" type="java.lang.String" %>
    <h:outputText value="test: #{requestScope['enabled']}" style="font-weight: bold;" /> to no avail...
    Let me know, please!
    Hi,
    Manrico

  • How to dynamically include jsp files using jsf el in include tag ?

    Hi,
    I'm trying to get the jsp file name from my backing bean to use it in an include tag but I can't make it work
    When using this piece of code I can get the generated path
             <h:outputText value="/_partial/#{myBean.jspName}.jsp"/>whereas in this code the jsf el is not replaced by this value.
            <%@ include file="/_partial/#{myBean.jspName}.jsp" %> Have you any idea of how to solve this ? I'm currently developing for J2EE 1.4 platform.     
    Thanks for your help,
    Regards.

    If you're using JSF 1.2 and JSTL 1.2 at a JSP 2.1 environment, then you can just use <jsp:include> with unified EL.
    If you're using JSF 1.1, then you may find this article useful [http://balusc.blogspot.com/2007/01/dynamic-jsf-subviews.html]

  • Using expressions in jsf tags

    I have a problem with using expressions in jsf tags! I know this
    topic was discussed before but it doesn`t work.
    I want to use the following jsf-code:
    <h:panel_data id="tab" var="vari" modelReference="Bean.varis">
    <h:output_text id="Id" modelReference="vari.id"/>
    <h:command_hyperlink id="hyper" href="next.jsp" label="Detail">
    <f:parameter id="Param1" name="id" value="vari.id"/>
    </h:command_hyperlink>
    </h:panel_data>
    The value of the parameter should have the value of vari.id!! Why doesn`t it work?? I also tried to use value="${vari.id}" and value=<%= vari.id %>.
    I have also changed the jsf_core.tld from
         <rtexprvalue>false</rtexprvalue>
    to
         <rtexprvalue>true</rtexprvalue>
    Does anybody know what to do? Where should the .tld-files be localized when i deploy the webapplication??

    On May 19th, 2003 HydraD == "HD" wrote:
    HD> I have a problem with using expressions in jsf tags! I
    HD> know this
    HD> topic was discussed before but it doesn`t work.
    HD>
    HD> I want to use the following jsf-code:
    HD>
    HD> <h:panel_data id="tab" var="vari" modelReference="Bean.varis">
    HD> <h:output_text id="Id" modelReference="vari.id"/>
    HD> ...
    HD> <h:command_hyperlink id="hyper" href="next.jsp" label="Detail">
    HD> <f:parameter id="Param1" name="id" value="vari.id"/>
    HD> </h:command_hyperlink>
    HD> </h:panel_data>
    HD>
    HD> The value of the parameter should have the value of
    HD> vari.id!! Why doesn`t it work?? I also tried to use
    HD> value="${vari.id}" and value=<%= vari.id %>.
    HD>
    HD> I have also changed the jsf_core.tld from
    HD>      <rtexprvalue>false</rtexprvalue>
    HD> to
    HD>      <rtexprvalue>true</rtexprvalue>
    HD>
    HD> Does anybody know what to do? Where should the
    HD> .tld-files be localized when i deploy the
    HD> webapplication??
    If you want your parameter's value to be pulled from the model, you must
    use modelReference instead of value. Try that and see if it works.
    Ed

  • Building JSF tag using existing Tags

    Hi all
    I wonder if it's possible to create a new JSF tag using existing JSF Tags?
    For example, I have a JSF tag which renders a lable and a textinputfield, let's call it <f:field>
    Now I want to build a new JSF tag, which will re-use the existing tag <f:field>. IS it possible?
    Thanks in advance

    Did you have a chance to look at facelets solution. Facelets provide several approach how to create composition components.
    Sergey : https://ajax4jsf.dev.java.net

Maybe you are looking for