Updating the model via AJAX

Victor,
I find Tor's and Greg M's bpcatalog documents describing AJAX and JSF useful. However they do not address 'updates'.
Updating the model via an AJAX request that is handled by the JSF framework as suggested by bccatalog examples is a challenge.
I am not sure if it is best to use the "Update Model" phase of the life cycle or just cheat and put he update code in the tags render response phase. Also, it appears that the "update model Phase" may not be included in the lifecycle as the ajax request is not really a JSF "postback".
Does anyone know what tradeoff result in doing an update in the Render Response Phase?
Cheers,
Godfrey

I've tried updating the model using AJAX and a RenderPhaseListener, but never succeeded. I have a simple CRUD form with two selectOneMenu components, some text boxes, and a submit button. When a selection is made in the first select list, an AJAX call is made that populates the second select list. Once that happens, the second select list contains a different list of <f:selectItems> in the DOM than it does in the underlying component model. If the array of SelectItems that are used to populate the second select list is in a managed bean, when the form is submitted, the second select list fails validation (Validation Failed: Not a Valid Value) because the selected item exists in the DOM, but not in the SelectItem array in the managed bean. To work around this, I placed the SelectItem array in the session, instead of in the managed bean. When the AJAX call is made, the backend Java code updates the SelectItem array in the session. This prevents the model and the DOM from getting out of synch. I hate putting anything in the session, because sessions tend to die, but this is the best workaround I could come up with. I'm open for any better solutions. Oh, by the way, if I use AJAX enabled select lists on a JSF page in a JSF 1.0 web app, the Invoke Application phase is mysteriously skipped when the form is submitted, which prevents the form contents from being saved. If I use JSF 1.1_01, the form saves like a charm. You gotta love being on the bleeding edge.

Similar Messages

  • How do i skip process validations and still update the model?

    how do i skip process validations and still update the model? This has got to be a bug or a really huge design flaw. And no I don't want to using 'binding' to bind to every component on my form just so I can set its value. I just want to use value binding.
    Perhaps there should be a FacesContext.getCurrentInstance().updateModel() method?

    how about if I want clear the form or load a new model:
    <h:commandButton action="#{customer.clear_action}" immediate="true" value="clear" />
    <h:commandButton action="#{customer.load_action}" immediate="true" value="load" />
    public void clear_action() {
    Customer c = new Customer();
    this.setBean("customerModel",c);
    FacesContext context = FacesContext.getCurrentInstance();
    context.renderResponse();
    public void load_action() {
    Customer c = new Customer(1000);
    this.setBean("customerModel",c);
    FacesContext context = FacesContext.getCurrentInstance();
    context.renderResponse();

  • Declarative component doesn't update the model

    Hi,
    I have a simple declarative component which has an attribute called 'val' and a input text field which uses the 'val' as its value like "#{attrs.val}"
    I use this declarative component within a page and i set the value 'val' attribute to something like "#{bindings.val.inputValue}" where val is an attribute from a bean data control.
    What i observe is that if i change the value in the UI the corresponding attribute in the data control is not affected.
    However this happens in the case of a normal input text field.
    Is it that declarative component are meant for only 'reading' in and not 'writing' out?
    Please let me know if there is a way to update the model with the value changes within a declarative component.
    Cheers,
    Raj

    Hi Frank,
    I want to avoid the managed bean here.
    For a simple text field the data in the data control gets updated without using a managed bean.
    I would expect the same for the declarative component too.
    Please let me know if i am missing something here.
    Cheers,
    Raj

  • Update "rendered" attribute via ajax

    Is there a workaround to update the "rendered" attribute of a commandLink via AJAX? I'm getting an error 'malformedXML: During update: j_idt12:prevCmd not found'.
    code snippet:
    <h:commandLink action="#{controller.previous}"
                                       value="Previous"
                                       rendered="#{controller.hasPreviousPage}"
                                       id="prevCmd">
         <f:ajax render="table prevCmd nextCmd" immediate="true"/>
    </h:commandLink>
    <h:commandLink action="#{controller.next}"
                                       value="Next"
                                       rendered="#{controller.hasNextPage}"
                                       id="nextCmd">
         <f:ajax render="table prevCmd nextCmd" immediate="true"/>
    </h:commandLink>

    Try adding the form name to the components names:
    <f:ajax render="form1:table form1:prevCmd form1:nextCmd" immediate="true"/>

  • How to  not update the model value whe, multiple back-end validation failed

    Hello !
    I have a save button who perform in backend code multiple validations on some fields. The validations can be ok, if not, I show specific error messages in my page. It's working fine.
    The problem is that all the InputText I need to valid are value binded with value=#{backing.somepropery} to the model and when the code of the ActionEvent is called the model was already update.
    So the validation is useless, you see error message ok but I can't prevent action to be done.
    As the validation occurs only when I press a specific button I can't use custom validator.
    does someone have an idea to manage that ?
    Thank You.
    Dan.

    Thnaks for your repsonse but, it"s not working because the values are bound so the modifications are already done.
    I'm sure that there is a way to do that.

  • How to update the model for a checkbox

    Hello,
    I have a series of check boxes. The first checkbox when checked, programmatically checks the others.
    The bidrectional binding of the UI and the model is done in the controller.
    However, when I dumped the model to the console I noticed that the actual visualized states of the checkboxes are not reflected in the console.
    I have been searching for a refresh() method or some mechanism to to the update but failed so far.
    Any help will be appreciated.

    Say i have 5 rows then
    for(int i=1;i<=5;i++){
    String Newpath = updatepath(eval("{{obj.libraryname.web_input_text_fieldname}}"),i)
    web.text_area(Newpath).setText("Text to be set")
    Below function is used to update my path
    public String updatepath(String path,int i) throws exception {
    String FPath = "";
    if(i<2) {
    FPath = path.substring(0, path.indexOf("'", path.lastIndexOf("@id=")+5))+path.substring(path.indexOf("'", path.lastIndexOf("@id=")+5));
    } else {
    FPath = path.substring(0, path.indexOf("'", path.lastIndexOf("@id=")+5))+(i-1)+path.substring(path.indexOf("'", path.lastIndexOf("@id=")+5));
    return Fpath
    anyother way to update path and set the fields in mutiple block is appreciable
    thanks
    Suresh

  • Struts2 - ScopedModelDriven - Unable to update the model in session

    Hi,
    I have a problem implementing ScopedModelDriven.
    I Have Model / User Java Bean object in action class.
    I am trying to implement concept of same model object being used for 3 JSP pages with PREVIOUS and NEXT button navigation.Data to be updated in Model object for every page navigation and to be saved in session.
    It is found the latest data is found from value stack when jsp page is navigated to next page, but not updated in Model object either in request or session scope I am sure I have configured necessary interceptors properly.
    This could be easily done in struts1 by setting the Actionform in session scope.Any advice or thought?.
    Struts.xml:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    <package name="myPackage" namespace="/" extends="struts-default">
    <interceptors>
    <interceptor name="myMultipleForm"
    class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
    <param name="scope">session</param>
    <param name="name">user</param>
    <param name="className">com.ut.p.s2.beans.User</param>
    </interceptor>
    </interceptors>
    <global-results>
    <result name="error">/jsp/Error.jsp</result>
    <result name="invalid.token">/jsp/Error.jsp</result>
    <result name="login">/jsp/login.jsp</result>
    </global-results>
    <global-exception-mappings>
    <exception-mapping
    result="error"
    exception="java.lang.Throwable"/>
    </global-exception-mappings>
    <action name="ShowScopedModel" class="com.ut.p.s2.actions.ServletTestAction" >
    <interceptor-ref name="servletConfig"/
    <interceptor-ref name="app_common"/>
    <result name="model_test_page">/jsp/smodelTest.jsp</result>
    <result>/jsp/smodelTest.jsp</result>
    </action>
    <action name="scopedModelAction_*" class="com.ut.p.s2.actions.ScopedModelDrivenAction" method="{1}">
    <interceptor-ref name="basicStack"/>
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="prepare"/>
    <interceptor-ref name="debugging"/>
    <interceptor-ref name="scopedModelDriven">
    <param name="scope">session</param>
    <param name="name">user</param>
    <param name="className">com.ut.p.s2.beans.User</param>
    </interceptor-ref>
    <interceptor-ref name="params"/>
    <interceptor-ref name="conversionError"/>
    <interceptor-ref name="workflow"/>
    <result name="input">/jsp/smodelTest.jsp</result>
    <result>/jsp/smodelResult.jsp</result>
    <result name="model_test_page">/jsp/smodelTest.jsp</result>
    <result name="model_test_page2">/jsp/smodelTest2.jsp</result>
    <result name="model_test_page3">/jsp/smodelTest3.jsp</result>
    <result name="model_result_page">/jsp/smodelResult.jsp</result>
    </action>
    </package>
    </struts>
    Action:
    package com.ut.p.s2.actions;
    import java.util.ArrayList;
    import com.ut.p.s2.beans.Books;
    import com.ut.p.s2.beans.Dept;
    import com.ut.p.s2.beans.User;
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.Preparable;
    import com.opensymphony.xwork2.interceptor.ScopedModelDriven;
    public class ScopedModelDrivenAction extends ActionSupport implements ScopedModelDriven,Preparable {
    private User user =null;
    private static final long serialVersionUID = 1271130427666936592L;
    private String scope = null;
    public void prepare() throws Exception {
    user = new User();
    ArrayList arlList=new ArrayList();
    Books b1 = new Books("Java",100);
    Books b2 = new Books("VB",200);
    arlList.add(b1);
    arlList.add(b2);
    Dept dept = new Dept();
    dept.setDeptNo("100");
    dept.setDeptName("Mechanical");
    user.setDept(dept);
    user.setArlList(arlList);
    public String getScopeKey() {
    return scope;
    public void setModel(Object arg0) {
    this.user = (User) arg0;
    public void setScopeKey(String arg0) {
    scope = arg0;
    public Object getModel() {
    return user;
    public User getUser() {
    return user;
    public void setUser(User user) {
    this.user = user;
    public String execute() {
    System.out.println("execute()........."+user);
    return INPUT;
    public String input() throws Exception {
    System.out.println("input()........."+user);
    return SUCCESS;
    public String save() {
    System.out.println("save()........."+user);
    return "model_result_page";
    public String page1() {
    System.out.println("page1()........."+user);
    System.out.println("page1()....scope....."+scope);
    return "model_test_page";
    public String page2() {
    System.out.println("page2()........."+user);
    System.out.println("page2()....scope....."+scope);
    return "model_test_page2";
    public String page3() {
    System.out.println("page3()........."+user);
    System.out.println("page3()....scope....."+scope);
    return "model_test_page3";
    }//end class
    JSP Page:
    <%@ page errorPage="/jsp/Error.jsp" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@taglib uri="/struts-tags" prefix="s" %>
    <html>
    <head>
    <s:head theme="simple"/>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>User Details</title>
    </head>
    <body>
    <h2>User Details</h2>
    <hr>
    User Name :<s:property value="name" /><br>
    Age :<s:property value="age" /><br>
    Hobbies :<s:property value="hobby" /><br>
    Country :<s:property value="country" /><br>
    <TABLE border="1">
    <s:iterator value="arlList" status="row">
    <TR>
    <TD><s:textfield name="arlList[%{#row.index}].name" value="%{name}" /></TD>
    <TD> <s:text name="arlList[%{#row.index}].price" /></TD>
    </TR>
    </s:iterator>
    </TABLE>
    <h2>
    User Department :<s:property value="dept" /><br>
    <s:property value="dept.id" />
    <s:property value="dept.name" />
    <jsp:include page="Footer.jsp"/>
    </body>
    </html>

    I am very surprised that you aren't aware of the CODE tags after being registered here for 5 years. Now your whole post with raw and unformatted code is hard to read. Make use of CODE tags to post code. You can use the CODE button in the toolbar of the message editor to get them.
    With regard to your actual problem: as this is a Struts specific issue and you're here at a JSP forum, all I can do is to suggest you to use a forum/mailinglist devoted to Struts if you don't get sufficient support here after a while.

  • Does changes in ViewRowImpl update the model?

    Hi, I have two related application modules A and B.
    Using A, I get a ViewRowImpl from UI using iterator binding and getCurrentRow() method and update some data.
    I do not post changes in database.
    In B, I tried to get an instance of the same ViewRowImpl using the findByKey() method. The data contained in ViewRowImpl does not contain the changes happened earlier in A.
    I also tried to relate A and B and get an instance of A from B using a getter from AppModuleImpl but again the ViewRowImpl got using findByKey() does not contain changes?
    Why does changes in a ViewRowImpl doesn't update the Data Model?
    I also tried findInCacheByKey() method but nothing changed
    Any comment will be helpful.
    Thanks.
    Edited by: IliasS on 2 Ιαν 2012 2:35 πμ

    Even if making B nested in A i didn't managed to get a ViewRowImpl with updated fields.
    I tried to use the B's service methods directly from UI through pageDef or
    indirectly calling a wrapper method in A's appModuleImpl that uses B's method.
    In A's service method I get the updated VOImpl,
    in B's service method I get an outdated VOImpl.
    Really I can't imagine an EJB container to handle object relational model in such a problematic way....

  • How to update the iPad iOS version? I have an iPad (first generation) iOS 5.1.1. I can't update the software via WiFi nether via iTunes

    I have an iPad (probably first generation - Model A1337 ). This tablet has iOS version 5.1.1.
    I would like to update for the latest version as possible.
    There is no option by iPad wifi.
    I also tried by iTunes and in option Checking for UpDate, only let me know the current version, but doesn't open the possiblity to update for a newer.
    How can I update the software version ?
    tks
    Reinaldo

    Hi,
    The first generation iPad is limited to iOS 5.1.1. This is due to the original iPad not having enough power or memory to get to iOS 6, 7 or any further in the future.
    All other iPads and iPad Minis can get to the current version - iOS 7.0.4 and at least until the end versions of iOS 7 or iOS 8.
    Hope this helps, and Welcome to the Apple Support Communities!

  • My ipod touch is telling me that the skype and twitter apps need updating. When I try to run them they fail. I have tried deleting the apps via itunes but it doesn't work and I have tried updating the apps via itunes and it says they are updated.

    My ipod touch is telling me that the Skype and Twitter apps need updating.  When I try to update them they both fail. I have tried numerous times.  I have tried connecting the ipod to itunes and removing the apps, to reload them but that does not work either.  If I try and update the apps through itunes the system tells me they are updated.  Can anyone assist please?

    - Try a reset. It cures amny ills
    Reset iPod touch:  Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Have you tried deleting them from the iPod and then redownloading them dorectly to the iPod?
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • Purchased an HP Photosmart 5520 all in one printer last year and a Macbook Pro in Jan. They worked together up to June. In Sept. when I tried to print wirelessly, it would not print. The laptop had been updated. Tried to update the printer via HP,couldn't

    I have an HP Photosmart 5520 all in one printer and a MacBook Pro. Bought the MacBook Pro in Jan 2013 and the printer in Dec 2012. I was able to print to the wireless printer up until June 2013. In September, when I tried to use them together, I could not print. During the period between June and Sept., my laptop software was updated. I have tried to update the HP software on my laptop, but could not. What can I do to use this printer with my MacBook Pro? Please help!

    The MacBook Pro is running at least 10.7.

  • Validation Error after updating a SelectOneMenu via Ajax (DWR)

    I have a <t:selectOneMenu> that is bound to a backing bean together with a <f:selectItems> that is bound to a SelectItems[] attribute in the same backing bean. See below:
    <t:selectOneMenu forceId="true"
    id="department"
    value="#{DeptBean.departmentId}">
    <f:selectItems value="#{DeptBean.departmentList}" />
    </t:selectOneMenu>
    When the user changes another field on my page, I use DWR to retrieve a new list of departments and update the <t:selectOneMenu> accordingly. That works just fine.
    The problem is that if I select a value from the updated department list and then submit the page I get a "Validation Error".
    I suspect that the JSF Component Tree still has the old list of values and does some validation which obviously fails.
    Has anyone dealt with this before? Any ideas would be appreciated!

    <t:selectOneMenu forceId="true"
    id="department"
    value="#{DeptBean.departmentId}">
    <f:selectItems value="#{DeptBean.departmentList}"
    />
    </t:selectOneMenu>What is the type of departmentId ? If it is not a String, then try making it a String and see if the issue is resolved. I am not sure if this will help you. But its worth a try.

  • HT1600 was told to update the tv via computer.....

    trying to update apple t.v from version to a 5.1 through the computer update. tried through it st up on tv, but no luck....anyone know how?

    Which Apple TV do you have? If its the 1st gen (ie not a little black box) then there won't be an update. If you have one of the recent models then how are you trying to update and what exactly is the issue

  • Update the database structure from entity Framework Model

    Hello !
    I'm using VB.net , EF6 with SQL server 2008R2 database.
    This is the situation :
    I have created the application. Using wizard I have created the Entity model from an existing database.
    A client start using this application using this database on his computer.
    After some month , I made some modifications on the database and I have updated the model on my application .
    Now I have a new .exe file that has the new model from the new database.
    I put the new .exe file on the client computer.
    Now on his computer : The .exe file has the new database model , but the sql server database has the old structure.
    I want to know : Is possible to update the database structure from the entity model on application ?
    I want to add a command on application that can make ( if is possible ) this update , so the database become up to date according to entity model ?
    Thank you !

    Hello,
    From your description, it seems that you want to apply a migration for a database first approach, unfortunately, as far as I know, EF Migrations is a product targeted at Code First and doesn't support Database First operations. A workaround I know is to
    use update-scripts. If your database structure would be changed frequently, it is recommended to use the Code First approach which would have a better workaround for migrations, for details, you could refer to this
    video,
     and with the
    Entity Framework Power Tools, it is easy to create a code first based project form an existing database.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Is it possible to set webapp item releaseDate when submitting via ajax?

    I've been trying to set the releaseDate of a webapp item when entering the item via ajax.  So far I have been unable to do so....is it possible?
    For the field name and date format I referenced the API docs.
    I've tried both releaseDate and ReleaseDate
    Here's the console of the variable before submission
    theItemName: Test
    strDate: 12/14/2014
    Here's the relevant submit code
              var testOpts = {
                    url: profileAction,
                    data: {
                        ItemName: theItemName,
                        releaseDate: strDate
                    type: "POST",
                    success: function(data, txt, jqXHR) {
                        console.log("submit success");
                    error: function(jqXHR, txt, error) {
                        console.log("submit error");
                        return false;
                $.ajax(testOpts)
    Anyone done this successfully?
    Thanks
    Dave

    Hi Dave,
    The date format specified in the parameters section was incorrect, I have fixed that and will push the update shortly. The correct date format is YYYY-MM-DD - sorry for the inconsistency.
    I have just re-tested the sample code here - Reference guide - Create web app item (that one had the correct format and it was working properly.
    Thanks and have a nice weekend,
    Mihai

Maybe you are looking for

  • Why is my Itunes "Purchased" list empty?

    My Ipod is missing "Ten Million Slaves" by Otis Taylor, I would download it again, but not able to. I checked my computer in the music and media files and its not there either...and not on the Ipod. I went to the Itunes store and there are no purchas

  • Lightbox Gallery widget 1.0

    Does anyone know if there is a variable to make the gallery move from the last image and wrap around to the first image instead of ending the gallery? or modifying the java script? Roz http://www.bigbroncocc.com/products.html

  • How to connect epson workforce 610 wireless printer

    I had it printing one time, and somehow info got lost in settings Print and Scan. I thought I put back right info but now it doesn't print at all. Any info would help.

  • Payment proposal workflow

    Hi friend, <Moderator note: new question related to [this thread|custom pushbutton created in the transaction F110;. Please always ask new questions in a new thread. See the [Rules of Engagement|https://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngag

  • Connect database in J2EE

    I create some container-managed entity beans and I use Microsoft SQL Server v.7.0. ( I don't know how to use cloudscape!!!) Could you show me how to configure the JDBC driver (for MS SQL Server 7.0)? For example, I use a database named aaaa . Please