Submiting form and backing beans
I am new in jsf, so may be my question is stupid, but:
When I submit a form, which contains elements conecting with backing beans, for example
<h:inputText id="usrName" value="#{textBean.dbUserName}"/>
does this mean, that a seter method of the bean is called and the value of the filed is recorded into the backing bean object? It doesn/t work like that in my Application, so i am wondering....
[426 byte] By [
begimota] at [2007-10-3 0:04:37]

Basic example:
JSF<h:form>
<h:inputText value="#{MyBean.inputValue}" />
<h:commandButton action="#{MyBean.action}" value="submit" />
</h:form>
MyBeanprivate String inputValue;
public void action() {
System.out.println("The value you entered: " + getInputValue());
// do your thing.
}
public String getInputValue() {
return inputValue;
}
public void setInputValue(String inputValue) {
this.inputValue = inputValue;
}
I did exactly the same, but it seems that this function action() is never called...
<h:commandButton id="connect" value="Connect to DB" actionListener="#{textBean.connectToDB}" action="#{textBean.action}"/>
Bean
public class JBean
{
private String dbUserName;
public String getDbUserName(){
return this.dbUserName;
}
public void setDbUserName(String dbUserName){
this.dbUserName = dbUserName;
}
......
public void action() {
setDbUserName("Does it work");
}
......
}
<faces-config>
<managed-bean>
<managed-bean-name>textBean</managed-bean-name>
<managed-bean-class>
mybeans.JBean
</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<managed-property>
<property-name>dbUserName</property-name>
<property-class>java.lang.String</property-class>
<value>ncheltsov</value>
</managed-property>
</managed-bean>
</faces-config>
And where to get the input values from, if they are not saved in the properties of the backing been when I submit the form. May be from the request, but than, where is the point from using this beans. They are representing some input fields and when the input changes its value, the property must also refresh when the form is submited. Or may be i am not understanding something corectly.
Yes:
<f:view>
<h:form id="helloForm" >
<h:panelGrid columns="2" title="title" border="0">
<h2>A little bit stupid SQL tool ;)</h2>
<h:inputTextarea cols="50" rows="20" value="#{textBean.dbSQL}" id="ssdfdds"/> <p/>
<h:panelGroup>
<h:panelGrid columns="2" title="title2" columnClasses="edit">
<h:outputText id="DBLabel" value="Select DB type: "/>
<h:selectOneMenu id="shippingOption" required="true" value="#{textBean.dbType}">
<f:selectItem itemValue="1" itemLabel="Oracle DB"/>
<f:selectItem itemValue="5" itemLabel="SQL Plus DB"/>
<f:selectItem itemValue="7" itemLabel="Other DB"/>
</h:selectOneMenu>
<h:outputText id="addressLabel" value="Enter DB URL: "/>
<h:inputText id="DBUrl" value="#{textBean.dbURL}" maxlength="50" size="50"/>
<h:outputText id="userName" value="Enter User Name: "/>
<h:inputText id="usrName" value="#{textBean.dbUserName}" maxlength="10" size="10"/>
<h:outputText id="password" value="Enter Password: "/>
<h:inputSecret id="psw" value="#{textBean.dbPassword}" maxlength="10" size="10"/>
</h:panelGrid>
<h:panelGrid style="padding: 5px">
<h:commandButton id="connect" value="Connect to DB" actionListener="#{textBean.connectToDB}" action="#{textBean.action}"/>
</h:panelGrid>
</h:panelGroup>
<h:commandButton id="submit" value="Execute Query"/>
<h:outputText value="#{textBean.dbUserName}"/>
</h:panelGrid>
</h:form>
</f:view>