Follow-up to previous question from wiki article
("C:\side\JavaServerFaces\ExecutingMethodsFromLinkButtonParameters - Myfaces
Wiki.htm"):

/**************  from wiki *********************
For example EmployeeAction might have: 

Approach #1:
private Employee employee; //standard POJO Value Object with properties
name, id, etc 
setEmployee( Employeee emp ) //
getEmployee() //

or

Approach #2:
String name; //getName/setName
Integer id;  //getId/setId


both techniques are valid although I like the first approach. Since I
usually have ValueObjects that are used in different places, it makes sense
to me to just make the POJO a managed property of your backing bean. The
only caveat is that you'll usually need to create a managed bean reference
to your property in your faces-config. 
****************************************/

Question:  I assume with approach #1, I would set the getter/setters for the
employee member properties in the employee class file?  I'm not sure what is
meant by a valueobject and if this is affecting my issue below (note there
was not any documentation for valueobject from the link). 


-----Original Message-----
From: Tom Butler [mailto:[EMAIL PROTECTED] 
Sent: Sunday, January 08, 2006 12:43 AM
To: 'MyFaces Discussion'
Subject: RE: referencing a managed bean property problem

The <t:updateactionlistener/> works great!

However, I'm having an issue with implementing approach #2 defined in the
wiki article:
"C:\side\JavaServerFaces\ExecutingMethodsFromLinkButtonParameters - Myfaces
Wiki.htm"

#1  When I configure <t:updateactionlistener> to set a direct member
property on the backing bean everything works fine:

<t:updateActionListener property="#{bean_myisp.id}" value="#{isp.id}" />
(bean_myisp = backing bean; bean_myisp.id = member property of backing bean)

#2   However, I receive errors if the member property on the backing bean is
itself a bean (these 2 approaches are defined in the wiki):

<t:updateActionListener property="#{bean_myisp.isp.id}" value="#{isp.id}" />
(bean_mysip.isp - isp is a bean member property of the backing bean)

I have tried to configure my facesconfig.xml as described in the wiki, but
when I include the <managed property> for bean_myisp.isp, I receive errors:

<managed-bean>
  <managed-bean-name>bean_myisp</managed-bean-name>
  <managed-bean-class>com.abc.bean_myisp</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
    <property-name>isp</property-name>
     <value>#{isp}</value>
     </managed-property>        
 </managed-bean>

Is the line "<value>#{isp}</value>" correct - wasn't sure if I was suppose
to enter this verbatim from wiki article?  Will JSF take care of
initializing the bean_mysip and ensure its member property bean 'isp' has an
instance?

Here's the error I'm receiving with approach #2 above - appears to be
nullpointerexception, but I'm not sure what object its referring to?:

SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
        at
org.apache.myfaces.custom.updateactionlistener.UpdateActionListener.processA
ction(UpdateActionListener.java:104)
        at
javax.faces.event.ActionEvent.processListener(ActionEvent.java:46)
        at
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:284)
        at javax.faces.component.UICommand.broadcast(UICommand.java:75)
        at javax.faces.component.UIData.broadcast(UIData.java:338)
        at
javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
        at
javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:132)
        at
org.apache.myfaces.lifecycle.LifecycleImpl.applyRequestValues(LifecycleImpl.
java:200)
        at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:71)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:213)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:178)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126
)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105
)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:107)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:744)
        at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav
a:527)
        at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo
rkerThread.java:80)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:684)
        at java.lang.Thread.run(Thread.java:595)


Thanks for any help.
Tom



-----Original Message-----
From: Dennis Byrne [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 04, 2006 1:21 AM
To: MyFaces Discussion
Subject: Re: referencing a managed bean property problem

Everyone on the mailing list has the use case you are describing :) .  My
advice is to use updateActionListener, or any ActionListener, for the low
risk/preparation part of a unit of work - and to use an action for the high
risk/completion of a unit of work.  

In other words, you have two sequential subtasks.  Get the identifier, and
use this value to go to the database.  t:updateActionListener allows you to
do the first w/ one line of JSP code, unless your last name is Kienenberger
:).  Because it is an action listener, it will fire *before* the action.  It
is better to do the second part in an action because it involves a db
transaction; this gives you navigational opportunities in the event of a
problem, something not available in a listener.

Does that help?

>-----Original Message-----
>From: Tom Butler [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, January 4, 2006 12:57 AM
>To: ''MyFaces Discussion''
>Subject: RE: referencing a managed bean property problem
>
>Can I use updateactionlistener if I just want to display the data in the
>second page, and not update it?  
>
>-----Original Message-----
>From: Dennis Byrne [mailto:[EMAIL PROTECTED] 
>Sent: Wednesday, January 04, 2006 12:29 AM
>To: MyFaces Discussion
>Subject: Re: referencing a managed bean property problem
>
>
>http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters?hig
h
>light=%28updateActionListener%29
>
>>-----Original Message-----
>>From: Dennis Byrne [mailto:[EMAIL PROTECTED]
>>Sent: Wednesday, January 4, 2006 12:24 AM
>>To: 'MyFaces Discussion'
>>Subject: Re:  referencing a managed bean property problem
>>
>>There is a wiki article on this.  My favorite is #2.
>>
>>>-----Original Message-----
>>>From: Tom Butler [mailto:[EMAIL PROTECTED]
>>>Sent: Wednesday, January 4, 2006 12:13 AM
>>>To: ''MyFaces Discussion''
>>>Subject: RE: referencing a managed bean property problem
>>>
>>>Simon,
>>>
>>>I have a follow up question to this:  I have a .jsf page that displays a
>>>datatable (listdatamodel) showing rows of names.  At the end of each row
I
>>>display a commandlink with the value 'select' that allows the user to
>select
>>>a name.  After they select a name, I want to take them to a second page
to
>>>show details for the selected value.
>>>
>>>Here is the commandlink from the first .jsf page:
>>>
>>><h:commandLink action="selectprovider" value="#{messages['sort_select']}"
>/>
>>>
>>>On the second .jsf page, I access the same bean as was used for the first
>>>.jsf page - I want to access the row index that the user selected from
the
>>>first page.  Here's what I've tried and values I receive
>>>(searchproviders_bean = bean from 1st page; dm_searchresults =
>>>listdatamodel)
>>>
>>><h:outputText value="#{searchproviders_bean.dm_searchresults.rowIndex}"/>
>>>Always returns -1
>>>
>>><h:outputText value="#{searchproviders_bean.dm_searchresults.rowCount}"/>
>>>Returns correct # of total rows
>>>
>>><h:outputText
>>>value="#{searchproviders_bean.dm_searchresults.getRowIndex()}"/>
>>>Returns error - assume cannot call method
>>>
>>>What is the best way to pass the id of a selected row from a datatable to
>>>the second .jsf page?
>>>
>>>Thanks
>>>Tom
>>>
>>>
>>>
>>>-----Original Message-----
>>>From: Simon Kitching [mailto:[EMAIL PROTECTED] 
>>>Sent: Tuesday, January 03, 2006 4:26 PM
>>>To: MyFaces Discussion
>>>Subject: Re: referencing a managed bean property problem
>>>
>>>Hi,
>>>
>>>I don't think that the syntax "#{savingsBean.recentBlogEntries[row]}" is 
>>>allowed. EL doesn't support passing parameters to methods, just 
>>>reading/writing *simple* properties.
>>>
>>>I presume your #{savingsBean.savingsList} method returns a List.
>>>You could add a method to your savingsBean that returns a ListDataModel 
>>>instance rather than a List, and specify that in the h:dataTable's 
>>>"value" attribute. You can then write a getRecentBlogEntries method 
>>>which accesses that ListDataModel object to get the current rowData or 
>>>rowIndex properties. These refer to the row currently being rendered at 
>>>the time the getRecentBlogEntries method is invoked.
>>>
>>>
>>>Regards,
>>>
>>>Simon
>>>
>>>Alexandre Poitras wrote:
>>>> I can see one quick mistake:
>>>> #{savingsBean.recentBlogEntries[#{row}]} should be
>>>> #{savingsBean.recentBlogEntries[row]}
>>>> 
>>>> On 1/3/06, Marco Mistroni <[EMAIL PROTECTED]> wrote:
>>>>> hello all,
>>>>> this code results in an error
>>>>>
>>>>> <f:view>
>>>>>   <h:form id="savingsForm">
>>>>>      <h:dataTable value="#{savingsBean.savingsList}" var="row"
>>>border="1">
>>>>>        <h:column>
>>>>>          <h:outputText value="#{row}"/>
>>>>>        </h:column>
>>>>>        <h:column>
>>>>>          <h:inputText
>value="#{savingsBean.recentBlogEntries[#{row}]}"/>
>>>>>      </h:column>
>>>>>     </h:dataTable>
>>>>>      <h:panelGroup>
>>>>>    <h:commandButton id="submitInsert" action="#{savingsBean.insert}"
>>>>> value="Insert"/>
>>>>>      </h:panelGroup>
>>>>>   </h:form>
>>>>> </f:view>
>>>>>
>>>>>
>>>>> at this point
>>>>>
>>>>> <h:inputText value="#{savingsBean.recentBlogEntries[#{row}]}"/
>>>>>
>>>>> recentBlogEntries is a Map. i tried, for hte sake of trying, to put in
>a
>>>>> List (savingsList, the one used for DataTable)all keys
>>>>> of the Map, and tried to generate inputText for the Map by passing the
>>>value
>>>>> of #{row} (which woul dbe the key of the map)
>>>>>
>>>>> it didnt work out..... is that impossible or is my syntax wrong
>somehow?
>>>>>
>>>>> thanks and regards
>>>>>  marco
>>>> 
>>>> 
>>>> --
>>>> Alexandre Poitras
>>>> Québec, Canada
>>>> 
>>>> 
>>>
>>>
>>
>>
>>
>
>
>


Reply via email to