Skip to content

Commit

Permalink
WELD-404
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 27, 2010
1 parent 19fe62c commit 944c6a2
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
Expand Up @@ -80,7 +80,7 @@ protected Object getReceiver(CreationalContext<?> creationalContext)
return creationalContextImpl.getIncompleteInstance(getDeclaringBean());
}
}
return beanManager.getReference(getDeclaringBean(), Object.class, creationalContext);
return beanManager.getReference(getDeclaringBean(), creationalContext, true);
}
}

Expand Down
Expand Up @@ -765,14 +765,14 @@ public Context getContext(Class<? extends Annotation> scopeType)

}

public Object getReference(Bean<?> bean, CreationalContext<?> creationalContext, boolean delegate)
public Object getReference(Bean<?> bean, CreationalContext<?> creationalContext, boolean noProxy)
{
bean = getMostSpecializedBean(bean);
if (creationalContext instanceof WeldCreationalContext<?>)
{
creationalContext = ((WeldCreationalContext<?>) creationalContext).getCreationalContext(bean);
}
if (!delegate && isProxyRequired(bean))
if (!noProxy && isProxyRequired(bean))
{
if (creationalContext != null || getContext(bean.getScope()).get(bean) != null)
{
Expand Down
@@ -0,0 +1,21 @@
package org.jboss.weld.tests.producer.field.named;

import java.io.Serializable;


public class Employee implements Serializable
{

private String name;

public void setName(String name)
{
this.name = name;
}

public String getName()
{
return name;
}

}
Expand Up @@ -33,6 +33,7 @@
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

/**
* <p>Check what happens when session.invalidate() is called.</p>
Expand All @@ -41,15 +42,17 @@
*
*/
@Artifact(addCurrentPackage=false)
@Classes({User.class, NewUserAction.class})
@Classes({User.class, NewUserAction.class, Employee.class, SaveAction.class})
@IntegrationTest(runLocally=true)
@Resources({
@Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION, source="web.xml"),
@Resource(destination="view.xhtml", source="view.xhtml"),
@Resource(destination="home.xhtml", source="home.xhtml"),
@Resource(destination="/WEB-INF/faces-config.xml", source="faces-config.xml")
})
public class NamedProducerTest extends AbstractWeldTest
{

@Test(description = "forum post")
public void testNamedProducerWorks() throws Exception
{
Expand All @@ -60,6 +63,24 @@ public void testNamedProducerWorks() throws Exception
// Check the page rendered ok
assert getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton") != null;
}

@Test(description = "WELD-404")
public void testNamedProducerFieldLoosesValues() throws Exception
{
WebClient client = new WebClient();

HtmlPage page = client.getPage(getPath("/home.jsf"));
// Check the page rendered ok
HtmlSubmitInput saveButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton");
HtmlTextInput employeeFieldName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeFieldName");
HtmlTextInput employeeMethodName = getFirstMatchingElement(page, HtmlTextInput.class, "employeeMethodName");
assert employeeFieldName != null;
assert employeeMethodName != null;
assert saveButton != null;
employeeFieldName.setValueAttribute("Pete");
employeeMethodName.setValueAttribute("Gavin");
saveButton.click();
}

protected <T> Set<T> getElements(HtmlElement rootElement, Class<T> elementClass)
{
Expand Down
@@ -0,0 +1,46 @@
package org.jboss.weld.tests.producer.field.named;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

@Named("save")
@SessionScoped
public class SaveAction implements Serializable
{

@Produces
@Named
private Employee employeeField = new Employee();

private Employee employeeMethod = new Employee();

private boolean executeCalled;

@Produces
@Named
public Employee getEmployeeMethod()
{
return employeeMethod;
}

public SaveAction()
{
}

public String execute()
{
assert employeeMethod.getName().equals("Gavin");
assert employeeField.getName().equals("Pete");
this.executeCalled = true;
return "/home?faces-redirect=true";
}

public boolean isExecuteCalled()
{
return executeCalled;
}

}
@@ -0,0 +1,19 @@
<?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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>New Employee</title>
</h:head>
<h:body>
<ui:debug hotkey="d"/>
<h:form>
<h:messages/>
<h:outputLabel value="Name:"/>
<h:inputText value="#{employeeField.name}" id="employeeFieldName" />
<h:inputText value="#{employeeMethod.name}" id="employeeMethodName" />
<h:commandButton action="#{save.execute}" value="Save!" id="saveButton"/>
</h:form>
</h:body>
</html>

0 comments on commit 944c6a2

Please sign in to comment.