Please post these types of questions to the user list. This list is
for discussing changes to the MyFaces source code only.
Regards,
Sean
On 1/2/06, Cuong Viet Hoang <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm pretty new to JSF. In my very first JSF application, I have a class
> called TestManager which contains an object of class Test. Now I have a
> table that renders a list of Test objects. On each row, there is a link to
> edit the current 'Test' object. When the link is clicked, an action method
> is called, which will populate 'test' object in TestManager managed bean
> using the id on the clicked row. Currently, I have to store a TestManager
> managed bean in session scope for the application to work.
>
> I download MyFaces examples and have a look at the master-detail examples. I
> found out that, there are two forms in the example: countryListForm and
> countryForm. But in real life, we'll probably have Country class which
> encapsulate information about country such as country code, name...
> Therefore, countryForm managed bean is kind of repeating that information.
> However, by designing application like this, we don't have to store managed
> bean in session scope.
>
> My question is, which one is the better design?
>
> Test.java
>
> public class Test {
>
> private int id;
> private String value;
>
> public int getId()
> {
> return id;
> }
> public void setId(int id)
> {
> this.id = id;
> }
> public String getValue() {
> return
> value;
> }
> public void setValue(String value) {
> this.value = value;
>
> }
> }
>
>
>
>
> TestManager.java
> public class TestManager {
>
> private Test test;
>
> public Test getTest() {
> return test;
> }
>
>
> public void setTest(Test test) {
> this.test = test;
> }
>
> public String update()
> {
> System.out.println(test.getId() + " -- " + test.getValue());
> return "success";
>
> }
> }
>
>
>
> In my faces-config.xml:
> <managed-bean>
> <managed-bean-name>test</managed-bean-name>
> <managed-bean-class>TestManager</managed-bean-class>
> <managed-bean-scope>session</managed-bean-scope>
>
> </managed-bean>
>
>
>
>
> Now in my jsp file:
>
> <h:form id="testForm">
> <h:messages layout="table"/>
> <h:panelGrid columns=
> "2">
> <h:outputText value="Id:"/>
> <h:inputText value="#{test.test.id}"
> />
> <h:outputText value="Value:"/>
> <h:inputText value="#{test.test.value}"/>
> <h:panelGroup></h:panelGroup>
>
> <h:panelGroup>
> <h:commandButton value="Submit" action="#{test.update}"/>
> </h:panelGroup>
> </h:panelGrid>
> </h:form>
>
>
>
>
> --
> Regards,
>
> Cuong Hoang