在页面上写了两个inputtext,用inject在后台拿到了值,但是用下面的方法貌似两个b(b1和b2)拿到的都是第二个inputtext的值。请问怎么能分别拿到值?<?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:f="http://java.sun.com/jsf/core">
<f:view>
<h:form>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:inputText value="#{b.bs}"/>
<h:inputText value="#{b.bs}"/>
<h:commandButton action="#{a.test2}"/>
<h:outputText value="#{a.r}"/>
</h:body>
</h:form>>
</f:view>
</html>
package b;import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;@Named
@RequestScoped
public class a { @Inject
private b b1;
@Inject
private b b2;
private String r = "we"; public String test2() {
r = "being" + b1.getBs()+b2.getBs();
return null;
} public String getR() {
return r;
} public void setR(String r) {
this.r = r;
} public b getB1() {
return b1;
} public void setB1(b b1) {
this.b1 = b1;
} public b getB2() {
return b2;
} public void setB2(b b2) {
this.b2 = b2;
}
}
package b;import javax.enterprise.context.RequestScoped;
import javax.inject.Named;@Named(value = "b")
@RequestScoped
public class b { private String bs; public String getBs() {
return bs;
} public void setBs(String bs) {
this.bs = bs;
}
public b() {
}
}
<!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:f="http://java.sun.com/jsf/core">
<f:view>
<h:form>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:inputText value="#{b.bs}"/>
<h:inputText value="#{b.bs}"/>
<h:commandButton action="#{a.test2}"/>
<h:outputText value="#{a.r}"/>
</h:body>
</h:form>>
</f:view>
</html>
package b;import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;@Named
@RequestScoped
public class a { @Inject
private b b1;
@Inject
private b b2;
private String r = "we"; public String test2() {
r = "being" + b1.getBs()+b2.getBs();
return null;
} public String getR() {
return r;
} public void setR(String r) {
this.r = r;
} public b getB1() {
return b1;
} public void setB1(b b1) {
this.b1 = b1;
} public b getB2() {
return b2;
} public void setB2(b b2) {
this.b2 = b2;
}
}
package b;import javax.enterprise.context.RequestScoped;
import javax.inject.Named;@Named(value = "b")
@RequestScoped
public class b { private String bs; public String getBs() {
return bs;
} public void setBs(String bs) {
this.bs = bs;
}
public b() {
}
}
return bs;
} public void setBs(List<String> bs) {
this.bs = bs;
}
public b() {
}
}