Using value binding expressions to set 'required' attribute

I am trying to use a value binding expression to determine whether the value of various input control's is required or not according to where they are used and not having much luck. I wonder if anyone can shed some light on this...
The following expression works: <h:inputText id="name" required="#{true}"/> whereas <c:set var="required" value="true" scope="request"/>
<h:inputText id="name" required="#{required}"/> does not, even though the expression evaluates to true! I have tried numerous variations (requestScope.required, required == true, required ? true : false, etc.) to no avail. Interestingly, #{1 == 1} or binding to a backing bean method works, but as soon as you add a request variable it breaks.
Am I doing something wrong, is this something that JSF doesn't allow, or just a bug in the RI? Note that I don't want to vary this flag between multiple submissions of the same form, I am just trying to reuse the same JSP include to generate form controls for required and optional data on different forms to avoid a whole lot of cutting any pasting.
Any pointers gratefully received.
-- Keith Wilson

I had something like this happen, and here's what I concluded the problem was. Perhaps your problem is similar.
In the first non-working example you show a request-scope variable being set in the JSP page, and then use that to set the "required" attribute. But consider what happens when you submit the form. There is no longer any request-scope variable set because we have a new request and we don't go through the JSP page! (Not before validation is checked, anyhow).
So basically I concluded that the variable had to be in (say) session scope for it to work as you would like.

Similar Messages

  • Using value binding expression for to-view-id

    hi;
    is it possible to use a value binding expression in the <to-view-id> element?
    if not, is there a logical reason for this?
    thanks

    Shrek-2:
    Are we there yet?No
    Are we there yet?No
    Are we there yet?Yes
    Really?
    NO
    Seriously, the default navigation handler does not allow to use EL for the to-view-id, but you can obtain the desire behaviour with the custom handler decorator.
    This is a code snippet:
         public void handleNavigation(FacesContext fc, String actionMethod, String actionName) {
              _base.handleNavigation(fc, actionMethod, actionName);
              String viewId = fc.getViewRoot().getViewId();
            if ((viewId.indexOf("#{") != -1) &&
                    (viewId.indexOf("#{") < viewId.indexOf('}'))) {
                 String bviewId = (String)fc.getApplication().createValueBinding(viewId).getValue(fc);
                 if (bviewId != null)
                      fc.getViewRoot().setViewId(bviewId);
                 else {
                      // you can throw the exception here
         }More about HandlerDecorator:
    http://www.jsftutorials.net/jsfNavigation/jsf-login-navigation-redirect.html
    http://www.jsftutorials.net/faces-config/navigationDecorator.html
    P.S. Note: This feature might broke the separation between the different levels of application from the architectural point of view. Hard-coding the ViewIds inside the java code is not a good idea at all.
    Sergey : jsfTutorials.net

  • Exception handling within a value-binding expression

    Hi all,
    Forgive me if this question seems odd, but I am a long-time Struts developer, new to JSF.
    In Struts, exception handling was easy because all requests were funnelled through some subclass of Action. Exception handling could effectively be consolidated into one spot by applying the template-method pattern.
    Of course, with JSF, this is not possible because method names in value-binding and action-binding expressions can be chosen arbitrarily. For this reason, I am exploring aspect-oriented (and other) techniques for consolidation JSF exception handling into one spot, but rather than focus too intently on that, it's clear that I first need the ability to forward to an error page when an exception is encountered in a value-binding or action-binding expression.
    For action-binding expressions, ExternalContext.dispatch("<view id>"); seems to work quite well, but I am unable to make the same work when in the context of a value-binding expression. This is probably attributed to the fact that at that point, I am in an entirely different phase of the JSF request processing lifecycle.
    What I'm looking to know is if anyone has a reliable means of forwarding to an error page within the context of a value-binding expression. Better yet, does anyone know a reliable way of forwarding to another view regardless of what phase you are in?
    If it makes a difference (and I think it does) the error page uses JSF as well, and uses the same layout (provided via custom tags courtesy of JSP 2.0 tag files), so some view components would have the same name as the page which encountered the error. This seems to get in the way of me simply defining the error page for a 500 in my web deployment descriptor.
    Thanks in advance to anyone with a working suggestion.
    -Kent

    Let me pose a purely hypothetical use case to demonstrate the problem:
    Imagine a page in an HR app, employeeDetails.jsp, that displays an always-up-to-date combo box which lists employee names and IDs. onChange triggers a form submit with the intention of simply posting back to this page, with various text boxes, etc. below updated to show all information for the selected employee.
    Obviously, with the requirement that the combo box always be up to date, it's clear that the getter invoked by the value-binding expression must access the database (not directly of course, but via a facade, application, then data-access layer). Any unexpected and unchecked exception in this chain would propagate back up to the getter method on the backing bean. I need to, at that point, log the exception (trivial) and forward to a user-friendly error page.
    I suppose I could put some contraint on myself that data access is only performed within ActionEvent handlers, but I'm not sure that's consistent with the JSF model in general, in fact it almost seems Struts-like in that I'd have to invoke some action before loading this form to build the up-to-date list for the combo box, shove it in request scope, where it's then available to the page indicated by the navigation rules. Submission of the form on the page in question would also need to result in rebuilding the up-to-date list. Now we're looking at firther propagation of code. I want to avoid this, so I am looking for a better way.

  • Faces config exception - Can't get value from value binding expression:

    the menuItem_Department shown property takes value from userRight's session bean object userDetail.
    class UserRights{
        public boolean mDept = false;
        public boolean loggedIn = false;
        public boolean admin = false;
       //accessors
    }now, the shown property picks correct value for #{userDetail.admin} but gives erros on this. any idea how to get around this exception:
    Managedbean menuItem_Department could not be created Can't get value from value binding expression: '#{userDetail.mDept}'.
    javax.faces.FacesException: Can't get value from value binding expression: '#{userDetail.mDept}'     at com.sun.faces.config.ManagedBeanFactory.evaluateValueBindingGet(ManagedBeanFactory.java:903)
         at com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean(ManagedBeanFactory.java:547)
         at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:233)
         at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:256)
    .. stack tracepointers appreciated.
    reagrds
    Rabs

    well, i figured out the problem so thought to share with all aswell.
    all i changed was the name of the variable from mDept to dept.
    java beans has its own set of rules and naming conventions which i have not read much about but this problem had to do sumthing with that!
    just changing the name simply works fine!

  • Localized String with params - Value Binding Expression...

    Hi All:
    I see many e.g.s where a command button / or a label's value can be a localized resource string using the generic value binding expression:
    "#{bundleVarName.keyName}"
    what if the resource string has parameters? for e.g.
    button.caption = Click Me for {0}
    Can we assign a value binding expression with params for button captions etc.
    Please help - I am a newbie in JSF,,,
    regards
    -Somesh

    JSF developers have forgotten about this :)
    Use other tools for displaying such messages (f. e. JSTL) where you need to have parametrized messaged.
    But mostly, non-parameterized JSF will be enough.

  • Value binding not working with rendered attribute

    In my jsf page i'm encountering problem with value binding it is not working for a h:inputText with rendered condition even when the rendered condition evaluates to true & the component is rendered.While trying to retrieve the value of the components with conditional rendering on submit i'm unable to retreive the value while on removing rendered condition the value binding is working perfectly
    <h:selectOneMenu id="DropDown" value="#pc_GeneralRequestInfo.objInfoDTO.State}" rendered="#pc_GeneralRequestInfo.objAddressRequestDetailsDTO.selectedAddressType == 'HOME'}">                    
    <f:selectItems value="#{pc_GeneralRequestInfo.statesList}" />
    </h:selectOneMenu>

    There is a { missing from the value attribute in the code you posted.                                                                                                                                                                                           

  • How to use value from one data set in other data set SQL select.

    Hello all, i have one data set, and i need to get value from that data set into other data set. Something like '?' but without input. I will try to explain it with screenshots:

    If both tables come from the same data source, join the two tables in one data set rather than two as shown. If they are from different data sources, use a 'join data set'

  • Partial trigger set showrequired attribute to true, but on page not seeing the required 'star'?

    Hi All,
    I have a selectonechoice dropdown list and a input field, i want when the second item of dropdown list selected then the showrequired attribute of the input field was set to false, if the first item selected then the showrequired set to true. I also want to see the 'star' sign which indicates the showrequired attribute visually can be seen show and disappeared.
    I am using a autosubmit enalbed selecteonechoice and a partialtrigger (set the dropdown's id), but on page I didn't see any visual change : the 'star' sign is now showing or disappearing at all. Should it work? Or it's working but on page just not calling related CSS to show/hide the star sign? BTW I am using an el express for the showrequired attribute:  showRequired="#{bindings.ReferenceValue1.inputValue eq 0? true: false}"
    I also tried set the showrequired attribute in java method that listen to the dropdown list's onchange event, but still visually I am not seeing any change.
    I did:
          comConEditBankName.setRequired(false);
          comConEditBankName.setShowRequired(false);
    Could anyone point out my mistake here or give some guide?
    Below are the jsf codes:
                                                    <af:selectOneChoice value="#{bindings.ReferenceValue1.inputValue}"
                                                                        label="Invoice Template"
                                                                        required="#{bindings.ReferenceValue1.hints.mandatory}"
                                                                        shortDesc="#{bindings.ReferenceValue1.hints.tooltip}"
                                                                        id="soc2"
                                                                        binding="#{home.invoiceTemplate}"
                                                                        visible="false"
                                                                        autoSubmit="true"
                                                                        valueChangeListener="#{home.invoiceTemplateOnChange}">
                                                        <f:selectItems value="#{bindings.ReferenceValue1.items}"
                                                                       id="si2"/>
                                                    </af:selectOneChoice>
    <af:inputText label="Bank Name" id="it12"  showRequired="#{bindings.ReferenceValue1.inputValue eq 0? true: false}"
                                                  required="#{bindings.ReferenceValue1.inputValue eq '0'? true: false}"
                                                  binding="#{home.comConEditBankName}"
                                                  autoSubmit="true"
                                                  maximumLength="50"
                                                  partialTriggers="soc2"
                                                  value="#{bindings.ReferenceValue1.inputValue}"/>
    Thanks!!!

    Did you check the expression bindings.ReferenceValue1.inputValue eq 0 is true or not.
    One more thing try showRequired="#{bindings.ReferenceValue1.inputValue eq 0}"

  • SPEL to set required value

    Hi,
    I've browsed thru a lot of the SPEL posts here but couldn't quite get an answer.
    I'm trying to do something simple - set SPEL on a required field. The available options are "yes", "no" and "SPEL"
    I extended my VO and added a new boolean attribute - lets call it xxIsequired, and personalized the field required property to {oa.xxVO.xxIsequired}, but there is no change (doesn't work). I checked that the substitution is in fact working, and I know the new attribute xxIsequired returns true or false correctly.
    Then I tried changing the attribute xxIsequired to string, and return yes or no. With this I can't even get the personalization page to save (Error:"Please provide a valid value for 'required'.").
    So if only boolean attribute can be used, will it really work with required attribute which needs a "yes" or "no"?
    I am on OA Framework 12.1.3.
    Thanks,
    Kalp

    Thank you for your responses. I can't get it to work. Don't know what's wrong??
    This is my code (cut down for simplicity):
    VO Query select:
    CASE WHEN country <> 'US' THEN 1
    ELSE 0
    END xxisTaxReq
    VO Attribute:
    <ViewAttribute
    Name="xxIsTaxReq"
    IsPersistent="false"
    Precision="1"
    Type="java.lang.Boolean"
    ColumnType="NUMBER"
    AliasName="IS_TAX_REQ"
    Expression="IS_TAX_REQ"
    SQLType="BIT" >
    <DesignTime>
    <Attr Name="_DisplaySize" Value="14" />
    </DesignTime>
    </ViewAttribute>
    SPEL:
    Required attribute: ${oa.xxVO.xxIsTaxReq}
    I tried to create a new item thru personalization on the page and the value true/false comes through correctly on the screen.
    So this really baffles me, I dont know what I'm doing wrong? The true/false value is available but the personalization doesnt apply it to required field.

  • Error when using a condition for required attribute

    Hi
    I have a requirement to validate the mandatory fields only when the submit button is pressed....if some other button is pressed or some how the form is submitted the validations should not be performed....
    I have used required="#{MyBB.somecondition}" for all the mandatory fields...the method that is being called for doing the condition check is given below:
    public boolean isSomeCondition() {
        // assumes submitButton is a component binding 
        FacesContext fc = FacesContext.getCurrentInstance();
        Map reqParams = fc.getExternalContext().getRequestParameterMap();
        return reqParams.containsKey(submitButton.getClientId());
      }It is same that is given at the following location
    http://wiki.apache.org/myfaces/How_The_Immediate_Attribute_Works ---Soln 3
    But the problem is if I am submitting the form using Javascript from another page(page is a popup that is opened inside the current window), this condition doesnt work and it gives me an error saying "Check some field for its value"
    Please help me sort out this problem
    Thanks

    I think the problem is not clear....my mistake
    I try to be more elaborate on this....
    I open up a popup page from my main window....Here I perform a search(lets say there is a requirement for finding the Country and pincode for a particular city that the user enters)
    Now when I select the particular row in the datatable and click the submit button...... I want the selected values to be filled inside the parent window.....
    I want to bring to your notice that the button that is clicked is in the popup page...not in the parent window.....
    So you see that when that button in popup is clicked i am submiting the form of the parent window and during that time I dont want the validation to occur..... To submit the form of the parent window I use the Javascript like this : window.opener.document.forms[0].submit();Also one more thing that I want to mention is that the method that is used for specifying the condition for required attribute for mandatory fields in the parent window works fine for any button that i click inside my parent window......
    What I mean by this is lets say I have a button to add a dynamic row into my parent page then also I have to submit the form but during that time validation should not occur and it works fine.
    So now I think its clear that the Javascript is being invoked from another page which is submitting the parent window.....
    Then you're doing something wrong. Invoking the wrong button maybe? So please enlighten me where i am wrong and how possibly would I know which button I am invoking??

  • For the Attribute Movement type(BWA) we use Value " 201" and not "101" why?

    Hello Experts,
    We are in SRM 7.0 classic scenario,
    For the Attribute Movement type(BWA) we use Value " 201" and not "101" and provide the Source syst(backend R/3)
    Can you all plz help me understand what is the difference if use value "101" for the  Attribute Movement type(BWA)
    Also,can you all plz help me understand if we shd use value "101" or "201" for the  Attribute Movement type(BWA) and under what scenario.
    Any pointers will be highly appreciated.
    Thanks & Regards,
    RKS

    Hi,
    Movment type " 201 maintained for the Classic scenario only.
    It is necessary to maintain the attribute if the default material group for a given user (or) sit is set to a backend logical system. The EBP system knows that if the user is set for backend procurement ,that there might be a possibility for a reservation to be generated therefore it checks to see that a value for this attribute is  maintained. The BWA value should be defined  for the  as 201 preceeded by the logical system and a backslash.
    101 should not be used. This isfor the Good receipt.
    In the extended classic scenario when you do the confirmations in SRM the movement type 101 will be created in the
    backend system (R/3 or ECC6.0)
    Regards
    Ganesh Kumar .G

  • Help Needed in Input Value Help of Custom Set attribute

    Hi All,
    We have maintained value table for custom set type attribute. We generated UI configuration for this set type and brought it into the web UI. But, we did not get the value help on the UI.
    We are trying to get the value help by implementing the BADI crm_prdgenset_valuehelp. This BADI returns object of type cl_bsp_wd_valuehelp_f4descr.
    PFB the code that is showing up the Value help icon but it is not showing any values.
      DATA: lv_valuehelp_descriptor type ref to cl_bsp_wd_valuehelp_f4descr.
    *    lv_fname_prefix = 'STRUCT'.
       ls_map-context_attr = component.  "ZCSDR_PRD_CLS
       ls_map-f4_attr = 'KEY'.
       INSERT ls_map INTO TABLE lt_outmap.
       INSERT ls_map INTO TABLE lt_inmap.
       CONCATENATE 'ZCSDR_CLS' 'ZZ0010' INTO lv_help_id SEPARATED BY '-'.
       CREATE OBJECT lv_valuehelp_descriptor
         TYPE
           cl_bsp_wd_valuehelp_f4descr
         EXPORTING
           iv_help_id                  = lv_help_id
           iv_help_id_kind             = if_bsp_wd_valuehelp_f4descr=>help_id_kind_comp
           iv_input_mapping            = lt_inmap
           iv_output_mapping           = lt_outmap
           iv_trigger_submit           = ABAP_TRUE.
       rv_valuehelp_descriptor = lv_valuehelp_descriptor.
    Any pointers on this is really helpful.
    Thanks,
    Udaya

    Hi Chand,
    Sorry for the late response. As far as i recollect, i guess we have enhanced the setter getter methods and written logic in the get-v method.
    Let me know if the issue is resolved.
    regards,uday

  • Using Airport Express to set up an ad hoc network for presentations

    I have to give a presentation where I will both need my MacBook Pro and iPad. I may or may not have a wireless network available (will depend on location). Is there a way that I can use an Airport Express to set up an ad hoc network and use an Apple TV for AirPlay from my iPad and laptop?

    Easy to do. Just set up the AirPort Express to "Create a wireless network".
    When you see the "error" message(s) that there is not an Ethernet cable plugged into the WAN port and/or no Internet connection, click "ignore" and you will have a green light on the Express.
    Wireless devices will connect to the network by selecting it and entering the password.

  • Easy and efficient way to set dynamic attributes

    My integration scenario is quite complex involving many different receivers and an integration process. For some receivers I have to set dynamic attributes.
    I know that I can set them by using a UDF, however in my case I mostly use XSLT so this is not applicable.
    Is there any other way to do this relatively easy so that I can avoid Java Mappings? Problem ist that I would need to use several Java Mappings to set the attributes where no transformation to the payload itself is taking place which seems to be too much for me. Especially when I consider that these Java Mappings are hard to maintain as they have to be imported again and again if any changes occur.
    So my question is:
    1. Do I really have to go for several Java Mappings just to set some dynamic attributes ?
    2. If so, should I use different Java Packages or is it advisable to leave all Java Mappings in one package?

    Hi Florian,
    yes, you can!
    set dyn atts in XSLT:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="java:java.util.Map" xmlns:dyn="java:com.sap.aii.mapping.api.DynamicConfiguration" xmlns:key="java:com.sap.aii.mapping.api.DynamicConfigurationKey">
    <xsl:if test="REFERENCEQUALIFIER='MSU'">
         <xsl:variable name="dynamic-conf" select="map:get($inputparam, 'DynamicConfiguration')"></xsl:variable>
         <!--  mit dem folgenden Key-Key-Paar muss dann via UDF die Adresse aus den dyn. Attr. gelesen werden -->
              <xsl:variable name="dynamic-key" select="key:create('http://sap.com/xi/XI/System/Mail', 'MAILADRESS_SU')"></xsl:variable>
              <xsl:variable name="dummy" select="dyn:put($dynamic-conf, $dynamic-key, $MAILADRESS)"></xsl:variable>
              <xsl:comment>Mailadresse SU ermittelt: <xsl:value-of select="$MAILADRESS"></xsl:value-of>
              </xsl:comment>
    Hoffe es hilft.
    Grüße
    Mario
    Edited by: Mario Müller on Oct 15, 2009 1:47 PM

  • How to get the currency of the logged in user using an el expression

    I want to get the currency of the logged in user using an el expression. I can get the same using ApplSessionUtil.getCurrency(). But can i get the same using an el exprssion?. I want to use this el expression for setting the default value of a VO attriubte
    Thanks in advance

    Hi
    If you are getting the currency value from ApplSessionUtil.getCurrency() set the result of the value to one of your VO on Bean and use it in your el expression .
    Thanks
    Raghav

Maybe you are looking for