Pass arguments to JSF tag attributes like id oder value

Hi!
I started with JSF some weeks ago and have some questions that i could not find in FAQ or tutorials.
My page structure uses some <jsp:includes>. Each included page uses JSF.
The structure is (example - users):
Users.jsp
|
|(incl)
|
Mainpage.jsp (=Framework)
|
|(incl)
|
Browser.jsp (=Table)
In "Users" all specific data is set. In "Browser" there is a <h:form> tag and a <h:dataTable> tag.
The result should be a simple table with users inside.
So I want to pass arguments to those sub-pages.
1) -> form-ids as parameter:
<h:form id="#{sessionScope.formName}">
... does not work, because ids have to start with a character or "_".
formName is set as followed:
session.setAttribute("formName", "form_users");
2) ->beans as parameter:
<h:dataTable id="browser_table_#{sessionScope.id}" styleClass="browser_table"
var="user" value="#{sessionScope.user_list}">
... does not work. "id" is requested to be a static value and "value" can't find the bean by this string.
user_list is set as followed:
session.setAttribute("user_list", "UserListBean.users");
(UserListBean.users is an ArrayList)
Is there an error in my thinking? Or is there a way to pass arguments as i want?
Thanks!

sorry ... mistake in topic: "oder" = "or" of course :)

Similar Messages

  • JSP ${} expressions in JSF tag attributes

    Does anyone know why the expert group decided not to allow ${} style expressions within JSF tag attributes? I understand that a different syntax is needed to implement the 'late binding' #{} expressions used to link input controls to form beans, but not why the JSF tags actually prevent the use of immediately evaluated ${} expressions for accessing variables in the page scope in JSP 2.0.
    I know there has been a lot of discussion about this and other threads mention a security loophole that would be opened up by allowing expressions like #{blah.${someProperty}}, but I'm not sure why this sort of thing would cause a problem. Is there any way to enable this behaviour, such as editing the JSF tag library descriptors to allow runtime expressions (horrible though that sounds)? Or perhaps another JSF implementation that supports both immediately evaluated and late-binding expressions? It seems a rather unnecessary restriction that is going to cause much confusion and mistyping for all...
    Thanks in advance,
    Keith.

    Thanks Adam, I see the problem now. It's a fairly obscure loophole but serious nonetheless. Of course, this problem could also be avoided by not using request parameters within JSF tags as it doesn't affect the majority of legitimate uses for expressions.
    I have to disagree with you about mixing ${} and #{} expressions though. The majority of developers will be used to writing ${} expressions in JSTL and JSP text and so will expect them to do work the same in JSF tags. Judging by the number of posts in this forum about being unable to use page scope variables in JSF tags this issue is already confusing a lot of people.
    As a rule of thumb, "use ${} for expressions that are output to the page and #{} for binding controls to backing beans and invoking methods" (which perform clearly distinct functions) is a lot simpler and easier to learn IMHO than the current one, which is "use ${} for expressions that are output to the page except within a JSF tag, where you use #{} for the same thing and also to update form values and invoke action methods"! (OK, I'm exaggerating a little for effect, but you get the point... :-)
    I agree that mixing both types of expression in the same attribute might be a little confusing, but this is an unlikely edge case that should probably be prevented in value binding or action attributes anyway. It's more of an issue for label values where mistyping one for the other is already very common and, although not especially difficult to debug, is just another pitfall awaiting the unwary JSP developer. I'm not sure that JSP expressions would be much more difficult to debug anyway as the value and method bindings will simply not work, which is pretty obvious as soon as you try and test the thing.
    Is this something that the EG would be prepared to reconsider for the next release of JSF, or perhaps getting the security loophole addressed in the next JSP spec? In the meantime, is there any reason that developers shouldn't enable runtime expressions in the TLD file provided that they're willing to live with the consequences?
    (Sorry to harp on about it, but I've already had several complaints about this after recommending JavaServer Faces for a major development project at ingenta.com.)
    Many thanks,
    Keith.

  • How do I use the ? operator in JSF tag attributes?

    I want to do something like this:
    <h:inputText styleClass="${myBean.valid ? 'styleA' : styleB'}" ...>
    What do I have to do to use this Expression language?
    With the #{...} expression the ? operator doesnt seem to be available.
    When I use the ${...} expression I am getting this error:
    javax.servlet.ServletException: ServletException in '/WEB-INF/body/Test.jsp': /WEB-INF/body/Test.jsp(12,5) According to TLD or attribute directive in tag file, attribute styleClass does not accept any expressions
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:121)
    Can anybody please help?
    Thanks!

    Personally, i'd do:
    <h:inputText styleClass="styleA" rendered="#{myBean.valid}"/>
    <h:inputText styleClass="styleB" rendered="#{!myBean.valid}"/>

  • Pass argument to custom tag

    Is there any way to pass a page-scope variable to a tag hanlder class? I have a variable fullname which I need to pass to the tag, so it can determine how to print it...I'm trying to avoid massive scriptlets in the middle of a complex page. The way it works is: A user logs in; the JSP page determines the user's fullname with a javabean, and then i want to pass that fullname to the tag, so it can either say "logged in as ..." or "not logged in" if the fullname="nobody".
    Or is there a much better architecture than what i'm proposing here?
    Thanks in advance,
    Laz

    Did you try putting the value of the name to the session? In your bean, you could create a method that would return a String that contains the name. And then you call that method in the JSP. for example:
    session.setAttribute("name", beanInstance.getName() );
    And then in the JSP where you need to display the name, you only have to get it by:
    out.println("You are logged in as " + session.getAttribute("name") );

  • Passing arguments to overidden messages

    Hi. Is it possible to override a default message and then pass dynamic data to be displayed in the custom message? I know this is possible with Struts tags, but I have not been able to do this with a JSF tag. For example, if I have the following JSF tag and message bundle entries, how would I pass, say "5", as an inputText tag attribute or parameter so that it will be displayed in the invalidFormField1 message where the "{0}" marker is?:
    // JSF tag:
    <h:inputText id="formField1" value="#{maintForm.formField1}" validatorMessage="#{msgs.invalidFormField1}">
    <f:validateLength minimum="5"/>
    </h:inputText>
    // Message bundle entries:
    javax.faces.validator.LengthValidator.MINIMUM=Value is less than allowable minimum of "{0}"
    invalidFormField1=Form Field 1 value is less than allowable minimum of "{0}"It seems strange that this is not straightforward to do (unless I am missing something). Is a custom validator required to accomplish this?
    Thanks.

    Same problem ...
    I tested with JSP.parameters["arg_myArg"] ... no result

  • 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

  • JSF tag/tag attribute reference?

    Is there a place where I can references for the various JSF tags and their attributes, fx. the validators and which attributes they support and so on?

    The right place to check is the html_basic.tld and jsf_core.tld. These are part of the jsf-ri.jar.

  • Pass two parameters using extraParams attribute in protlet:createWebFlowURL tag

    Ho do I pass two parameters using extraParams attribute in portlet:createWebFlowURL?

    <portlet:createWebFlowURL event="RTFM" extraParams="read=manual&do=you">
    "Linda" <[email protected]> wrote:
    >
    Ho do I pass two parameters using extraParams attribute in portlet:createWebFlowURL?

  • Passing argument through EL

    I was wondering if its possible to pass an argument through an EL expression. Specifically I was wondering if I could use #{Foo.bar("something")} as an attribute for a tag? I know that it won't work as written (I've tried it) but you can get the idea of what I'm trying for.
    What I don't want is to have to have a special method for each variation of how I might determine the value. I know its possible to have:
    #{Foo.barSomething}
    #{Foo.barSomethingElse}
    But in these cases, the method is no argument and the method name distinguishes them.
    TIA,
    sean

    Looking back at the component I created, I realized that what I was doing wasn't really standard EL anyway, so why not make things really elegant? I therefore combined property-value and method-value expressions, and then used normal Java method parentheses to differentiate the two. Revising the two examples from yesterday (and keeping the same backing bean method) yields:
    <gw:assignment var="test1" expression="#{'success'}"/>
    <html:outputText value="#{test1}"/>and
    <gw:assignment var="test2" expression="#{presence.concat(#{'suc'}, #{'cess'})}"/>
    <html:outputText value="#{test2}"/>Oh, but I'm not finished! How about this?
    <gw:assignment var="test3" expression="#{presence.concat(#{'suc'}, #{presence.concat(#{'ce'}, #{'ss'})})}"/>
    <html:outputText value="#{test3}"/>Infinitely nestable parameters, using both property values and method values. You like? I call it "extended EL."
    Now to stir up some controversy: Having an extra assignment step is still too much needless overhead. I'm going to go through and reimplement many of the common JSF tags (such as h:outputText) and retrofit the "value" attribute so that it handles extended EL.
    Normally I'm the first to jump on the standards/consistency bandwagon, and I'm a loud and long champion of doing things according to common specifications even if you lose just a little in functionality or efficiency. In this case, however, the JSF EL is amazingly deficient (I'm not the only person ranting about parameter passing), to the point that it's hard for me to implement normal functionality, as I mention earlier on this thread. Besides, using an extended EL in the attribute of my own component extension is really equivalent to using an existing JSF component combined with my custom assignment component, the latter of which uses an extended EL anyway.
    What makes this whole story so sad is that I'm at a loss to explain why parameter passing was not included in JSF EL from the beginning. The API already allows parameters in method-binding---the EL syntax simply doesn't provide access to this.
    Worse still (and contributing to the problem) is that the JSF expression language API is ill-designed. JSF EL only recognizes method-signature binding and does not include method-value binding. The former binds to the method itself, similar to a function pointer in C++ or a reference to a method in Delphi. The latter binds to the result of a method invocation, just as what JSF calls "value binding" does with the result of invoking a getter or setter method. (Note that "value binding" really uses "method-value binding" in the background once it finds the appropriate getter or setter method.)
    Let's take the <h:commandLink actionListener="#{backingBean.listener}"> attribute value, for instance. Here true method-binding is at work---JSF does not invoke the method indicated in the value of this attribute when the component is rendered---the method is the value of the attribute. (Note that the JSF EL is short-sighted here. It doesn't allow indication of parameters because it knows the method signature---but what about in the future when we want to differentiate among methods with the same names but different signatures?) Simarly the <h:commandLink action="#{backingBean.doAction}"> keeps a reference to the actual bean method and invokes it later when the command button is clicked by the user, although at this point JSF EL starts to conflate the distinction and actually uses the result of the invocation as if it were literally included as the original attribute value.
    My extended EL implementation, on the other hand, recognizes both property-value binding and method-value binding, the latter of which is absent from JSF EL. For each of my custom components from now on, the "value" attribute will accept a literal value, a property-value binding, or a method-value binding. The method-value bindings will accept parameters, each of which can be a property-value-binding or a method-value binding. (Maybe I'll throw literal parameter values into the mix later on, but that's really the least of my worries.)
    What should JSF do? First, it should add parentheses back into the EL for methods, and deprecate method binding and method-value syntax that do not have parentheses. Next, it should refactor ValueBinding to be an interface or abstract parent class of two new classes: PropertyValueBinding (equivalent to the existing ValueBinding) and MethodValueBinding (equivalent to the existing MethodBinding if it implemented a ValueBinding interface or derived from ValueBinding).
    All the existing createValueBinding() methods will then create the appropriate ValueBinding instance based upon whether a propert-value binding or method-value binding is being represented. Suddenly, all JSF components (yes, even the custom components that you've already created) will not only be aware of property-value and method-value invocation, they will all support nested method parameters.
    Yes, it's that simple. I know because I'm the new happy owner of my first of many components that support extended EL---something that should have been part of standard EL from the beginning.
    Now back to my regularly-scheduled application building...
    Garret

  • Passing argument to function

    hi to all
    i have one querry
    i want to pass an argument to function through jsf tags
    can you help me out
    how i will do it
    <h:selectOneMenu id="listSP" value="#{ProfileInit.selectedItem}" immediate="true">
    <f:selectItems value="#{ProfileInit.populateSubStationsName}" />
    </h:selectOneMenu>
    public populateSubStationsName(String a,String b){
    i want to pass two argument to "populateSubStationsName()" method
    is it possible
    i heard about the tag name "attribute" is it possible to pass through this tag

    Yes, it is. See [1]. But I doubt if you actually need this. Reading the articles at [2] and [3] may give new insights.
    [1] http://balusc.blogspot.com/2006/06/communication-in-jsf.html
    [2] http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html
    [3] http://balusc.blogspot.com/2007/10/populate-child-menus.html

  • Problem with custom tag attribute types

    Hi,
    I try to figure out how to pass an attribute to a custom tag that is of a type other than "String"?
    In my case, I should pass an attribute with a type of "java.util.ResourceBundle".
    My tag looks like this:
    <tt:cs sel="ab" ce="<%= java.util.ResourceBundle.getBundle("de", Application.getApp().getLocale())%>" />
    I always get the message that the attribute ce is empty.
    Isn't it possible to have attirbutes that are of an other type than string? How could I solve this problem?
    Thanks a lot!
    Regards Patrick

    In JSP 1.2, in the Tag Library Descriptor, you can specify a tagt attribute as
    <attribute>
       <name>attr1</name>
       <required>true|false|yes|no</required>
       <rtexprvalue>true|false|yes|no</rtexprvalue>
       <type>fully-qualified_type</type>
    </attribute> Notice the XML element <type>fully-qualified_type</type>
    Not sure if you can do this in JSP 1.1

  • Replace JSF tag by an own tag

    Hi,
    I'm trying to replace a <h:inputText> by my own tag. The used HtmlInputText component should not be replaced.
    The reason is, that i want to pass permissions to the tag and map them to readonly and rendered attributes. My Problem is, that my own tag doesn't reolv bean values. If i use the <h:inputText> the bean values show up correctly. If i use my own tag, the input text shows "#{myBean.value}".
    What could be the problem?
    Thx in advance
    Henrik
    Here is my tag:
    import javax.faces.component.UIComponent;
    import javax.faces.component.html.HtmlInputText;
    import javax.faces.context.FacesContext;
    import javax.faces.webapp.UIComponentTag;
    import com.arvato.jsf.security.JSFSecurity;
    import com.arvato.jsf.security.Permissions;
    import com.sun.faces.taglib.html_basic.InputTextTag;
    public class ArvatoTextFieldTag extends InputTextTag {
        private String role;
        private String onkeypress;
        private String id;
        private String value;
        public String getRole() {
            return role;
        public void setRole(String permissions) {
            this.role = permissions;
        protected void setProperties(UIComponent component) {
            super.setProperties(component);
            if(id != null) {
                component.getAttributes().put("id", id);
            if(onkeypress != null) {
                component.getAttributes().put("onkeypress", onkeypress);
            if(value != null) {
                component.getAttributes().put("value", value);
            if(role != null) {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                Permissions p = JSFSecurity.getInstance().getPermissionsForRole(role, facesContext);
                if(!p.isWritable()) {
                    component.getAttributes().put("readonly", true);
                if(!p.isReadable()) {
                    component.getAttributes().put("rendered", false);
            } else {
                component.getAttributes().put("readonly", false);
                component.getAttributes().put("rendered", true);
        @Override
        public String getComponentType() {
            return "javax.faces.HtmlInputText";
        @Override
        public String getRendererType() {
            return null; // no standalone renderer
        @Override
        public void release() {
            super.release();
            role = null;
        public String getValue() {
            return value;
        public void setValue(String value) {
            this.value = value;
        public String getOnkeypress() {
            return onkeypress;
        public void setOnkeypress(String onkeypress) {
            this.onkeypress = onkeypress;
        public String getId() {
            return id;
        public void setId(String id) {
            this.id = id;
    }and my tld definition:
    <taglib>
       <tlib-version>0.03</tlib-version>
       <jsp-version>1.2</jsp-version>
       <short-name>arvato-jsf</short-name>
       <uri>http://arvato.com/jsf/component/tags</uri>
       <description>Arvato JSF tags</description>
       <tag>
          <name>textfield</name>
          <tag-class>com.arvato.jsf.tag.ArvatoTextFieldTag</tag-class>
          <attribute>
             <name>id</name>
          </attribute>
          <attribute>
             <name>role</name>
          </attribute>
          <attribute>
             <name>value</name>
          </attribute>
          <attribute>
             <name>onkeypress</name>
          </attribute>
       </tag>
    </taglib>

    In the setProperties method, you've got to resolve the valuebinding (#{blah.whatever}) to get the actual value. But you only want to do that if the attribute is set to a valuebinding.
    Here's an example:
          * @see javax.faces.webapp.UIComponentTag#setProperties(UIComponent)
         protected void setProperties(UIComponent component) {
              super.setProperties(component);
              //Set the field reference property
              if (fieldRef != null) {
                   if (UIComponentTag.isValueReference(fieldRef)) {
                        ValueBinding vb = getFacesContext().getApplication().
                             createValueBinding(fieldRef);
                        component.setValueBinding("fieldRef", vb);
                   } else {
                        component.getAttributes().put("fieldRef", fieldRef);
         }This example shows how to determine if the "fieldRef" attribute is a value binding, and extracts the value accordingly. But there's one more step. In your component class, or anywhere you access the attributes of your custom tag, use the following code:
         public String getFieldRef() {
              if (fieldRef != null)
                   return fieldRef;
              ValueBinding vb = getValueBinding("fieldRef");
              if (vb != null)
                   return (String)vb.getValue(getFacesContext());
              else
                   return null;
         }The above snippet is what you would put in your custom component getter method.
    JSF is open source. Something I found very helpful while learning how to create custom components was looking at how the JSF developers created theirs. You should go ahead and download the JSF source code.
    CowKing

  • How to run generated JSF tags ?

    I am beginner in JSF. I would like execute JSF tags generated dynamically by XSLT, but in the JSP page,
    these tags are not interpreted. Does anyone has the solution ? Thanks a lot.
    Example below is only a simple test,
    ResearchBean.java :
    public String researchAction() {
        // Actually, htmlResponse is the output string after the XSLT transformation, and it contains JSF tags
        htmlResponse = "<h:outputText value=\"Text\"/>";
        return "response";
    }response.xhtml :
    <f:view xmlns:f="http://java.sun.com/jsf/core
    xmlns:h="http://java.sun.com/jsf/html
    <html>
    #{researchBean.htmlResponse}
    </html>
    </f:view>In the page received by the browser, <h:outputText value="Text"/> isn't replaced by the html code.
    Edited by: wondergarance on Jul 2, 2009 1:24 PM

    The JSF tags are apparently generated after the FacesServlet has done its work. You in fact need to pass the generated output through the FacesServlet again. If you're using a servlet/filter to run XSLT, you need to run it before the FacesServlet kicks in. You can control the servlet/filter invocation order in the web.xml.

  • 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)

  • JSF tag inside another JSF tag

    Hi,
    Note: It's a bit of a long post but I will try to cut to the point without leaving behind any pertinent details.
    I've created some simple custom JSF tags in the past. The tags usually consisted of one or two attributes that would be beans. The tags would then print out the data for those beans or process them and then output the results.
    What I am trying to do now is a bit more complicated for me. I have a JSP page with a scriplet on it. It iterates over a bean containing a list of items. The loop adds those items to an HTML select menu one at a time. The outline of the code looks similar to this,
    <% extract data List from the bean and store it in variable called dataList %>
    <select>
    <%
      for (int i=0; i<dataList.size(); i++;){
        ListItem item = dataList.get(i);
        String name = item.getName();
        String value = item.getValue();
    %>
    <option value="<%=value%>">
      <%=name%>
    </option>
    <%}%>
    </select>
    <h:commandButton id="gobtn" action="go_to_page" actionListener="#{action.fetch}" value="Go"/>What I want to do is take all the above code and put it into a custom JSF tag. This tag would contain all the scriplet code, output the HTML code and also the commandButton code at the end.
    All of that is pretty easy except for the commandButton part. I am not sure how to output a commandButton from a custom JSF tag. How do I pass it the action.fetch part for the actionListener attribute? Can I create a commandButton object in my custom JSF tag and pass it this information?
    I've followed a tutorial at this site in the past but it doesn't go into too much detail
    http://www.exadel.com/tutorial/jsf/jsftutorial-customcomponents.html
    Any help is appreciated,
    Nick

    I guess I missed some information. The dataList in the bean is stored in a HashMap. So some work has to be done with the bean before hand to determine what list to pull out and then "massage" it a bit for viewer consumption. This is not easily accomplished with the standard JSF html tags, hence my going with a custom tag approach.
    Processing this bean and getting a list from the Hashmap in the bean before displaying it is easy, so is outputting the HTML. The hard part is rendering the commandButton with all the attributes I listed previously.
    Is there a way in general to have other JSF tags nested inside a custom JSF tag?

Maybe you are looking for