You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by JSFSter Smith <js...@gmail.com> on 2006/04/11 09:20:58 UTC

Newbie help

Hi,

I have just started using MyFaces for a new project and had a couple of
questions while I am on the learning curve. Any help/response is greatly
appreciated.  Its been a pleasure to actually create  JSP pages with no java
code using JSF in them and I hope to keep them that way!


1. <h:commandLink> tag does not work inside a <t:dataTable> tag
     and ends up refreshing the same page from where the link was clicked
without any updates to the model. The get/set  methods for the corresponding
backing bean member are never called by the framework

    I looked through the mail archives for myFaces as well as JSF RI. This
seems to be an issue faced by many users and the suggested work around is to
make the backing bean that contains the table data a session bean (currently
mine is a request). Is this a bug with the spec or am I missing something ?

2. <h:commandButton> with a request scope backing bean cannot be used to
pass request parameters to the next page using <f:param> tags.
    The <h:commandLink> tag has to be used instead. Again is this a bug or I
am missing something?

Currently, I am using h:commandLinks for  my request param passing and it
works fine. But this leads me to my final question:

3. I am trying to map the enter key to my command link (which is an image)
using javascript and have included a snippet below.

   if (keycode == 13) {

       document.forms['MyJSFForm'].elements['submitLink'].click()
        return false;
    }

    I have explicitly given id's to my form and commandLink. The java script
object for the link is invalid

Thanks in advance for your response!

- Rajiv

Re: Newbie help

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi Rajiv,

1: The model must the same on render and restore phase, afaik you can
   force this by using preserveDataModel="true" on t:datatable.
   Or you can use the t:saveState tag see:
       http://myfaces.apache.org/tomahawk/uiSaveState.html


3: the html ids are created by prefixing component ids with the ids of
   namingcontainer components

   you should use sommething like

   document.forms['MyJSFForm'].elements['MyJSFForm:submitLink'].click()

   or

   document.getElementById('MyJSFForm:submitLink').click()

   Take a look into the generated html source if unclear about the
   generated id of the link.


Regards,
  Volker


JSFSter Smith wrote:
> Hi,
> 
> I have just started using MyFaces for a new project and had a couple of
> questions while I am on the learning curve. Any help/response is greatly
> appreciated.  Its been a pleasure to actually create  JSP pages with no java
> code using JSF in them and I hope to keep them that way!
> 
> 
> 1. <h:commandLink> tag does not work inside a <t:dataTable> tag
>      and ends up refreshing the same page from where the link was clicked
> without any updates to the model. The get/set  methods for the corresponding
> backing bean member are never called by the framework
> 
>     I looked through the mail archives for myFaces as well as JSF RI. This
> seems to be an issue faced by many users and the suggested work around is to
> make the backing bean that contains the table data a session bean (currently
> mine is a request). Is this a bug with the spec or am I missing something ?
> 
> 2. <h:commandButton> with a request scope backing bean cannot be used to
> pass request parameters to the next page using <f:param> tags.
>     The <h:commandLink> tag has to be used instead. Again is this a bug or I
> am missing something?
> 
> Currently, I am using h:commandLinks for  my request param passing and it
> works fine. But this leads me to my final question:
> 
> 3. I am trying to map the enter key to my command link (which is an image)
> using javascript and have included a snippet below.
> 
>    if (keycode == 13) {
> 
>        document.forms['MyJSFForm'].elements['submitLink'].click()
>         return false;
>     }
> 
>     I have explicitly given id's to my form and commandLink. The java script
> object for the link is invalid
> 
> Thanks in advance for your response!
> 
> - Rajiv
> 

-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: Newbie help

Posted by Mike Kienenberger <mk...@gmail.com>.
On 4/11/06, JSFSter Smith <js...@gmail.com> wrote:
> 1. This
> seems to be an issue faced by many users and the suggested work around is to
> make the backing bean that contains the table data a session bean (currently
> mine is a request). Is this a bug with the spec or am I missing something ?

Use t:saveState to effectively make the scope of your request-scoped
beans into page-scoped beans.



>  2. <h:commandButton> with a request scope backing bean cannot be
> used to pass request parameters to the next page using <f:param> tags.
>      The <h:commandLink> tag has to be used instead. Again is this a bug or
> I am missing something?

Correct, you cannot do it this way as f:param doesn't work with buttons.
There's a few ways to do this.   One is to add a component that will
set values (updateActionListener) when the action is triggered.  
Another is to call some javascript to manually set the parameter, but
it's not recommended.


  		<script language="javascript">
		// <![CDATA[
			function triggerRefreshButton(){
			    clear_form();
               
document.forms['form'].elements['NET_SF_JSFC_OPT_VDTR_MODE'].value='soft';
       			document.forms['form'].elements['autoScroll'].value=getScrolling();
       			document.getElementById("form:nonclearingRefreshButton").click();
			}
		// ]]>
		</script>


		<!-- non-clearing refresh button; JSF will see it as refreshButton  -->
		<f:verbatim>
		    <input type="submit" style="display: none;" value="Submit"
name="form:refreshButton" id="form:nonclearingRefreshButton"/>
		</f:verbatim>
		
		<!-- never used directly; refreshButton exists so verbatim html
above can imitate it -->
		<h:commandButton id="refreshButton"
		    value="Submit" action="#{page.refresh}"
		    style="display:none">
		</h:commandButton>