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:

<script language="javascript">
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);
}
</script>

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

Reply via email to