Skip to main content

jsf 2 not work the inject a another bean with annotation @Mangedproperties

5 replies [Last post]
mauro2011
Offline
Joined: 2011-06-08
Points: 0

i have 2 managedbeans:

1 with requestscoped

2 with sessionscoped

i have tried to inject the sessionscoped into the bean requestscoped.

but i have a messages errors.

it note that the reauestscoped bean its null............

but if i configure the beans into face.config.xml with the managedproperties,it workl!!!

but intojsf2 the config not have to write it...

i have used the annotation @Managebeans and @MangedProfìperties..............

help me.........

mauro

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Savex

Sorry cannot help you.

I just came in for support.

hope you can find what you want earlier.

-------------------------------------------

wow gold

RodionGork
Offline
Joined: 2011-07-02
Points: 0

1) You need not post your question twice. All people see your message very well.

2) JSF 2 works nicely and injection with annotation @ManagedProperty works fine. A lot of people use it for now.

3) If so, then it is obvious that you have something done wrong. (Do not be frustrated, there are a lot of opportunities to make some little mistake - like providing unnecessary faces-config.xml and specifying wrong JSF version here etc).

4) But since you did not show your sources, it is impossible to tell where exactly you have done mistake. (You know: telepathes are on vacations etc.) The more accurately you describe your problem - the sooner you would have solution. Try to provide source (or source fragments) instead of all these punctuation marks.

mauro2011
Offline
Joined: 2011-06-08
Points: 0

escuse me .

how i public the code and the errors:

------------------------------------

my managedbeans:

//requestscoped:

-------------------------------------------------

package managed;

import entity.Customer;

import javax.enterprise.context.SessionScoped;

import javax.faces.bean.ManagedBean;

/**

*

* @author mauro

*/

@ManagedBean(name = "customerSession")

@SessionScoped

public class CustomerSession {

private Customer customer;

/** Creates a new instance of CustomerSession */

public CustomerSession() {

}

/**

* @return the customer

*/

public Customer getCustomer() {

return customer;

}

/**

* @param customer the customer to set

*/

public void setCustomer(Customer customer) {

this.customer = customer;

}

 

}

-------------------------------

An Error Occurred:

/index.xhtml @17,59 value="#{customerForm.name}": Target Unreachable, identifier 'customerForm' resolved to null

javax.el.PropertyNotFoundException: /index.xhtml @17,59 value="#{customerForm.name}": Target Unreachable, identifier 'customerForm' resolved to null

at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)

at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)

at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)

at javax.faces.component.UIInput.validate(UIInput.java:960)

at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)

at javax.faces.component.UIInput.processValidators(UIInput.java:698)

at javax.faces.component.UIForm.processValidators(UIForm.java:253)

at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)

at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)

at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)

at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)

at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)

at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)

at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)

at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)

at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)

at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)

at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)

at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)

at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

at java.lang.Thread.run(Thread.java:619)

<UIViewRoot id="j_id1" inView="true" locale="it_IT" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/index.xhtml">

<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<UIOutput id="j_idt4" inView="true" rendered="true" transient="false">

<title>Facelet Title</title>

</UIOutput>

<UIOutput id="j_idt6" inView="true" rendered="true" transient="false">

crete new customer

<HtmlForm enctype="application/x-www-form-urlencoded" id="create" inView="true" prependId="true" rendered="true" submitted="true" transient="false">

Name:

<HtmlInputText disabled="false" id="namecustomer" immediate="false" inView="true" localValueSet="false" maxlength="-2147483648" readonly="false" rendered="true" required="true" size="-2147483648" submittedValue="pippo" transient="false" valid="true"/>

<HtmlCommandButton action="#{customerForm.saveCustomerintodb}" actionExpression="#{customerForm.saveCustomerintodb}" disabled="false" id="submit" immediate="false" inView="true" readonly="false" rendered="true" transient="false" type="submit" value="Create"/>

</HtmlForm>

</UIOutput>

</html>

</UIViewRoot>

----------------

Request ParametersName Value

create create

create:namecustomer pippo

create:submit Create

View AttributesName Value

None

Request AttributesName Value

None

Flash AttributesName Value

None

Session AttributesName Value

None

Application AttributesName Value

csfcff com.sun.faces.context.flash.ELFlash@b16391

package managed;

import ejb.CustomerFacade;

import entity.Customer;

 

import javax.ejb.EJB;

import javax.faces.bean.ManagedBean;

import javax.faces.bean.ManagedProperty;

import javax.faces.bean.RequestScoped;

/**

*

* @author mauro

*/

@ManagedBean(name = "customerForm")

@RequestScoped

public class CustomerForm {

@EJB

private CustomerFacade customerFacade;

private String name;

@ManagedProperty(value="#{customerSession}")

private CustomerSession customerSession;

/** Creates a new instance of CustomerForm */

public CustomerForm() {

}

/**

* @return the name

*/

public String getName() {

return name;

}

/**

* @param name the name to set

*/

public void setName(String name) {

this.name = name;

}

/**

* @return the customerSession

*/

public CustomerSession getCustomerSession() {

return customerSession;

}

/**

* @param customerSession the customerSession to set

*/

public void setCustomerSession(CustomerSession customerSession) {

this.customerSession = customerSession;

}

public String saveCustomerintodb(){

Customer newcustomer= new Customer();

newcustomer.setName(name);

Customer customersaved= this.customerFacade.saveCustomer(newcustomer);

this.customerSession.setCustomer(customersaved);

return "viewcustomer";

}

}

RodionGork
Offline
Joined: 2011-07-02
Points: 0

Mauro, hi!

It is better, but still it is unusable. Here are no information on your xml setting files (like web.xml) or directory structure. Try to pack whole project folder in zip and attach as a single file to this thread.

In files which you posted here is no even request to customerForm.name property.

mauro2011
Offline
Joined: 2011-06-08
Points: 0

I you send the project in format zip

It now seems to work, because I have inserted in the file faces-config the declarations of the manageds beans and the managed properties .

but if I remove such declarations the application doesn't work.
yet jsf2 it doesn't require more than to insert the managed beans and the managed properties in the file of config.

the 2 manageds beans like you see they have the declarations with the annotations.
thanks for your attention.
mauro