Re: Dynamically adding form elements client-side
H... an interesting question. Well, the JSF component tree is forever in your forming hands, so what you could do is write e.g. a custom form which looks at the request values and does something with the component tree if a new, unknown parameter shows up. (It's easy to add components, just create a new one and add it to its parent). I am not sure though if submitting would work in all cases (especially if you clicked on a link). You might as well try it out, we have never had a use-case like this. All we did was hiding and showing fields depending on some javascript wise changed status. regards, Martin On 6/19/05, Richard Wallace <[EMAIL PROTECTED]> wrote: > Thanks, I understand how to do it on the javascript side. I'm just not > sure how to translate it into something the JavaServer Faces will be > able to understand. Optimally, of course, the values of the new > elements would be bound to the backing bean in the same way as any other > values. The difficulty is, of course, changing the state on either the > client or the server side so it is restored in the restore view phase. > If someone can tell me how to do that, I will be forever grateful. > > Rich > > David G. Friedman wrote: > > >Richard, > > > >I am still learning about MyFaces so I can only give you the JavaScript/DOM > >portion of the solution. I can't yet give you information on how to name > >your fields to work with a map/list/set backed Managed bean. I'm hoping > >this will get you far enough along so your MyFaces skills can fill in the > >gaps past my own light DOM/JavaScript knowledge. > > > >A good reference link (for me) was: > >http://www.mozilla.org/docs/dom/technote/tn-dom-table/#quick > > > >My test file used an input button on my form with an onClick like so: > > > >javascript:addFieldPlusLineBr(this);return false; > > > >To invoke a JavaScript example method of my own making to add a text field > >and line break to the form: > > > > > >function addFieldPlusLineBr(input) { > > var form = input.form; > > alert("hello"); > > var inputNode = document.createElement("input"); > > form.appendChild(document.createElement("br")); > > inputNode.setAttribute("name","fred"); > > inputNode.setAttribute("value","fredValue"); > > form.appendChild(inputNode); > >} > > > > > >Your trick will be figuring out how to place it exactly WHERE you want it in > >your form. The link I mentioned should include various methods you could > >invoke to add it after the element, or elements, of your choice. > > > >Good luck! > > > >Regards, > >David > > > >-Original Message- > >From: Richard Wallace [mailto:[EMAIL PROTECTED] > >Sent: Saturday, June 18, 2005 11:10 PM > >To: MyFaces Discussion > >Subject: Re: Dynamically adding form elements client-side > > > > > >David G. Friedman wrote: > > > > > > > >>Richard, > >> > >>Are you talking about hiding/showing the fields (such as using a CSS style) > >>or completely adding to the page without a resubmit? > >> > >> > >> > >> > >> > >Completely adding a new element to the form. > > > > > > > >>Regards, > >>David > >> > >>-Original Message- > >>From: Richard Wallace [mailto:[EMAIL PROTECTED] > >>Sent: Saturday, June 18, 2005 11:04 PM > >>To: MyFaces Discussion > >>Subject: Dynamically adding form elements client-side > >> > >> > >>Hello again, > >> > >>I'm trying to figure out how, if it's possible to add form elements, > >>like text fields, when a user clicks an add button without having to > >>have the page resubmit. I'm not even sure it's 100% possible unless the > >>STATE_SAVING_METHOD is client. And then the javascript would have to > >>manipulate that hidden field. Or do some kind of AJAX operation to > >>modify the state when it's being stored server side. At this point, I > >>think if anything prevents us from adopting JSF at work it would be > >>dynamically adding form elements. Any suggestions? > >> > >>Thanks, > >>Rich > >> > >> > >> > >> > >> > > > > > > > >
Re: Dynamically adding form elements client-side
Thanks, I understand how to do it on the javascript side. I'm just not sure how to translate it into something the JavaServer Faces will be able to understand. Optimally, of course, the values of the new elements would be bound to the backing bean in the same way as any other values. The difficulty is, of course, changing the state on either the client or the server side so it is restored in the restore view phase. If someone can tell me how to do that, I will be forever grateful. Rich David G. Friedman wrote: Richard, I am still learning about MyFaces so I can only give you the JavaScript/DOM portion of the solution. I can't yet give you information on how to name your fields to work with a map/list/set backed Managed bean. I'm hoping this will get you far enough along so your MyFaces skills can fill in the gaps past my own light DOM/JavaScript knowledge. A good reference link (for me) was: http://www.mozilla.org/docs/dom/technote/tn-dom-table/#quick My test file used an input button on my form with an onClick like so: javascript:addFieldPlusLineBr(this);return false; To invoke a JavaScript example method of my own making to add a text field and line break to the form: function addFieldPlusLineBr(input) { var form = input.form; alert("hello"); var inputNode = document.createElement("input"); form.appendChild(document.createElement("br")); inputNode.setAttribute("name","fred"); inputNode.setAttribute("value","fredValue"); form.appendChild(inputNode); } Your trick will be figuring out how to place it exactly WHERE you want it in your form. The link I mentioned should include various methods you could invoke to add it after the element, or elements, of your choice. Good luck! Regards, David -Original Message- From: Richard Wallace [mailto:[EMAIL PROTECTED] Sent: Saturday, June 18, 2005 11:10 PM To: MyFaces Discussion Subject: Re: Dynamically adding form elements client-side David G. Friedman wrote: Richard, Are you talking about hiding/showing the fields (such as using a CSS style) or completely adding to the page without a resubmit? Completely adding a new element to the form. Regards, David -Original Message- From: Richard Wallace [mailto:[EMAIL PROTECTED] Sent: Saturday, June 18, 2005 11:04 PM To: MyFaces Discussion Subject: Dynamically adding form elements client-side Hello again, I'm trying to figure out how, if it's possible to add form elements, like text fields, when a user clicks an add button without having to have the page resubmit. I'm not even sure it's 100% possible unless the STATE_SAVING_METHOD is client. And then the javascript would have to manipulate that hidden field. Or do some kind of AJAX operation to modify the state when it's being stored server side. At this point, I think if anything prevents us from adopting JSF at work it would be dynamically adding form elements. Any suggestions? Thanks, Rich
RE: Dynamically adding form elements client-side
Richard, I am still learning about MyFaces so I can only give you the JavaScript/DOM portion of the solution. I can't yet give you information on how to name your fields to work with a map/list/set backed Managed bean. I'm hoping this will get you far enough along so your MyFaces skills can fill in the gaps past my own light DOM/JavaScript knowledge. A good reference link (for me) was: http://www.mozilla.org/docs/dom/technote/tn-dom-table/#quick My test file used an input button on my form with an onClick like so: javascript:addFieldPlusLineBr(this);return false; To invoke a JavaScript example method of my own making to add a text field and line break to the form: function addFieldPlusLineBr(input) { var form = input.form; alert("hello"); var inputNode = document.createElement("input"); form.appendChild(document.createElement("br")); inputNode.setAttribute("name","fred"); inputNode.setAttribute("value","fredValue"); form.appendChild(inputNode); } Your trick will be figuring out how to place it exactly WHERE you want it in your form. The link I mentioned should include various methods you could invoke to add it after the element, or elements, of your choice. Good luck! Regards, David -Original Message- From: Richard Wallace [mailto:[EMAIL PROTECTED] Sent: Saturday, June 18, 2005 11:10 PM To: MyFaces Discussion Subject: Re: Dynamically adding form elements client-side David G. Friedman wrote: >Richard, > >Are you talking about hiding/showing the fields (such as using a CSS style) >or completely adding to the page without a resubmit? > > > Completely adding a new element to the form. >Regards, >David > >-Original Message- >From: Richard Wallace [mailto:[EMAIL PROTECTED] >Sent: Saturday, June 18, 2005 11:04 PM >To: MyFaces Discussion >Subject: Dynamically adding form elements client-side > > >Hello again, > >I'm trying to figure out how, if it's possible to add form elements, >like text fields, when a user clicks an add button without having to >have the page resubmit. I'm not even sure it's 100% possible unless the >STATE_SAVING_METHOD is client. And then the javascript would have to >manipulate that hidden field. Or do some kind of AJAX operation to >modify the state when it's being stored server side. At this point, I >think if anything prevents us from adopting JSF at work it would be >dynamically adding form elements. Any suggestions? > >Thanks, >Rich > > >
Re: Dynamically adding form elements client-side
David G. Friedman wrote: Richard, Are you talking about hiding/showing the fields (such as using a CSS style) or completely adding to the page without a resubmit? Completely adding a new element to the form. Regards, David -Original Message- From: Richard Wallace [mailto:[EMAIL PROTECTED] Sent: Saturday, June 18, 2005 11:04 PM To: MyFaces Discussion Subject: Dynamically adding form elements client-side Hello again, I'm trying to figure out how, if it's possible to add form elements, like text fields, when a user clicks an add button without having to have the page resubmit. I'm not even sure it's 100% possible unless the STATE_SAVING_METHOD is client. And then the javascript would have to manipulate that hidden field. Or do some kind of AJAX operation to modify the state when it's being stored server side. At this point, I think if anything prevents us from adopting JSF at work it would be dynamically adding form elements. Any suggestions? Thanks, Rich
RE: Dynamically adding form elements client-side
Richard, Are you talking about hiding/showing the fields (such as using a CSS style) or completely adding to the page without a resubmit? Regards, David -Original Message- From: Richard Wallace [mailto:[EMAIL PROTECTED] Sent: Saturday, June 18, 2005 11:04 PM To: MyFaces Discussion Subject: Dynamically adding form elements client-side Hello again, I'm trying to figure out how, if it's possible to add form elements, like text fields, when a user clicks an add button without having to have the page resubmit. I'm not even sure it's 100% possible unless the STATE_SAVING_METHOD is client. And then the javascript would have to manipulate that hidden field. Or do some kind of AJAX operation to modify the state when it's being stored server side. At this point, I think if anything prevents us from adopting JSF at work it would be dynamically adding form elements. Any suggestions? Thanks, Rich
Dynamically adding form elements client-side
Hello again, I'm trying to figure out how, if it's possible to add form elements, like text fields, when a user clicks an add button without having to have the page resubmit. I'm not even sure it's 100% possible unless the STATE_SAVING_METHOD is client. And then the javascript would have to manipulate that hidden field. Or do some kind of AJAX operation to modify the state when it's being stored server side. At this point, I think if anything prevents us from adopting JSF at work it would be dynamically adding form elements. Any suggestions? Thanks, Rich
DataScroller & Lazy loading collections
Hi, Maybe this is not the most adequate forum to post this question, but I know many of you are using MyFaces together with Spring & Hibernate, so it would be great it you give me some comments. The problem I have comes with Lazy collections in my objects. Assuming you know how to use Hibernate & Spring, the problem comes when I try to paginate my DataTable using the DataScroller, because the OpenSessionInViewFilter pattern establishes the session Hibernate in the initial query (the one that shows the first page of the DataTable). So, when the following page is needed, as MyFaces executes a new request, the session binded by the OpenSessionInViewFilter for this new request, is not obviously the same as the session previously established at the first request. Finally, I always get a Lazy initialization exception from Hibernate, as you surely have imagined... So my question is very simple: How do you manage objects with lazy collections being shown in different request with respect to the OpenSessionInViewFilter pattern? Thanks in advance. I'm looking forward to hearing your comments. Enrique Medina.
Re: Submitting a form automatically (without user clicking a button)
u cant simple fire submit. jsf stuff works cause when u click on commandbuttn or sth than few things are set by JS (ex. form action). so submiting without seting that "magic things" doesnt make any sense. clicking on button performs setting jsf stuff so u must find that button and click it: document.getElementById('formId:buttonId').click(); cheers Slawek I found a very simple javascript solution: form.elements['myForm:myButton'].click() This simulates a user click on the button. I have simply hidden the button using CSS, so the user does not see that a GUI form is used. Still I would like NOT to involve a button at all. Does anyone know what it takes to make a regular javascript submit work? Something like form.submit(); In response to Galen Dunklebergers post: I have verified that my "form" var is does indeed contain the form object, but invoking ".submit()" simply reloads the same page as if MyFaces does not realize what just happened. I was guessing that this is because the simulated click makes the browser set the "action=xyz" parameter of the request, but I have not been able to simulate this by something like action='xyz'. I will do some more testing, but if someone has already been down this alley, I would be happy to hear from you. Randahl Enrique Medina wrote: Or you can use forceId ;-) 2005/6/17, Galen Dunkleberger <[EMAIL PROTECTED]>: This document.forms['mySecretAndHiddenForm'].submit(); probably isn't working for you because it's not the id of the form once jsf has renderd it. If you look at the source of the generated html page the id of you form has all the names of the parent containers seperated by :. Anyway i've found the j4j tag library's idProxy tag works great for getting the correct id of an element from javascript. On 6/16/05, Randahl Fink Isaksen <[EMAIL PROTECTED]> wrote: I have a page which detects some browser properties (browser window width, etc.) and I would like to submit these capabilities automatically using a javascript like document.forms['mySecretAndHiddenForm'].submit(); However this does not seem to work. In other words: Automatically invoking submit from javascript does not seem to yeild the same results as making the user click a form button manually - probably because the action of the form is never set. Is there a standard way to submit hidden form fields using javascript? Now I guess I could manually set the action of the form to something like "#{evaluationBean.evaluate}" using javascript and then call submit afterwards, but it does not feel right to hard-code this into my javascript - I sence there has got to be a better, cleaner way. Any suggestions would be highly appreciated. Randahl Here follows my forms JSF code: [...]
Re: Submitting a form automatically (without user clicking a button)
Thanks Adrien - I guess we wrote e-mails at the same time... as stated in the previous e-mail I have just tried such a solution. Still I wish there was a more standard way... R. Adrien FOURES wrote: Hello Randahl, If i have understand your question, try this: [...] function test(){document.getElementById('mySecretAndHiddenForm:sendProperties').click();}